@@ -1112,108 +1112,4 @@ extension String {
1112
1112
}
1113
1113
}
1114
1114
1115
- extension _StringGutsSlice {
1116
- internal func _isScalarNFCQC(
1117
- _ scalar: Unicode . Scalar ,
1118
- _ prevCCC: inout UInt8
1119
- ) -> Bool {
1120
- let normData = Unicode . _NormData ( scalar, fastUpperbound: 0x300 )
1121
1115
1122
- if prevCCC > normData. ccc, normData. ccc != 0 {
1123
- return false
1124
- }
1125
-
1126
- if !normData. isNFCQC {
1127
- return false
1128
- }
1129
-
1130
- prevCCC = normData. ccc
1131
- return true
1132
- }
1133
-
1134
- internal func _withNFCCodeUnits( _ f: ( UInt8 ) throws -> Void ) rethrows {
1135
- let substring = String ( _guts) [ range]
1136
- // Fast path: If we're already NFC (or ASCII), then we don't need to do
1137
- // anything at all.
1138
- if _fastPath ( _guts. isNFC) {
1139
- try substring. utf8. forEach ( f)
1140
- return
1141
- }
1142
-
1143
- var isNFCQC = true
1144
- var prevCCC : UInt8 = 0
1145
-
1146
- if _guts. isFastUTF8 {
1147
- _fastNFCCheck ( & isNFCQC, & prevCCC)
1148
-
1149
- // Because we have access to the fastUTF8, we can go through that instead
1150
- // of accessing the UTF8 view on String.
1151
- if isNFCQC {
1152
- try unsafe withFastUTF8 {
1153
- for unsafe byte in unsafe $0 {
1154
- try f ( byte)
1155
- }
1156
- }
1157
-
1158
- return
1159
- }
1160
- } else {
1161
- for scalar in substring. unicodeScalars {
1162
- if !_isScalarNFCQC( scalar, & prevCCC) {
1163
- isNFCQC = false
1164
- break
1165
- }
1166
- }
1167
-
1168
- if isNFCQC {
1169
- for byte in substring. utf8 {
1170
- try f ( byte)
1171
- }
1172
-
1173
- return
1174
- }
1175
- }
1176
-
1177
- for scalar in substring. unicodeScalars. _internalNFC {
1178
- try scalar. withUTF8CodeUnits {
1179
- for unsafe byte in unsafe $0 {
1180
- try f ( byte)
1181
- }
1182
- }
1183
- }
1184
- }
1185
-
1186
- internal func _fastNFCCheck( _ isNFCQC: inout Bool , _ prevCCC: inout UInt8 ) {
1187
- unsafe withFastUTF8 { utf8 in
1188
- var position = 0
1189
-
1190
- while position < utf8. count {
1191
- // If our first byte is less than 0xCC, then it means we're under the
1192
- // 0x300 scalar value and everything up to 0x300 is NFC already.
1193
- if unsafe utf8 [ position] < 0xCC {
1194
- // If our first byte is less than 0xC0, then it means it is ASCII
1195
- // and only takes up a single byte.
1196
- if unsafe utf8 [ position] < 0xC0 {
1197
- position &+= 1
1198
- } else {
1199
- // Otherwise, this is a 2 byte < 0x300 sequence.
1200
- position &+= 2
1201
- }
1202
- // ASCII always has ccc of 0.
1203
- prevCCC = 0
1204
-
1205
- continue
1206
- }
1207
-
1208
- let ( scalar, len) = unsafe _decodeScalar( utf8, startingAt: position)
1209
-
1210
- if !_isScalarNFCQC( scalar, & prevCCC) {
1211
- isNFCQC = false
1212
- return
1213
- }
1214
-
1215
- position &+= len
1216
- }
1217
- }
1218
- }
1219
- }
0 commit comments