Skip to content

[stdlib] Add ASCII shortcuts for isUppercase and isLowercase #81483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions stdlib/public/core/CharacterProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,12 @@ extension Character {
/// - "Π" (U+03A0 GREEK CAPITAL LETTER PI)
@inlinable
public var isUppercase: Bool {
if _fastPath(_isSingleScalar && _firstScalar.properties.isUppercase) {
return true
if _fastPath(_isSingleScalar) {
if _firstScalar.isASCII {
return _firstScalar.value >= 0x41 && _firstScalar.value <= 0x5A
} else if _firstScalar.properties.isUppercase {
return true
}
}
return _isUppercased && isCased
}
Expand All @@ -266,8 +270,12 @@ extension Character {
/// - "π" (U+03C0 GREEK SMALL LETTER PI)
@inlinable
public var isLowercase: Bool {
if _fastPath(_isSingleScalar && _firstScalar.properties.isLowercase) {
return true
if _fastPath(_isSingleScalar) {
if _firstScalar.isASCII {
return _firstScalar.value >= 0x61 && _firstScalar.value <= 0x7A
} else if _firstScalar.properties.isLowercase {
return true
}
}
return _isLowercased && isCased
}
Expand Down