| ︙ | | |
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
-
+
|
* None.
*
*---------------------------------------------------------------------------
*/
INLINE static int
UtfCount(
int ch) /* The Tcl_UniChar whose size is returned. */
int ch) /* The Unicode character whose size is returned. */
{
if ((unsigned)(ch - 1) < (UNICODE_SELF - 1)) {
return 1;
}
if (ch <= 0x7FF) {
return 2;
}
|
| ︙ | | |
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
-
+
|
/*
* UTF-8 string length in bytes will be <= Unicode string length *
* TCL_UTF_MAX.
*/
oldLength = Tcl_DStringLength(dsPtr);
Tcl_DStringSetLength(dsPtr, (oldLength + uniLength + 1) * TCL_UTF_MAX);
Tcl_DStringSetLength(dsPtr, oldLength + (uniLength + 1) * TCL_UTF_MAX);
string = Tcl_DStringValue(dsPtr) + oldLength;
p = string;
wEnd = uniStr + uniLength;
for (w = uniStr; w < wEnd; ) {
p += Tcl_UniCharToUtf(*w, p);
w++;
|
| ︙ | | |
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
-
+
-
+
-
+
-
+
-
+
|
return 1;
} else if (byte < 0xE0) {
if ((src[1] & 0xC0) == 0x80) {
/*
* Two-byte-character lead-byte followed by a trail-byte.
*/
*chPtr = (Tcl_UniChar) (((byte & 0x1F) << 6) | (src[1] & 0x3F));
*chPtr = (((byte & 0x1F) << 6) | (src[1] & 0x3F));
if ((unsigned)(*chPtr - 1) >= (UNICODE_SELF - 1)) {
return 2;
}
}
/*
* A two-byte-character lead-byte not followed by trail-byte
* represents itself.
*/
} else if (byte < 0xF0) {
if (((src[1] & 0xC0) == 0x80) && ((src[2] & 0xC0) == 0x80)) {
/*
* Three-byte-character lead byte followed by two trail bytes.
*/
*chPtr = (Tcl_UniChar) (((byte & 0x0F) << 12)
*chPtr = (((byte & 0x0F) << 12)
| ((src[1] & 0x3F) << 6) | (src[2] & 0x3F));
if (*chPtr > 0x7FF) {
return 3;
}
}
/*
* A three-byte-character lead-byte not followed by two trail-bytes
* represents itself.
*/
}
#if TCL_UTF_MAX > 3
else if (byte < 0xF8) {
else if (byte < 0xF5) {
if (((src[1] & 0xC0) == 0x80) && ((src[2] & 0xC0) == 0x80) && ((src[3] & 0xC0) == 0x80)) {
/*
* Four-byte-character lead byte followed by three trail bytes.
*/
*chPtr = (Tcl_UniChar) (((byte & 0x07) << 18) | ((src[1] & 0x3F) << 12)
*chPtr = (((byte & 0x07) << 18) | ((src[1] & 0x3F) << 12)
| ((src[2] & 0x3F) << 6) | (src[3] & 0x3F));
if ((unsigned)(*chPtr - 0x10000) <= 0xFFFFF) {
return 4;
}
}
/*
* A four-byte-character lead-byte not followed by three trail-bytes
* represents itself.
*/
}
#endif
*chPtr = (Tcl_UniChar) byte;
*chPtr = byte;
return 1;
}
/*
*---------------------------------------------------------------------------
*
* Tcl_UtfToUniCharDString --
|
| ︙ | | |
424
425
426
427
428
429
430
431
432
433
434
435
436
437
|
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
+
|
/*
* Unicode string length in Tcl_UniChars will be <= UTF-8 string length in
* bytes.
*/
oldLength = Tcl_DStringLength(dsPtr);
Tcl_DStringSetLength(dsPtr,
oldLength + (int) ((length + 1) * sizeof(Tcl_UniChar)));
wString = (Tcl_UniChar *) (Tcl_DStringValue(dsPtr) + oldLength);
w = wString;
p = src;
end = src + length - TCL_UTF_MAX;
|
| ︙ | | |
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
|
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
|
-
-
+
+
-
-
+
+
|
}
/*
*---------------------------------------------------------------------------
*
* Tcl_UtfFindFirst --
*
* Returns a pointer to the first occurance of the given Tcl_UniChar in
* the NULL-terminated UTF-8 string. The NULL terminator is considered
* Returns a pointer to the first occurance of the given Unicode character
* in the NULL-terminated UTF-8 string. The NULL terminator is considered
* part of the UTF-8 string. Equivalent to Plan 9 utfrune().
*
* Results:
* As above. If the Tcl_UniChar does not exist in the given string, the
* return value is NULL.
* As above. If the Unicode character does not exist in the given string,
* the return value is NULL.
*
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
|
| ︙ | | |
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
|
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
|
-
-
+
+
-
+
-
+
|
}
/*
*---------------------------------------------------------------------------
*
* Tcl_UtfFindLast --
*
* Returns a pointer to the last occurance of the given Tcl_UniChar in
* the NULL-terminated UTF-8 string. The NULL terminator is considered
* Returns a pointer to the last occurance of the given Unicode character
* in the NULL-terminated UTF-8 string. The NULL terminator is considered
* part of the UTF-8 string. Equivalent to Plan 9 utfrrune().
*
* Results:
* As above. If the Tcl_UniChar does not exist in the given string, the
* As above. If the Unicode character does not exist in the given string, the
* return value is NULL.
*
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
CONST char *
Tcl_UtfFindLast(
CONST char *src, /* The UTF-8 string to be searched. */
int ch) /* The Tcl_UniChar to search for. */
int ch) /* The Unicode character to search for. */
{
int len;
Tcl_UniChar find;
CONST char *last;
last = NULL;
while (1) {
|
| ︙ | | |
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
|
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
|
-
-
-
+
+
+
+
+
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
+
+
+
+
|
}
/*
*---------------------------------------------------------------------------
*
* Tcl_UtfNext --
*
* Given a pointer to some current location in a UTF-8 string, move
* forward one character. The caller must ensure that they are not asking
* for the next character after the last character in the string.
* Given a pointer to some location in a UTF-8 string, Tcl_UtfNext
* returns a pointer to the next UTF-8 character in the string.
* The caller must not ask for the next character after the last
* character in the string if the string is not terminated by a null
* character.
*
* Results:
* The return value is the pointer to the next character in the UTF-8
* string.
*
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
CONST char *
Tcl_UtfNext(
CONST char *src) /* The current location in the string. */
{
int byte = *((unsigned char *) src);
int left = totalBytes[byte];
int left = totalBytes[UCHAR(*src)];
const char *next = src + 1;
while (--left) {
byte = *((unsigned char *) next);
if ((byte & 0xC0) != 0x80) {
if ((*next & 0xC0) != 0x80) {
/*
* src points to non-trail byte; We ran out of trail bytes
* before the needs of the lead byte were satisfied.
* Let the (malformed) lead byte alone be a character
*/
return src + 1;
}
next++;
}
if ((next == src + 1) || Invalid((unsigned char *)src)) {
return src + 1;
}
return next;
}
/*
*---------------------------------------------------------------------------
*
* Tcl_UtfPrev --
*
* The aim of this routine is to provide a way to move backward
* through a UTF-8 string. The caller is expected to pass non-NULL
* pointer arguments start and src. start points to the beginning
* of a string, and src >= start points to a location within (or just
* past the end) of the string. This routine always returns a
* pointer within the string (>= start). When (src == start), it
* returns start. When (src > start), it returns a pointer (< src)
* and (>= src - TCL_UTF_MAX). Subject to these constraints, the
* routine returns a pointer to the earliest byte in the string that
* Given a pointer to some current location in a UTF-8 string, move
* starts a character when characters are read starting at start and
* that character might include the byte src[-1]. The routine will
* examine only those bytes in the range that might be returned.
* It will not examine the byte *src, and because of that cannot
* determine for certain in all circumstances whether the character
* that begins with the returned pointer will or will not include
* the byte src[-1]. In the scenario, where src points to the end of
* a buffer being filled, the returned pointer point to either the
* final complete character in the string or to the earliest byte
* that might start an incomplete character waiting for more bytes to
* complete.
*
* Because this routine always returns a value < src until the point
* it is forced to return start, it is useful as a backward iterator
* through a string that will always make progress and always be
* prevented from running past the beginning of the string.
*
* In a string where all characters are complete and properly formed,
* and the value of src points to the first byte of a character,
* repeated Tcl_UtfPrev calls will step to the starting bytes of
* characters, one character at a time. Within those limitations,
* backwards one character. This works correctly when the pointer is in
* Tcl_UtfPrev and Tcl_UtfNext are inverses. If either condition cannot
* be met, Tcl_UtfPrev and Tcl_UtfNext may not function as inverses and
* the caller will have to take greater care.
* the middle of a UTF-8 character.
*
* Results:
* A pointer to the start of a character in the string as described
* above.
* The return value is a pointer to the previous character in the UTF-8
* string. If the current location was already at the beginning of the
* string, the return value will also be a pointer to the beginning of
* the string.
*
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
|
| ︙ | | |
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
|
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
|
-
+
|
result = TclParseBackslash(src, LINE_LENGTH, &numRead, dst);
if (numRead == LINE_LENGTH) {
/*
* We ate a whole line. Pay the price of a strlen()
*/
result = TclParseBackslash(src, (int)strlen(src), &numRead, dst);
result = TclParseBackslash(src, strlen(src), &numRead, dst);
}
if (readPtr != NULL) {
*readPtr = numRead;
}
return result;
}
|
| ︙ | | |
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
|
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
|
-
+
-
+
-
-
-
+
+
+
-
+
|
int
Tcl_UtfToUpper(
char *str) /* String to convert in place. */
{
Tcl_UniChar ch, upChar;
char *src, *dst;
int bytes;
int len;
/*
* Iterate over the string until we hit the terminating null.
*/
src = dst = str;
while (*src) {
bytes = TclUtfToUniChar(src, &ch);
len = TclUtfToUniChar(src, &ch);
upChar = Tcl_UniCharToUpper(ch);
/*
* To keep badly formed Utf strings from getting inflated by the
* conversion (thereby causing a segfault), only copy the upper case
* char to dst if its size is <= the original char.
*/
if (bytes < UtfCount(upChar)) {
memmove(dst, src, (size_t) bytes);
dst += bytes;
if (len < UtfCount(upChar)) {
memmove(dst, src, len);
dst += len;
} else {
dst += Tcl_UniCharToUtf(upChar, dst);
}
src += bytes;
src += len;
}
*dst = '\0';
return (dst - str);
}
/*
*----------------------------------------------------------------------
|
| ︙ | | |
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
|
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
|
-
+
-
+
-
-
-
+
+
+
-
+
|
int
Tcl_UtfToLower(
char *str) /* String to convert in place. */
{
Tcl_UniChar ch, lowChar;
char *src, *dst;
int bytes;
int len;
/*
* Iterate over the string until we hit the terminating null.
*/
src = dst = str;
while (*src) {
bytes = TclUtfToUniChar(src, &ch);
len = TclUtfToUniChar(src, &ch);
lowChar = Tcl_UniCharToLower(ch);
/*
* To keep badly formed Utf strings from getting inflated by the
* conversion (thereby causing a segfault), only copy the lower case
* char to dst if its size is <= the original char.
*/
if (bytes < UtfCount(lowChar)) {
memmove(dst, src, (size_t) bytes);
dst += bytes;
if (len < UtfCount(lowChar)) {
memmove(dst, src, len);
dst += len;
} else {
dst += Tcl_UniCharToUtf(lowChar, dst);
}
src += bytes;
src += len;
}
*dst = '\0';
return (dst - str);
}
/*
*----------------------------------------------------------------------
|
| ︙ | | |
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
|
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
|
-
+
-
+
-
-
-
+
+
+
-
+
-
+
-
-
-
+
+
+
-
+
|
int
Tcl_UtfToTitle(
char *str) /* String to convert in place. */
{
Tcl_UniChar ch, titleChar, lowChar;
char *src, *dst;
int bytes;
int len;
/*
* Capitalize the first character and then lowercase the rest of the
* characters until we get to a null.
*/
src = dst = str;
if (*src) {
bytes = TclUtfToUniChar(src, &ch);
len = TclUtfToUniChar(src, &ch);
titleChar = Tcl_UniCharToTitle(ch);
if (bytes < UtfCount(titleChar)) {
memmove(dst, src, (size_t) bytes);
dst += bytes;
if (len < UtfCount(titleChar)) {
memmove(dst, src, len);
dst += len;
} else {
dst += Tcl_UniCharToUtf(titleChar, dst);
}
src += bytes;
src += len;
}
while (*src) {
bytes = TclUtfToUniChar(src, &ch);
len = TclUtfToUniChar(src, &ch);
lowChar = ch;
/* Special exception for Georgian Asomtavruli chars, no titlecase. */
if ((unsigned)(lowChar - 0x1C90) >= 0x30) {
lowChar = Tcl_UniCharToLower(lowChar);
}
if (bytes < UtfCount(lowChar)) {
memmove(dst, src, (size_t) bytes);
dst += bytes;
if (len < UtfCount(lowChar)) {
memmove(dst, src, len);
dst += len;
} else {
dst += Tcl_UniCharToUtf(lowChar, dst);
}
src += bytes;
src += len;
}
*dst = '\0';
return (dst - str);
}
/*
*----------------------------------------------------------------------
|
| ︙ | | |
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
|
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
|
-
+
-
-
+
+
|
}
return 0;
}
/*
*----------------------------------------------------------------------
*
* Tcl_UtfNcasecmp --
* TclUtfCasecmp --
*
* Compare UTF chars of string cs to string ct case insensitively.
* Replacement for strcasecmp in Tcl core, in places where UTF-8 should
* be handled.
*
* Results:
* Return <0 if cs < ct, 0 if cs == ct, or >0 if cs > ct.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int
TclUtfCasecmp(
CONST char *cs, /* UTF string to compare to ct. */
CONST char *ct) /* UTF string cs is compared to. */
{
while (*cs && *ct) {
Tcl_UniChar ch1, ch2;
Tcl_UniChar ch1, ch2;
while (*cs && *ct) {
cs += TclUtfToUniChar(cs, &ch1);
ct += TclUtfToUniChar(ct, &ch2);
if (ch1 != ch2) {
ch1 = Tcl_UniCharToLower(ch1);
ch2 = Tcl_UniCharToLower(ch2);
if (ch1 != ch2) {
return ch1 - ch2;
|
| ︙ | | |
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
|
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
|
+
+
+
-
+
-
-
-
+
+
+
+
+
+
+
|
*----------------------------------------------------------------------
*/
Tcl_UniChar
Tcl_UniCharToUpper(
int ch) /* Unicode character to convert. */
{
#if TCL_UTF_MAX > 3
if (!UNICODE_OUT_OF_RANGE(ch)) {
#endif
int info = GetUniCharInfo(ch);
int info = GetUniCharInfo(ch);
if (GetCaseType(info) & 0x04) {
ch -= GetDelta(info);
}
if (GetCaseType(info) & 0x04) {
ch -= GetDelta(info);
}
#if TCL_UTF_MAX > 3
}
ch &= 0x1FFFFF;
#endif
return (Tcl_UniChar) ch;
}
/*
*----------------------------------------------------------------------
*
* Tcl_UniCharToLower --
|
| ︙ | | |
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
|
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
|
+
+
+
-
-
+
+
-
-
-
+
+
+
+
+
+
+
|
*----------------------------------------------------------------------
*/
Tcl_UniChar
Tcl_UniCharToLower(
int ch) /* Unicode character to convert. */
{
#if TCL_UTF_MAX > 3
if (!UNICODE_OUT_OF_RANGE(ch)) {
#endif
int info = GetUniCharInfo(ch);
int mode = GetCaseType(info);
int info = GetUniCharInfo(ch);
int mode = GetCaseType(info);
if ((mode & 0x02) && (mode != 0x7)) {
ch += GetDelta(info);
}
if ((mode & 0x02) && (mode != 0x7)) {
ch += GetDelta(info);
}
#if TCL_UTF_MAX > 3
}
ch &= 0x1FFFFF;
#endif
return (Tcl_UniChar) ch;
}
/*
*----------------------------------------------------------------------
*
* Tcl_UniCharToTitle --
|
| ︙ | | |
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
|
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
|
+
+
+
-
-
+
+
-
-
-
-
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
|
*----------------------------------------------------------------------
*/
Tcl_UniChar
Tcl_UniCharToTitle(
int ch) /* Unicode character to convert. */
{
#if TCL_UTF_MAX > 3
if (!UNICODE_OUT_OF_RANGE(ch)) {
#endif
int info = GetUniCharInfo(ch);
int mode = GetCaseType(info);
int info = GetUniCharInfo(ch);
int mode = GetCaseType(info);
if (mode & 0x1) {
/*
* Subtract or add one depending on the original case.
*/
if (mode & 0x1) {
/*
* Subtract or add one depending on the original case.
*/
if (mode != 0x7) {
ch += ((mode & 0x4) ? -1 : 1);
}
} else if (mode == 0x4) {
ch -= GetDelta(info);
}
if (mode != 0x7) {
ch += ((mode & 0x4) ? -1 : 1);
}
} else if (mode == 0x4) {
ch -= GetDelta(info);
}
#if TCL_UTF_MAX > 3
}
ch &= 0x1FFFFF;
#endif
return (Tcl_UniChar) ch;
}
/*
*----------------------------------------------------------------------
*
* Tcl_UniCharLen --
|
| ︙ | | |
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
|
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
|
+
+
+
+
+
|
*----------------------------------------------------------------------
*/
int
Tcl_UniCharIsAlnum(
int ch) /* Unicode character to test. */
{
#if TCL_UTF_MAX > 3
if (UNICODE_OUT_OF_RANGE(ch)) {
return 0;
}
#endif
return (((ALPHA_BITS | DIGIT_BITS) >> GetCategory(ch)) & 1);
}
/*
*----------------------------------------------------------------------
*
* Tcl_UniCharIsAlpha --
|
| ︙ | | |
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
|
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
|
+
+
+
+
+
|
*----------------------------------------------------------------------
*/
int
Tcl_UniCharIsAlpha(
int ch) /* Unicode character to test. */
{
#if TCL_UTF_MAX > 3
if (UNICODE_OUT_OF_RANGE(ch)) {
return 0;
}
#endif
return ((ALPHA_BITS >> GetCategory(ch)) & 1);
}
/*
*----------------------------------------------------------------------
*
* Tcl_UniCharIsControl --
|
| ︙ | | |
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
|
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
|
+
+
+
+
+
+
+
+
+
+
+
+
|
*----------------------------------------------------------------------
*/
int
Tcl_UniCharIsControl(
int ch) /* Unicode character to test. */
{
#if TCL_UTF_MAX > 3
if (UNICODE_OUT_OF_RANGE(ch)) {
ch &= 0x1FFFFF;
if ((ch == 0xE0001) || ((ch >= 0xE0020) && (ch <= 0xE007F))) {
return 1;
}
if ((ch >= 0xF0000) && ((ch & 0xFFFF) <= 0xFFFD)) {
return 1;
}
return 0;
}
#endif
return ((CONTROL_BITS >> GetCategory(ch)) & 1);
}
/*
*----------------------------------------------------------------------
*
* Tcl_UniCharIsDigit --
|
| ︙ | | |
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
|
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
|
+
+
+
+
+
|
*----------------------------------------------------------------------
*/
int
Tcl_UniCharIsDigit(
int ch) /* Unicode character to test. */
{
#if TCL_UTF_MAX > 3
if (UNICODE_OUT_OF_RANGE(ch)) {
return 0;
}
#endif
return (GetCategory(ch) == DECIMAL_DIGIT_NUMBER);
}
/*
*----------------------------------------------------------------------
*
* Tcl_UniCharIsGraph --
|
| ︙ | | |
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
|
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
|
+
+
+
+
+
|
*----------------------------------------------------------------------
*/
int
Tcl_UniCharIsGraph(
int ch) /* Unicode character to test. */
{
#if TCL_UTF_MAX > 3
if (UNICODE_OUT_OF_RANGE(ch)) {
return ((unsigned)((ch & 0x1FFFFF) - 0xE0100) <= 0xEF);
}
#endif
return ((GRAPH_BITS >> GetCategory(ch)) & 1);
}
/*
*----------------------------------------------------------------------
*
* Tcl_UniCharIsLower --
|
| ︙ | | |
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
|
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
|
+
+
+
+
+
|
*----------------------------------------------------------------------
*/
int
Tcl_UniCharIsLower(
int ch) /* Unicode character to test. */
{
#if TCL_UTF_MAX > 3
if (UNICODE_OUT_OF_RANGE(ch)) {
return 0;
}
#endif
return (GetCategory(ch) == LOWERCASE_LETTER);
}
/*
*----------------------------------------------------------------------
*
* Tcl_UniCharIsPrint --
|
| ︙ | | |
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
|
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
|
+
+
+
+
+
|
*----------------------------------------------------------------------
*/
int
Tcl_UniCharIsPrint(
int ch) /* Unicode character to test. */
{
#if TCL_UTF_MAX > 3
if (UNICODE_OUT_OF_RANGE(ch)) {
return ((unsigned)((ch & 0x1FFFFF) - 0xE0100) <= 0xEF);
}
#endif
return (((GRAPH_BITS|SPACE_BITS) >> GetCategory(ch)) & 1);
}
/*
*----------------------------------------------------------------------
*
* Tcl_UniCharIsPunct --
|
| ︙ | | |
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
|
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
|
+
+
+
+
+
|
*----------------------------------------------------------------------
*/
int
Tcl_UniCharIsPunct(
int ch) /* Unicode character to test. */
{
#if TCL_UTF_MAX > 3
if (UNICODE_OUT_OF_RANGE(ch)) {
return 0;
}
#endif
return ((PUNCT_BITS >> GetCategory(ch)) & 1);
}
/*
*----------------------------------------------------------------------
*
* Tcl_UniCharIsSpace --
|
| ︙ | | |
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
|
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
|
+
+
+
+
+
+
+
+
-
+
+
+
+
+
-
+
|
*----------------------------------------------------------------------
*/
int
Tcl_UniCharIsSpace(
int ch) /* Unicode character to test. */
{
#if TCL_UTF_MAX > 3
/* Ignore upper 11 bits. */
ch &= 0x1FFFFF;
#else
/* Ignore upper 16 bits. */
ch &= 0xFFFF;
#endif
/*
* If the character is within the first 127 characters, just use the
* standard C function, otherwise consult the Unicode table.
*/
if (((Tcl_UniChar) ch) < ((Tcl_UniChar) 0x80)) {
if (ch < 0x80) {
return TclIsSpaceProcM((char) ch);
#if TCL_UTF_MAX > 3
} else if (UNICODE_OUT_OF_RANGE(ch)) {
return 0;
#endif
} else if ((Tcl_UniChar) ch == 0x180E || (Tcl_UniChar) ch == 0x202F) {
} else if (ch == 0x180E || ch == 0x202F) {
return 1;
} else {
return ((SPACE_BITS >> GetCategory(ch)) & 1);
}
}
/*
|
| ︙ | | |
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
|
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
|
+
+
+
+
+
|
*----------------------------------------------------------------------
*/
int
Tcl_UniCharIsUpper(
int ch) /* Unicode character to test. */
{
#if TCL_UTF_MAX > 3
if (UNICODE_OUT_OF_RANGE(ch)) {
return 0;
}
#endif
return (GetCategory(ch) == UPPERCASE_LETTER);
}
/*
*----------------------------------------------------------------------
*
* Tcl_UniCharIsWordChar --
|
| ︙ | | |
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
|
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
|
+
+
+
+
+
|
*----------------------------------------------------------------------
*/
int
Tcl_UniCharIsWordChar(
int ch) /* Unicode character to test. */
{
#if TCL_UTF_MAX > 3
if (UNICODE_OUT_OF_RANGE(ch)) {
return 0;
}
#endif
return ((WORD_BITS >> GetCategory(ch)) & 1);
}
/*
*----------------------------------------------------------------------
*
* Tcl_UniCharCaseMatch --
|
| ︙ | | |