Skip to content

Commit 76fbb3c

Browse files
committed
Some fixes for scalar names
1 parent e5bfda7 commit 76fbb3c

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

stdlib/public/core/UnicodeScalarProperties.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,12 +1207,12 @@ extension Unicode.Scalar.Properties {
12071207
(0x2B740 ... 0x2B81D),
12081208
(0x2B820 ... 0x2CEA1),
12091209
(0x2CEB0 ... 0x2EBE0),
1210-
(0x2F800 ... 0x2FA1D),
12111210
(0x30000 ... 0x3134A):
12121211
return "CJK UNIFIED IDEOGRAPH-\(scalarName)"
12131212

12141213
case (0xF900 ... 0xFA6D),
1215-
(0xFA70 ... 0xFAD9):
1214+
(0xFA70 ... 0xFAD9),
1215+
(0x2F800 ... 0x2FA1D):
12161216
return "CJK COMPATIBILITY IDEOGRAPH-\(scalarName)"
12171217

12181218
case (0x17000 ... 0x187F7),

stdlib/public/stubs/Unicode/Apple/ScalarPropsData.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20063,6 +20063,8 @@ static const __swift_uint8_t _swift_stdlib_names[215884] = {
2006320063
0xBD,
2006420064
};
2006520065

20066+
#define NAMES_SCALARS_MAX_INDEX 39039
20067+
2006620068
static const __swift_uint32_t _swift_stdlib_names_scalars[39040] = {
2006720069
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
2006820070
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x7, 0xB, 0xD, 0x11,

stdlib/public/stubs/Unicode/Common/ScalarPropsData.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20035,6 +20035,8 @@ static const __swift_uint8_t _swift_stdlib_names[215884] = {
2003520035
0xE1, 0xF, 0xBD,
2003620036
};
2003720037

20038+
#define NAMES_SCALARS_MAX_INDEX 39039
20039+
2003820040
static const __swift_uint32_t _swift_stdlib_names_scalars[39040] = {
2003920041
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
2004020042
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x7, 0xB, 0xD, 0x11,

stdlib/public/stubs/Unicode/UnicodeScalarProps.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,18 +233,30 @@ __swift_intptr_t _swift_stdlib_getScalarName(__swift_uint32_t scalar,
233233
auto scalarIndex = (setOffset << 7) + (scalar & ((1 << 7) - 1));
234234
auto scalarOffset = _swift_stdlib_names_scalars[scalarIndex];
235235

236-
if (scalarOffset == 0) {
236+
// U+20 is the first scalar that Unicode defines a name for, so their offset
237+
// will the only valid 0.
238+
if (scalarOffset == 0 && scalar != 0x20) {
237239
return 0;
238240
}
239241

240242
__swift_uint32_t nextScalarOffset = 0;
241-
int i = 1;
242243

243-
// Look for the next scalar who has a name and their position in the names
244-
// array. This tells us exactly how many bytes our name takes up.
245-
while (nextScalarOffset == 0) {
246-
nextScalarOffset = _swift_stdlib_names_scalars[scalarIndex + i];
247-
i += 1;
244+
if (scalarIndex != NAMES_SCALARS_MAX_INDEX) {
245+
int i = 1;
246+
247+
// Look for the next scalar who has a name and their position in the names
248+
// array. This tells us exactly how many bytes our name takes up.
249+
while (nextScalarOffset == 0) {
250+
nextScalarOffset = _swift_stdlib_names_scalars[scalarIndex + i];
251+
i += 1;
252+
}
253+
} else {
254+
// This is the last element in the array which represents the last scalar
255+
// name that Unicode defines (excluding variation selectors). This is
256+
// U+E007F at the moment whose name is 'CANCEL TAG'. We add 4 because
257+
// 'CANCEL' is found outside the byte area for words, but tag does.
258+
// The resulting word indices look like this: [..., 0xFF, _, _, 0xXX];
259+
nextScalarOffset = scalarOffset + 4;
248260
}
249261

250262
auto nameSize = nextScalarOffset - scalarOffset;

utils/gen-unicode-data/Sources/GenScalarProps/Names.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ func emitScalarNames(
159159
}
160160
}
161161

162+
result += """
163+
#define NAMES_SCALARS_MAX_INDEX \(scalars.count - 1)
164+
165+
166+
"""
167+
162168
emitCollection(nameBytes, name: "_swift_stdlib_names", into: &result)
163169

164170
return scalarNameIndices

0 commit comments

Comments
 (0)