Skip to content

Commit 5a50f27

Browse files
committed
[stdlib] Migrate normalization usage to public properties
1 parent 3a2ad05 commit 5a50f27

File tree

2 files changed

+12
-47
lines changed

2 files changed

+12
-47
lines changed

stdlib/public/core/StringComparison.swift

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ internal func _decodeSurrogatePair(
122122

123123
internal func _hasNormalizationBoundary(before cu: UInt16) -> Bool {
124124
guard !_isSurrogate(cu) else { return false }
125-
return UnicodeScalar(_unchecked: UInt32(cu))._hasNormalizationBoundaryBefore
125+
return UnicodeScalar(
126+
_unchecked: UInt32(cu)).properties.hasNormalizationBoundaryBefore
126127
}
127128

128129
//
@@ -698,10 +699,10 @@ private struct _UnicodeScalarExceptions {
698699
guard let scalar = UnicodeScalar(rawValue) else { continue }
699700

700701
// Fast path: skip unassigned code points
701-
guard scalar._isDefined else { continue }
702+
guard scalar.properties.isDefined else { continue }
702703

703704
// Fast path: skip unless QC_FCD=no
704-
if _fastPath(!scalar._hasFullCompExclusion) {
705+
if _fastPath(!scalar.properties.isFullCompositionExclusion) {
705706
continue
706707
}
707708

@@ -717,8 +718,10 @@ private struct _UnicodeScalarExceptions {
717718
var i = 0
718719
while i < length {
719720
let (innerScalar, nextI) = _parseRawScalar(&outBuffer, startingFrom: i)
720-
if _slowPath(i != 0 && innerScalar._hasNormalizationBoundaryBefore) {
721-
guard innerScalar._hasNormalizationBoundaryBefore else {
721+
if _slowPath(
722+
i != 0 && innerScalar.properties.hasNormalizationBoundaryBefore
723+
) {
724+
guard innerScalar.properties.hasNormalizationBoundaryBefore else {
722725
fatalError(
723726
"Unicode invariant violated: non-starter multi-segment expander")
724727
}
@@ -892,7 +895,7 @@ extension _UnmanagedString where CodeUnit == UInt16 {
892895
var (_, segmentEndIdx) = self._parseRawScalar(startingFrom: idx)
893896
while segmentEndIdx < count {
894897
let (scalar, nextIdx) = self._parseRawScalar(startingFrom: segmentEndIdx)
895-
if scalar._hasNormalizationBoundaryBefore {
898+
if scalar.properties.hasNormalizationBoundaryBefore {
896899
break
897900
}
898901
segmentEndIdx = nextIdx
@@ -910,7 +913,7 @@ extension _UnmanagedString where CodeUnit == UInt16 {
910913
while idx > 0 {
911914
let (scalar, priorIdx) = _reverseParseRawScalar(endingAt: idx)
912915
idx = priorIdx
913-
if scalar._hasNormalizationBoundaryBefore {
916+
if scalar.properties.hasNormalizationBoundaryBefore {
914917
break
915918
}
916919
}
@@ -936,7 +939,8 @@ extension _UnmanagedString where CodeUnit == UInt16 {
936939
}
937940

938941
// Check current scalar
939-
if self._parseRawScalar(startingFrom: idx).0._hasNormalizationBoundaryBefore {
942+
let currentScalar = self._parseRawScalar(startingFrom: idx).0
943+
if currentScalar.properties.hasNormalizationBoundaryBefore {
940944
return (idx, segmentEnd)
941945
}
942946

stdlib/public/core/StringNormalization.swift

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -68,46 +68,7 @@ internal enum _Normalization {
6868
}
6969
return length == string.count
7070
}
71-
}
72-
73-
extension UnicodeScalar {
74-
// Normalization boundary - a place in a string where everything left of the
75-
// boundary can be normalized independently from everything right of the
76-
// boundary. The concatenation of each result is the same as if the entire
77-
// string had been normalized as a whole.
78-
//
79-
// Normalization segment - a sequence of code units between two normalization
80-
// boundaries (without any boundaries in the middle). Note that normalization
81-
// segments can, as a process of normalization, expand, contract, and even
82-
// produce new sub-segments.
83-
84-
// Whether this scalar value always has a normalization boundary before it.
85-
internal var _hasNormalizationBoundaryBefore: Bool {
86-
_sanityCheck(Int32(exactly: self.value) != nil, "top bit shouldn't be set")
87-
let value = Int32(bitPattern: self.value)
88-
return 0 != __swift_stdlib_unorm2_hasBoundaryBefore(
89-
_Normalization._nfcNormalizer, value)
90-
}
91-
92-
// Whether the supported version of Unicode has assigned a code point to this
93-
// value.
94-
internal var _isDefined: Bool {
95-
return __swift_stdlib_u_isdefined(Int32(self.value)) != 0
96-
}
97-
98-
// A property tracked in ICU regarding the scalar's potential non-normality;
99-
// this is equivalent to whether quickCheck=NO. A subset of such scalars may
100-
// expand under NFC normalization, and a subset of those may expand into
101-
// multiple segments.
102-
internal var _hasFullCompExclusion: Bool {
103-
_sanityCheck(Int32(exactly: self.value) != nil, "top bit shouldn't be set")
104-
let value = Int32(bitPattern: self.value)
105-
let prop = __swift_stdlib_UCHAR_FULL_COMPOSITION_EXCLUSION
106-
return __swift_stdlib_u_hasBinaryProperty(value, prop) != 0
107-
}
108-
}
10971

110-
extension _Normalization {
11172
// When normalized in NFC, some segments may expand in size (e.g. some non-BMP
11273
// musical notes). This expansion is capped by the maximum expansion factor of
11374
// the normal form. For NFC, that is 3x.

0 commit comments

Comments
 (0)