Skip to content

Commit 6475e09

Browse files
authored
Merge pull request #40644 from Azoy/scalar-name-fixes
[stdlib] Some fixes for scalar names
2 parents 4b4ac29 + 47a8402 commit 6475e09

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7420,6 +7420,8 @@ static const __swift_uint32_t _swift_stdlib_word_indices[12866] = {
74207420
0x13139,
74217421
};
74227422

7423+
#define NAMES_LAST_SCALAR_OFFSET 215884
7424+
74237425
static const __swift_uint8_t _swift_stdlib_names[215884] = {
74247426
0xFF, 0xA3, 0x2, 0xFF, 0x76, 0x2, 0x2B, 0xFF, 0x36, 0x2, 0x2B, 0x1D, 0x1, 0xFF, 0x1B, 0x5, 0x1,
74257427
0xFF, 0x28, 0x6, 0x1, 0xFF, 0x74, 0x4, 0xFF, 0x45, 0x4, 0x27, 0xFF, 0xB7, 0x1, 0x25, 0xFF, 0xB7,
@@ -20063,6 +20065,8 @@ static const __swift_uint8_t _swift_stdlib_names[215884] = {
2006320065
0xBD,
2006420066
};
2006520067

20068+
#define NAMES_SCALARS_MAX_INDEX 39039
20069+
2006620070
static const __swift_uint32_t _swift_stdlib_names_scalars[39040] = {
2006720071
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
2006820072
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7391,6 +7391,8 @@ static const __swift_uint32_t _swift_stdlib_word_indices[12866] = {
73917391
0x130FC, 0x130FE, 0x13103, 0x13108, 0x1310D, 0x13111, 0x1311A, 0x13127, 0x1312B, 0x13131, 0x1313A,
73927392
};
73937393

7394+
#define NAMES_LAST_SCALAR_OFFSET 215884
7395+
73947396
static const __swift_uint8_t _swift_stdlib_names[215884] = {
73957397
0xFF, 0xA7, 0x2, 0xFF, 0x77, 0x2, 0x2B, 0xFF, 0x3A, 0x2, 0x2B, 0x1D, 0x1, 0xFF, 0xDD, 0x4, 0x1,
73967398
0xFF, 0x7C, 0x6, 0x1, 0xFF, 0x9F, 0x4, 0xFF, 0x46, 0x4, 0x27, 0xFF, 0xB6, 0x1, 0x25, 0xFF, 0xB6,
@@ -20035,6 +20037,8 @@ static const __swift_uint8_t _swift_stdlib_names[215884] = {
2003520037
0xE1, 0xF, 0xBD,
2003620038
};
2003720039

20040+
#define NAMES_SCALARS_MAX_INDEX 39039
20041+
2003820042
static const __swift_uint32_t _swift_stdlib_names_scalars[39040] = {
2003920043
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
2004020044
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: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,18 +233,27 @@ __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).
256+
nextScalarOffset = NAMES_LAST_SCALAR_OFFSET;
248257
}
249258

250259
auto nameSize = nextScalarOffset - scalarOffset;

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

Lines changed: 12 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_LAST_SCALAR_OFFSET \(nameBytes.count)
164+
165+
166+
"""
167+
162168
emitCollection(nameBytes, name: "_swift_stdlib_names", into: &result)
163169

164170
return scalarNameIndices
@@ -198,6 +204,12 @@ func emitScalars(
198204
}
199205
}
200206

207+
result += """
208+
#define NAMES_SCALARS_MAX_INDEX \(scalars.count - 1)
209+
210+
211+
"""
212+
201213
emitCollection(scalars, name: "_swift_stdlib_names_scalars", into: &result)
202214

203215
return scalarSetIndices

0 commit comments

Comments
 (0)