From baeb6c635fba053fc88c5179389dce3d8bde0023 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Tue, 13 May 2025 12:50:55 -0500 Subject: [PATCH] Add ASCII shortcuts for isUppercase and isLowercase It looks like accessing _swift_stdlib_getBinaryProperties is non-trivial, so answering the upper/lower question for ASCII characters could be helpful. --- stdlib/public/core/CharacterProperties.swift | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/stdlib/public/core/CharacterProperties.swift b/stdlib/public/core/CharacterProperties.swift index ebbeba1e00436..21a7d13ac7c33 100644 --- a/stdlib/public/core/CharacterProperties.swift +++ b/stdlib/public/core/CharacterProperties.swift @@ -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 } @@ -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 }