Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | backport most unicode fixes from wtf-8-experiment branch |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
088e611d9f6e8706f33780c2ecbdcc1d |
User & Date: | chw 2020-05-20 11:02:03.885 |
Context
2020-05-20
| ||
20:36 | add selected tk upstream changes check-in: 47872f1843 user: chw tags: trunk | |
12:32 | merge with trunk check-in: 34c5b6ec22 user: chw tags: wtf-8-experiment | |
11:02 | backport most unicode fixes from wtf-8-experiment branch check-in: 088e611d9f user: chw tags: trunk | |
2020-05-16
| ||
03:22 | add tcllib upstream changes check-in: d8e1910985 user: chw tags: trunk | |
Changes
assets/tcllib1.20/mapproj/mapproj.tcl became executable.
︙ | ︙ |
assets/tcllib1.20/math/interpolate.tcl became executable.
︙ | ︙ |
assets/tcllib1.20/math/pdf_stat.tcl became executable.
︙ | ︙ |
assets/tcllib1.20/math/wilcoxon.tcl became executable.
︙ | ︙ |
Changes to jni/tcl/generic/tclCmdIL.c.
︙ | ︙ | |||
4348 4349 4350 4351 4352 4353 4354 | *---------------------------------------------------------------------- */ static int DictionaryCompare( const char *left, const char *right) /* The strings to compare. */ { | | | 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 | *---------------------------------------------------------------------- */ static int DictionaryCompare( const char *left, const char *right) /* The strings to compare. */ { int uniLeft, uniRight, uniLeftLower, uniRightLower; int diff, zeros; int secondaryDiff = 0; while (1) { if (isdigit(UCHAR(*right)) /* INTL: digit */ && isdigit(UCHAR(*left))) { /* INTL: digit */ /* |
︙ | ︙ | |||
4417 4418 4419 4420 4421 4422 4423 | /* * Convert character to Unicode for comparison purposes. If either * string is at the terminating null, do a byte-wise comparison and * bail out immediately. */ if ((*left != '\0') && (*right != '\0')) { | > > > | > > > > > > > > > | > > > > > > > > | | | 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 | /* * Convert character to Unicode for comparison purposes. If either * string is at the terminating null, do a byte-wise comparison and * bail out immediately. */ if ((*left != '\0') && (*right != '\0')) { Tcl_UniChar lch = 0, rch = 0; int len; len = TclUtfToUniChar(left, &lch); uniLeft = lch; #if TCL_UTF_MAX == 4 if (!len) { len = TclUtfToUniChar(left, &lch); uniLeft = (((uniLeft&0x3FF)<<10) | (lch&0x3FF)) + 0x10000; } #endif left += len; len = TclUtfToUniChar(right, &rch); uniRight = rch; #if TCL_UTF_MAX == 4 if (!len) { len = TclUtfToUniChar(right, &rch); uniRight = (((uniRight&0x3FF)<<10) | (rch&0x3FF)) + 0x10000; } #endif right += len; /* * Convert both chars to lower for the comparison, because * dictionary sorts are case insensitve. Covert to lower, not * upper, so chars between Z and a will sort before A (where most * other interesting punctuations occur). */ uniLeftLower = TclUCS4ToLower(uniLeft); uniRightLower = TclUCS4ToLower(uniRight); } else { diff = UCHAR(*left) - UCHAR(*right); break; } diff = uniLeftLower - uniRightLower; if (diff) { |
︙ | ︙ |
Changes to jni/tcl/generic/tclCmdMZ.c.
︙ | ︙ | |||
26 27 28 29 30 31 32 33 34 35 36 37 38 39 | static Tcl_NRPostProc SwitchPostProc; static Tcl_NRPostProc TryPostBody; static Tcl_NRPostProc TryPostFinal; static Tcl_NRPostProc TryPostHandler; static int UniCharIsAscii(int character); static int UniCharIsHexDigit(int character); /* * Default set of characters to trim in [string trim] and friends. This is a * UTF-8 literal string containing all Unicode space characters [TIP #413] */ const char tclDefaultTrimSet[] = "\x09\x0a\x0b\x0c\x0d " /* ASCII */ | > > > > > > > > > > > > > > > > > | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | static Tcl_NRPostProc SwitchPostProc; static Tcl_NRPostProc TryPostBody; static Tcl_NRPostProc TryPostFinal; static Tcl_NRPostProc TryPostHandler; static int UniCharIsAscii(int character); static int UniCharIsHexDigit(int character); #if TCL_UTF_MAX == 4 static int MemCmp(const void *s1, const void *s2, size_t n, int flags); static int NumCodePointsUtf(const char *src, int length, int *flagPtr); static int NumCodePointsUnicode(const Tcl_UniChar *src, int length, int *flagPtr); static int UniCharNcmp(const Tcl_UniChar *ucs, const Tcl_UniChar *uct, size_t numCp, int flags); static int UniCharNcasecmp(const Tcl_UniChar *ucs, const Tcl_UniChar *uct, size_t numCp, int flags); static int UtfNcasecmp(const char *cs, const char *ct, size_t numCp, int flags); static int UtfNcmp(const char *cs, const char *ct, size_t numCp, int flags); #endif /* * Default set of characters to trim in [string trim] and friends. This is a * UTF-8 literal string containing all Unicode space characters [TIP #413] */ const char tclDefaultTrimSet[] = "\x09\x0a\x0b\x0c\x0d " /* ASCII */ |
︙ | ︙ | |||
58 59 60 61 62 63 64 65 66 67 68 69 70 71 | "\xe2\x80\xa9" /* paragraph separator (U+2029) */ "\xe2\x80\xaf" /* narrow no-break space (U+202f) */ "\xe2\x81\x9f" /* medium mathematical space (U+205f) */ "\xe2\x81\xa0" /* word joiner (U+2060) */ "\xe3\x80\x80" /* ideographic space (U+3000) */ "\xef\xbb\xbf" /* zero width no-break space (U+feff) */ ; /* *---------------------------------------------------------------------- * * Tcl_PwdObjCmd -- * * This procedure is invoked to process the "pwd" Tcl command. See the | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 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 | "\xe2\x80\xa9" /* paragraph separator (U+2029) */ "\xe2\x80\xaf" /* narrow no-break space (U+202f) */ "\xe2\x81\x9f" /* medium mathematical space (U+205f) */ "\xe2\x81\xa0" /* word joiner (U+2060) */ "\xe3\x80\x80" /* ideographic space (U+3000) */ "\xef\xbb\xbf" /* zero width no-break space (U+feff) */ ; #if TCL_UTF_MAX == 4 /* *--------------------------------------------------------------------------- * * MemCmp -- * * Private wrapper for memcmp(). See C library documentation. * *--------------------------------------------------------------------------- */ static int MemCmp(const void *s1, const void *s2, size_t n, int flags) { return memcmp(s1, s2, n); } #endif #if TCL_UTF_MAX == 4 /* *--------------------------------------------------------------------------- * * NumCodePointsUtf -- * * Like Tcl_NumUtfChars() but returns the number of code points. * * Results: * As above. * * Side effects: * None. * *--------------------------------------------------------------------------- */ static int NumCodePointsUtf( const char *src, /* The UTF-8 string to measure. */ int length, /* The length of the string in bytes. */ int *flagPtr) /* Location to receive end flag. */ { Tcl_UniChar ch = 0; int len, i = 0; const char *endPtr = src + length - TCL_UTF_MAX; while (src < endPtr) { len = TclUtfToUniChar(src, &ch); if (len) { ch = 0; } else { len = TclUtfToUniChar(src, &ch); } src += len; i++; } endPtr += TCL_UTF_MAX; while ((src < endPtr) && Tcl_UtfCharComplete(src, endPtr - src)) { len = TclUtfToUniChar(src, &ch); if (len) { ch = 0; } else { len = TclUtfToUniChar(src, &ch); } src += len; i++; } if (src < endPtr) { i += endPtr - src; } return i; } #endif #if TCL_UTF_MAX == 4 /* *---------------------------------------------------------------------- * * UtfNcmp -- * * Like Tcl_UtfNcmp() but the limit is guaranteed and specified in * code points. * * Results: * Return <0 if cs < ct, 0 if cs == ct, or >0 if cs > ct. * * Side effects: * None. * *---------------------------------------------------------------------- */ static int UtfNcmp( const char *cs, /* UTF string to compare to ct. */ const char *ct, /* UTF string cs is compared to. */ size_t numCp, /* Number of code points to compare. */ int flags) /* Flags describing string ends. */ { return Tcl_UtfNcmp(cs, ct, numCp); } #endif #if TCL_UTF_MAX == 4 /* *---------------------------------------------------------------------- * * UtfNcasecmp -- * * Like Tcl_UtfNcasecmp() but the limit is guaranteed and specified in * code points. * * Results: * Return <0 if cs < ct, 0 if cs == ct, or >0 if cs > ct. * * Side effects: * None. * *---------------------------------------------------------------------- */ static int UtfNcasecmp( const char *cs, /* UTF string to compare to ct. */ const char *ct, /* UTF string cs is compared to. */ size_t numCp, /* Number of code points to compare. */ int flags) /* Flags describing string ends. */ { return Tcl_UtfNcasecmp(cs, ct, numCp); } #endif #if TCL_UTF_MAX == 4 /* *--------------------------------------------------------------------------- * * NumCodePointsUnicode -- * * Returns the number of code points of a Tcl_UniChar array. * * Results: * As above. * * Side effects: * None. * *--------------------------------------------------------------------------- */ static int NumCodePointsUnicode( const Tcl_UniChar *src, /* The array to measure. */ int length, /* The length of the array in elements. */ int *flagPtr) /* Location to receive end flag. */ { int i, n = 0; *flagPtr = 0; for (i = 0; i < length; i++, n++) { if ((src[i] & 0xFC00) == 0xD800) { if (i + 1 >= length) { *flagPtr = 1; } if ((i + 1 < length) && ((src[i+1] & 0xFC00) == 0xDC00)) { i++; } } } return n; } #endif #if TCL_UTF_MAX == 4 /* *---------------------------------------------------------------------- * * UniCharNcmp -- * * Like Tcl_UniCharNcmp() but the limit is guaranteed and specified in * code points. * * Results: * Return <0 if ucs < uct, 0 if ucs == uct, or >0 if ucs > uct. * * Side effects: * None. * *---------------------------------------------------------------------- */ static int UniCharNcmp( const Tcl_UniChar *ucs, /* Unicode string to compare to uct. */ const Tcl_UniChar *uct, /* Unicode string ucs is compared to. */ size_t numCp, /* Number of code points to compare. */ int flags) /* Flags describing string ends. */ { int lcs, lct; for ( ; numCp != 0; numCp--, ucs++, uct++) { lcs = *ucs; lct = *uct; if ((lcs & 0xFC00) == 0xD800) { if ((flags & 1) && (numCp == 1)) { /* String ends with high surrogate. */ } else if ((ucs[1] & 0xFC00) == 0xDC00) { lcs = (((lcs&0x3FF)<<10) | (ucs[1]&0x3FF)) + 0x10000; ucs++; } } if ((lct & 0xFC00) == 0xD800) { if ((flags & 2) && (numCp == 1)) { /* String ends with high surrogate. */ } else if ((uct[1] & 0xFC00) == 0xDC00) { lct = (((lct&0x3FF)<<10) | (uct[1]&0x3FF)) + 0x10000; uct++; } } if (lcs != lct) { return (lcs - lct); } } return 0; } #endif #if TCL_UTF_MAX == 4 /* *---------------------------------------------------------------------- * * UniCharNcasecmp -- * * Like Tcl_UniCharNcasecmp() but the limit is guaranteed and specified in * code points. * * Results: * Return <0 if ucs < uct, 0 if ucs == uct, or >0 if ucs > uct. * * Side effects: * None. * *---------------------------------------------------------------------- */ static int UniCharNcasecmp( const Tcl_UniChar *ucs, /* Unicode string to compare to uct. */ const Tcl_UniChar *uct, /* Unicode string ucs is compared to. */ size_t numCp, /* Number of code points to compare. */ int flags) /* Flags describing string ends. */ { int lcs, lct; for ( ; numCp != 0; numCp--, ucs++, uct++) { lcs = *ucs; lct = *uct; if ((lcs & 0xFC00) == 0xD800) { if ((flags & 1) && (numCp == 1)) { /* String ends with high surrogate. */ } else if ((ucs[1] & 0xFC00) == 0xDC00) { lcs = (((lcs&0x3FF)<<10) | (ucs[1]&0x3FF)) + 0x10000; ucs++; } } if ((lct & 0xFC00) == 0xD800) { if ((flags & 2) && (numCp == 1)) { /* String ends with high surrogate. */ } else if ((uct[1] & 0xFC00) == 0xDC00) { lct = (((lct&0x3FF)<<10) | (uct[1]&0x3FF)) + 0x10000; uct++; } } if (lcs != lct) { lcs = TclUCS4ToLower(lcs); lct = TclUCS4ToLower(lct); if (lcs != lct) { return (lcs - lct); } } } return 0; } #endif /* *---------------------------------------------------------------------- * * Tcl_PwdObjCmd -- * * This procedure is invoked to process the "pwd" Tcl command. See the |
︙ | ︙ | |||
306 307 308 309 310 311 312 | * start of the string unless the previous character is a newline. */ if (offset == 0) { eflags = 0; } else if (offset > stringLength) { eflags = TCL_REG_NOTBOL; | | | 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 | * start of the string unless the previous character is a newline. */ if (offset == 0) { eflags = 0; } else if (offset > stringLength) { eflags = TCL_REG_NOTBOL; } else if (Tcl_GetUniChar(objPtr, offset-1) == (Tcl_UniChar)'\n') { eflags = 0; } else { eflags = TCL_REG_NOTBOL; } match = Tcl_RegExpExecObj(interp, regExpr, objPtr, offset, numMatchesSaved, eflags); |
︙ | ︙ | |||
592 593 594 595 596 597 598 | /* * This is a simple one pair string map situation. We make use of a * slightly modified version of the one pair STR_MAP code. */ int slen, nocase; int (*strCmpFn)(const Tcl_UniChar*,const Tcl_UniChar*,unsigned long); | | > > > | 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 | /* * This is a simple one pair string map situation. We make use of a * slightly modified version of the one pair STR_MAP code. */ int slen, nocase; int (*strCmpFn)(const Tcl_UniChar*,const Tcl_UniChar*,unsigned long); Tcl_UniChar *p; #if TCL_UTF_MAX != 4 Tcl_UniChar wsrclc; #endif numMatches = 0; nocase = (cflags & TCL_REG_NOCASE); strCmpFn = nocase ? Tcl_UniCharNcasecmp : Tcl_UniCharNcmp; wsrc = Tcl_GetUnicodeFromObj(objv[0], &slen); wstring = Tcl_GetUnicodeFromObj(objv[1], &wlen); |
︙ | ︙ | |||
621 622 623 624 625 626 627 628 629 | Tcl_AppendUnicodeToObj(resultPtr, wsubspec, wsublen); Tcl_AppendUnicodeToObj(resultPtr, wstring, 1); numMatches++; } wlen = 0; } } else { wsrclc = Tcl_UniCharToLower(*wsrc); for (p = wfirstChar = wstring; wstring < wend; wstring++) { | > > > > | | > > > > | 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 | Tcl_AppendUnicodeToObj(resultPtr, wsubspec, wsublen); Tcl_AppendUnicodeToObj(resultPtr, wstring, 1); numMatches++; } wlen = 0; } } else { #if TCL_UTF_MAX != 4 wsrclc = Tcl_UniCharToLower(*wsrc); #endif for (p = wfirstChar = wstring; wstring < wend; wstring++) { if ( #if TCL_UTF_MAX != 4 (*wstring == *wsrc || (nocase && Tcl_UniCharToLower(*wstring)==wsrclc)) && (slen==1 || (strCmpFn(wstring, wsrc, (unsigned long) slen) == 0)) #else !strCmpFn(wstring, wsrc, (unsigned long) slen) #endif ) { if (numMatches == 0) { resultPtr = Tcl_NewUnicodeObj(wstring, 0); Tcl_IncrRefCount(resultPtr); } if (p != wstring) { Tcl_AppendUnicodeToObj(resultPtr, p, wstring - p); p = wstring + slen; |
︙ | ︙ | |||
1127 1128 1129 1130 1131 1132 1133 | objPtr = Tcl_NewStringObj(stringPtr, p - stringPtr); Tcl_ListObjAppendElement(NULL, listPtr, objPtr); stringPtr = p + 1; } TclNewStringObj(objPtr, stringPtr, end - stringPtr); Tcl_ListObjAppendElement(NULL, listPtr, objPtr); } else { | | | > > > > > > > | > > > > > > > > > > > > > > > > > > < < > > | | > > > | > > | 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 | objPtr = Tcl_NewStringObj(stringPtr, p - stringPtr); Tcl_ListObjAppendElement(NULL, listPtr, objPtr); stringPtr = p + 1; } TclNewStringObj(objPtr, stringPtr, end - stringPtr); Tcl_ListObjAppendElement(NULL, listPtr, objPtr); } else { const char *element, *p; int i, uch; Tcl_DString ds; /* * Make split chars into unicode array. */ Tcl_DStringInit(&ds); p = splitChars; while (p < splitChars + splitCharLen) { len = TclUtfToUniChar(p, &ch); uch = ch; #if TCL_UTF_MAX == 4 if (!len) { len = TclUtfToUniChar(p, &ch); uch = (((uch&0x3FF)<<10) | (ch&0x3FF)) + 0x10000; } #endif Tcl_DStringAppend(&ds, (char *) &uch, sizeof(int)); p += len; } /* * Now have real length of split chars. */ splitCharLen = Tcl_DStringLength(&ds) / sizeof(int); /* * Normal case: split on any of a given set of characters. Discard * instances of the split characters. */ for (element = stringPtr; stringPtr < end; stringPtr += len) { len = TclUtfToUniChar(stringPtr, &ch); uch = ch; #if TCL_UTF_MAX == 4 if (!len) { len = TclUtfToUniChar(stringPtr, &ch); uch = (((uch&0x3FF)<<10) | (ch&0x3FF)) + 0x10000; } #endif for (i = 0; i < splitCharLen; i++) { if (uch == ((int *)Tcl_DStringValue(&ds))[i]) { TclNewStringObj(objPtr, element, stringPtr - element); Tcl_ListObjAppendElement(NULL, listPtr, objPtr); element = stringPtr + len; break; } } } TclNewStringObj(objPtr, element, stringPtr - element); Tcl_ListObjAppendElement(NULL, listPtr, objPtr); Tcl_DStringFree(&ds); } Tcl_SetObjResult(interp, listPtr); return TCL_OK; } /* *---------------------------------------------------------------------- |
︙ | ︙ | |||
1994 1995 1996 1997 1998 1999 2000 | * Special case for one map pair which avoids the extra for loop and * extra calls to get Unicode data. The algorithm is otherwise * identical to the multi-pair case. This will be >30% faster on * larger strings. */ int mapLen; | | > > > > > > > | | > > > > | > > > > > > > > > | | > > > > > | 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 | * Special case for one map pair which avoids the extra for loop and * extra calls to get Unicode data. The algorithm is otherwise * identical to the multi-pair case. This will be >30% faster on * larger strings. */ int mapLen; Tcl_UniChar *mapString; #if TCL_UTF_MAX != 4 Tcl_UniChar u2lc; #endif ustring2 = Tcl_GetUnicodeFromObj(mapElemv[0], &length2); p = ustring1; if ((length2 > length1) || (length2 == 0)) { /* * Match string is either longer than input or empty. */ ustring1 = end; } else { mapString = Tcl_GetUnicodeFromObj(mapElemv[1], &mapLen); #if TCL_UTF_MAX != 4 u2lc = (nocase ? Tcl_UniCharToLower(*ustring2) : 0); #endif for (; ustring1 < end; ustring1++) { if ( #if TCL_UTF_MAX != 4 ((*ustring1 == *ustring2) || (nocase&&Tcl_UniCharToLower(*ustring1)==u2lc)) && (length2==1 || strCmpFn(ustring1, ustring2, (unsigned long) length2) == 0) #else !strCmpFn(ustring1, ustring2, (unsigned long) length2) #endif ) { if (p != ustring1) { Tcl_AppendUnicodeToObj(resultPtr, p, ustring1-p); p = ustring1 + length2; } else { p += length2; } ustring1 = p - 1; Tcl_AppendUnicodeToObj(resultPtr, mapString, mapLen); } } } } else { Tcl_UniChar **mapStrings; #if TCL_UTF_MAX != 4 Tcl_UniChar *u2lc = NULL; #endif int *mapLens; /* * Precompute pointers to the unicode string and length. This saves us * repeated function calls later, significantly speeding up the * algorithm. We only need the lowercase first char in the nocase * case. */ mapStrings = TclStackAlloc(interp, mapElemc*2*sizeof(Tcl_UniChar *)); mapLens = TclStackAlloc(interp, mapElemc * 2 * sizeof(int)); #if TCL_UTF_MAX != 4 if (nocase) { u2lc = TclStackAlloc(interp, mapElemc * sizeof(Tcl_UniChar)); } #endif for (index = 0; index < mapElemc; index++) { mapStrings[index] = Tcl_GetUnicodeFromObj(mapElemv[index], mapLens+index); #if TCL_UTF_MAX != 4 if (nocase && ((index % 2) == 0)) { u2lc[index/2] = Tcl_UniCharToLower(*mapStrings[index]); } #endif } for (p = ustring1; ustring1 < end; ustring1++) { for (index = 0; index < mapElemc; index += 2) { /* * Get the key string to match on. */ ustring2 = mapStrings[index]; length2 = mapLens[index]; if ( #if TCL_UTF_MAX != 4 (length2 > 0) && ((*ustring1 == *ustring2) || (nocase && (Tcl_UniCharToLower(*ustring1) == u2lc[index/2]))) && /* Restrict max compare length. */ (end-ustring1 >= length2) && ((length2 == 1) || !strCmpFn(ustring2, ustring1, (unsigned) length2)) #else (length2 > 0) && (end-ustring1 >= length2) && !strCmpFn(ustring2, ustring1, (unsigned) length2) #endif ) { if (p != ustring1) { /* * Put the skipped chars onto the result first. */ Tcl_AppendUnicodeToObj(resultPtr, p, ustring1-p); p = ustring1 + length2; |
︙ | ︙ | |||
2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 | Tcl_AppendUnicodeToObj(resultPtr, mapStrings[index+1], mapLens[index+1]); break; } } } if (nocase) { TclStackFree(interp, u2lc); } TclStackFree(interp, mapLens); TclStackFree(interp, mapStrings); } if (p != ustring1) { /* * Put the rest of the unmapped chars onto result. */ | > > | 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 | Tcl_AppendUnicodeToObj(resultPtr, mapStrings[index+1], mapLens[index+1]); break; } } } #if TCL_UTF_MAX != 4 if (nocase) { TclStackFree(interp, u2lc); } #endif TclStackFree(interp, mapLens); TclStackFree(interp, mapStrings); } if (p != ustring1) { /* * Put the rest of the unmapped chars onto result. */ |
︙ | ︙ | |||
2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 | int checkEq, /* comparison is only for equality */ int nocase, /* comparison is not case sensitive */ int reqlength) /* requested length; -1 to compare whole * strings */ { const char *s1, *s2; int empty, length, match, s1len, s2len; memCmpFn_t memCmpFn; if ((reqlength == 0) || (value1Ptr == value2Ptr)) { /* * Always match at 0 chars or if it is the same obj. */ return 0; } if (!nocase && TclIsPureByteArray(value1Ptr) && TclIsPureByteArray(value2Ptr)) { /* * Use binary versions of comparisons since that won't cause undue * type conversions and it is much faster. Only do this if we're * case-sensitive (which is all that really makes sense with byte * arrays anyway, and we have no memcasecmp() for some reason... :^) */ s1 = (char *) Tcl_GetByteArrayFromObj(value1Ptr, &s1len); s2 = (char *) Tcl_GetByteArrayFromObj(value2Ptr, &s2len); memCmpFn = memcmp; } else if ((value1Ptr->typePtr == &tclStringType) && (value2Ptr->typePtr == &tclStringType)) { /* * Do a unicode-specific comparison if both of the args are of String * type. If the char length == byte length, we can do a memcmp. In * benchmark testing this proved the most efficient check between the * unicode and string comparison operations. */ if (nocase) { s1 = (char *) Tcl_GetUnicodeFromObj(value1Ptr, &s1len); s2 = (char *) Tcl_GetUnicodeFromObj(value2Ptr, &s2len); | > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > | 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 | int checkEq, /* comparison is only for equality */ int nocase, /* comparison is not case sensitive */ int reqlength) /* requested length; -1 to compare whole * strings */ { const char *s1, *s2; int empty, length, match, s1len, s2len; #if TCL_UTF_MAX == 4 int s1flag = 0, s2flag = 0; typedef int (*memCmpFn_t)(const void *, const void *, size_t, int); #else typedef int (*memCmpFn_t)(const void *, const void *, size_t); #endif memCmpFn_t memCmpFn; if ((reqlength == 0) || (value1Ptr == value2Ptr)) { /* * Always match at 0 chars or if it is the same obj. */ return 0; } if (!nocase && TclIsPureByteArray(value1Ptr) && TclIsPureByteArray(value2Ptr)) { /* * Use binary versions of comparisons since that won't cause undue * type conversions and it is much faster. Only do this if we're * case-sensitive (which is all that really makes sense with byte * arrays anyway, and we have no memcasecmp() for some reason... :^) */ s1 = (char *) Tcl_GetByteArrayFromObj(value1Ptr, &s1len); s2 = (char *) Tcl_GetByteArrayFromObj(value2Ptr, &s2len); #if TCL_UTF_MAX == 4 memCmpFn = MemCmp; #else memCmpFn = memcmp; #endif } else if ((value1Ptr->typePtr == &tclStringType) && (value2Ptr->typePtr == &tclStringType)) { /* * Do a unicode-specific comparison if both of the args are of String * type. If the char length == byte length, we can do a memcmp. In * benchmark testing this proved the most efficient check between the * unicode and string comparison operations. */ if (nocase) { s1 = (char *) Tcl_GetUnicodeFromObj(value1Ptr, &s1len); s2 = (char *) Tcl_GetUnicodeFromObj(value2Ptr, &s2len); #if TCL_UTF_MAX == 4 s1len = NumCodePointsUnicode((Tcl_UniChar *) s1, s1len, &s1flag); s2len = NumCodePointsUnicode((Tcl_UniChar *) s2, s2len, &s2flag); memCmpFn = (memCmpFn_t) UniCharNcasecmp; #else memCmpFn = (memCmpFn_t) Tcl_UniCharNcasecmp; #endif } else { s1len = Tcl_GetCharLength(value1Ptr); s2len = Tcl_GetCharLength(value2Ptr); if ((s1len == value1Ptr->length) && (value1Ptr->bytes != NULL) && (s2len == value2Ptr->length) && (value2Ptr->bytes != NULL)) { s1 = value1Ptr->bytes; s2 = value2Ptr->bytes; #if TCL_UTF_MAX == 4 memCmpFn = MemCmp; #else memCmpFn = memcmp; #endif } else { s1 = (char *) Tcl_GetUnicode(value1Ptr); s2 = (char *) Tcl_GetUnicode(value2Ptr); if ( #ifdef WORDS_BIGENDIAN 1 #else checkEq #endif /* WORDS_BIGENDIAN */ ) { #if TCL_UTF_MAX == 4 memCmpFn = MemCmp; #else memCmpFn = memcmp; #endif s1len *= sizeof(Tcl_UniChar); s2len *= sizeof(Tcl_UniChar); } else { #if TCL_UTF_MAX == 4 s1len = NumCodePointsUnicode((Tcl_UniChar *) s1, s1len, &s1flag); s2len = NumCodePointsUnicode((Tcl_UniChar *) s2, s2len, &s2flag); memCmpFn = (memCmpFn_t) UniCharNcmp; #else memCmpFn = (memCmpFn_t) Tcl_UniCharNcmp; #endif } } } } else { /* * Get the string representations, being careful in case we have * special empty string objects about. |
︙ | ︙ | |||
2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 | if (!nocase && checkEq) { /* * When we have equal-length we can check only for (in)equality. * We can use memcmp() in all (n)eq cases because we don't need to * worry about lexical LE/BE variance. */ memCmpFn = memcmp; } else { /* * As a catch-all we will work with UTF-8. We cannot use memcmp() * as that is unsafe with any string containing NUL (\xC0\x80 in * Tcl's utf rep). We can use the more efficient TclpUtfNcmp2 if * we are case-sensitive and no specific length was requested. */ | > > > > | > > > > > | 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 | if (!nocase && checkEq) { /* * When we have equal-length we can check only for (in)equality. * We can use memcmp() in all (n)eq cases because we don't need to * worry about lexical LE/BE variance. */ #if TCL_UTF_MAX == 4 memCmpFn = MemCmp; #else memCmpFn = memcmp; #endif } else { /* * As a catch-all we will work with UTF-8. We cannot use memcmp() * as that is unsafe with any string containing NUL (\xC0\x80 in * Tcl's utf rep). We can use the more efficient TclpUtfNcmp2 if * we are case-sensitive and no specific length was requested. */ #if TCL_UTF_MAX == 4 s1len = NumCodePointsUtf(s1, s1len, &s1flag); s2len = NumCodePointsUtf(s2, s2len, &s2flag); memCmpFn = (memCmpFn_t) (nocase ? UtfNcasecmp : UtfNcmp); #else if ((reqlength < 0) && !nocase) { memCmpFn = (memCmpFn_t) TclpUtfNcmp2; } else { s1len = Tcl_NumUtfChars(s1, s1len); s2len = Tcl_NumUtfChars(s2, s2len); memCmpFn = (memCmpFn_t) (nocase ? Tcl_UtfNcasecmp : Tcl_UtfNcmp); } #endif } } length = (s1len < s2len) ? s1len : s2len; if (reqlength > 0 && reqlength < length) { length = reqlength; } else if (reqlength < 0) { |
︙ | ︙ | |||
2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 | if (checkEq && (s1len != s2len)) { match = 1; /* This will be reversed below. */ } else { /* * The comparison function should compare up to the minimum byte * length only. */ match = memCmpFn(s1, s2, (size_t) length); } if ((match == 0) && (reqlength > length)) { match = s1len - s2len; } return (match > 0) ? 1 : (match < 0) ? -1 : 0; } | > > > > | 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 | if (checkEq && (s1len != s2len)) { match = 1; /* This will be reversed below. */ } else { /* * The comparison function should compare up to the minimum byte * length only. */ #if TCL_UTF_MAX == 4 match = memCmpFn(s1, s2, (size_t) length, s1flag | (s2flag << 1)); #else match = memCmpFn(s1, s2, (size_t) length); #endif } if ((match == 0) && (reqlength > length)) { match = s1len - s2len; } return (match > 0) ? 1 : (match < 0) ? -1 : 0; } |
︙ | ︙ |
Changes to jni/tcl/generic/tclExecute.c.
︙ | ︙ | |||
5925 5926 5927 5928 5929 5930 5931 | TRACE(("%s \"%.30s\" => ", tclStringClassTable[opnd].name, O2S(valuePtr))); ustring1 = Tcl_GetUnicodeFromObj(valuePtr, &length); match = 1; if (length > 0) { end = ustring1 + length; for (p=ustring1 ; p<end ; p++) { | > > > > > > > > > > | | 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 | TRACE(("%s \"%.30s\" => ", tclStringClassTable[opnd].name, O2S(valuePtr))); ustring1 = Tcl_GetUnicodeFromObj(valuePtr, &length); match = 1; if (length > 0) { end = ustring1 + length; for (p=ustring1 ; p<end ; p++) { int ch = *p; #if TCL_UTF_MAX == 4 if (((ch&0xFC00)==0xD800) && (p+1<end)) { if ((p[1]&0xFC00)==0xDC00) { ch = ((ch&0x3FF) << 10) + 0x10000 + (p[1]&0x3FF); p++; } } #endif if (!tclStringClassTable[opnd].comparator(ch)) { match = 0; break; } } } TRACE_APPEND(("%d\n", match)); JUMP_PEEPHOLE_F(match, 2, 1); |
︙ | ︙ |
Changes to jni/tcl/generic/tclInt.h.
︙ | ︙ | |||
3158 3159 3160 3161 3162 3163 3164 | MODULE_SCOPE void TclSignalExitThread(Tcl_ThreadId id, int result); MODULE_SCOPE void TclSpellFix(Tcl_Interp *interp, Tcl_Obj *const *objv, int objc, int subIdx, Tcl_Obj *bad, Tcl_Obj *fix); MODULE_SCOPE void * TclStackRealloc(Tcl_Interp *interp, void *ptr, int numBytes); | < | 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 | MODULE_SCOPE void TclSignalExitThread(Tcl_ThreadId id, int result); MODULE_SCOPE void TclSpellFix(Tcl_Interp *interp, Tcl_Obj *const *objv, int objc, int subIdx, Tcl_Obj *bad, Tcl_Obj *fix); MODULE_SCOPE void * TclStackRealloc(Tcl_Interp *interp, void *ptr, int numBytes); MODULE_SCOPE int TclStringCmp (Tcl_Obj *value1Ptr, Tcl_Obj *value2Ptr, int checkEq, int nocase, int reqlength); MODULE_SCOPE int TclStringCmpOpts (Tcl_Interp *interp, int objc, Tcl_Obj *const objv[], int *nocase, int *reqlength); MODULE_SCOPE int TclStringMatch(const char *str, int strLen, const char *pattern, int ptnLen, int flags); MODULE_SCOPE int TclStringMatchObj(Tcl_Obj *stringObj, |
︙ | ︙ | |||
3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 | MODULE_SCOPE void TclErrorStackResetIf(Tcl_Interp *interp, const char *msg, int length); #if TCL_UTF_MAX > 3 MODULE_SCOPE int TclCollapseSurrogatePair(Tcl_Token *tokenPtr, int *numReadPtr, char *buffer); #endif /* * Many parsing tasks need a common definition of whitespace. * Use this routine and macro to achieve that and place * optimization (fragile on changes) in one place. */ | > > > > > > > > > | 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 | MODULE_SCOPE void TclErrorStackResetIf(Tcl_Interp *interp, const char *msg, int length); #if TCL_UTF_MAX > 3 MODULE_SCOPE int TclCollapseSurrogatePair(Tcl_Token *tokenPtr, int *numReadPtr, char *buffer); #endif #if TCL_UTF_MAX == 4 MODULE_SCOPE int TclUCS4ToUpper(int ch); MODULE_SCOPE int TclUCS4ToLower(int ch); MODULE_SCOPE int TclUCS4ToTitle(int ch); #else #define TclUCS4ToUpper(ch) Tcl_UniCharToUpper((ch)) #define TclUCS4ToLower(ch) Tcl_UniCharToLower((ch)) #define TclUCS4ToTitle(ch) Tcl_UniCharToTitle((ch)) #endif /* * Many parsing tasks need a common definition of whitespace. * Use this routine and macro to achieve that and place * optimization (fragile on changes) in one place. */ |
︙ | ︙ |
Changes to jni/tcl/generic/tclScan.c.
︙ | ︙ | |||
27 28 29 30 31 32 33 | * The following structure contains the information associated with a * character set. */ typedef struct CharSet { int exclude; /* 1 if this is an exclusion set. */ int nchars; | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | * The following structure contains the information associated with a * character set. */ typedef struct CharSet { int exclude; /* 1 if this is an exclusion set. */ int nchars; int *chars; int nranges; struct Range { int start; int end; } *ranges; } CharSet; /* * Declarations for functions used only in this file. */ #undef UtfToUniChar static int UtfToUniChar(const char *string, int *chPtr); static const char * BuildCharSet(CharSet *cset, const char *format); static int CharInSet(CharSet *cset, int ch); static void ReleaseCharSet(CharSet *cset); static int ValidateFormat(Tcl_Interp *interp, const char *format, int numVars, int *totalVars); /* *---------------------------------------------------------------------- * * UtfToUniChar -- * * Wrapper to Tcl_UtfToUniChar() capable of dealing with * UCS4 when compiled with TCL_UTF_MAX == 4. * * Results: * *chPtr is filled with the full unicode character, and the * return value is the number of bytes from the UTF-8 string that * were consumed. * * Side effects: * None. * *---------------------------------------------------------------------- */ static int #if TCL_UTF_MAX != 4 inline #endif UtfToUniChar( const char *src, int *chPtr) { Tcl_UniChar ch = 0; int uch, len; len = TclUtfToUniChar(src, &ch); uch = ch; #if TCL_UTF_MAX == 4 if (!len) { len = TclUtfToUniChar(src + len, &ch); uch = ((uch & 0x3FF) << 10) + 0x10000 + (ch & 0x3FF); } #endif *chPtr = uch; return len; } /* *---------------------------------------------------------------------- * * BuildCharSet -- * * This function examines a character set format specification and builds |
︙ | ︙ | |||
68 69 70 71 72 73 74 | */ static const char * BuildCharSet( CharSet *cset, const char *format) /* Points to first char of set. */ { | | | | | | | | | | | | 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | */ static const char * BuildCharSet( CharSet *cset, const char *format) /* Points to first char of set. */ { int ch, start; int offset, nranges; const char *end; memset(cset, 0, sizeof(CharSet)); offset = UtfToUniChar(format, &ch); if (ch == '^') { cset->exclude = 1; format += offset; offset = UtfToUniChar(format, &ch); } end = format + offset; /* * Find the close bracket so we can overallocate the set. */ if (ch == ']') { end += UtfToUniChar(end, &ch); } nranges = 0; while (ch != ']') { if (ch == '-') { nranges++; } end += UtfToUniChar(end, &ch); } cset->chars = ckalloc(sizeof(int) * (end - format - 1)); if (nranges > 0) { cset->ranges = ckalloc(sizeof(struct Range) * nranges); } else { cset->ranges = NULL; } /* * Now build the character set. */ cset->nchars = cset->nranges = 0; format += UtfToUniChar(format, &ch); start = ch; if (ch == ']' || ch == '-') { cset->chars[cset->nchars++] = ch; format += UtfToUniChar(format, &ch); } while (ch != ']') { if (*format == '-') { /* * This may be the first character of a range, so don't add it * yet. */ start = ch; } else if (ch == '-') { /* * Check to see if this is the last character in the set, in which * case it is not a range and we should add the previous character * as well as the dash. */ if (*format == ']' || !cset->ranges) { cset->chars[cset->nchars++] = start; cset->chars[cset->nchars++] = ch; } else { format += UtfToUniChar(format, &ch); /* * Check to see if the range is in reverse order. */ if (start < ch) { cset->ranges[cset->nranges].start = start; cset->ranges[cset->nranges].end = ch; } else { cset->ranges[cset->nranges].start = ch; cset->ranges[cset->nranges].end = start; } cset->nranges++; } } else { cset->chars[cset->nchars++] = ch; } format += UtfToUniChar(format, &ch); } return format; } /* *---------------------------------------------------------------------- * |
︙ | ︙ | |||
176 177 178 179 180 181 182 | * *---------------------------------------------------------------------- */ static int CharInSet( CharSet *cset, | | < < | 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | * *---------------------------------------------------------------------- */ static int CharInSet( CharSet *cset, int ch) /* Character to test. */ { int i, match = 0; for (i = 0; i < cset->nchars; i++) { if (cset->chars[i] == ch) { match = 1; break; } |
︙ | ︙ | |||
251 252 253 254 255 256 257 | Tcl_Interp *interp, /* Current interpreter. */ const char *format, /* The format string. */ int numVars, /* The number of variables passed to the scan * command. */ int *totalSubs) /* The number of variables that will be * required. */ { | | < | 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | Tcl_Interp *interp, /* Current interpreter. */ const char *format, /* The format string. */ int numVars, /* The number of variables passed to the scan * command. */ int *totalSubs) /* The number of variables that will be * required. */ { int gotXpg, gotSequential, value, i, flags, ch; char *end; int objIndex, xpgSize, nspace = numVars; int *nassign = TclStackAlloc(interp, nspace * sizeof(int)); char buf[TCL_UTF_MAX+1] = ""; Tcl_Obj *errorMsg; /* Place to build an error messages. Note that * these are messy operations because we do * not want to use the formatting engine; * we're inside there! */ |
︙ | ︙ | |||
275 276 277 278 279 280 281 | for (i = 0; i < nspace; i++) { nassign[i] = 0; } xpgSize = objIndex = gotXpg = gotSequential = 0; while (*format != '\0') { | | | | | | 318 319 320 321 322 323 324 325 326 327 328 329 330 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 | for (i = 0; i < nspace; i++) { nassign[i] = 0; } xpgSize = objIndex = gotXpg = gotSequential = 0; while (*format != '\0') { format += UtfToUniChar(format, &ch); flags = 0; if (ch != '%') { continue; } format += UtfToUniChar(format, &ch); if (ch == '%') { continue; } if (ch == '*') { flags |= SCAN_SUPPRESS; format += UtfToUniChar(format, &ch); goto xpgCheckDone; } if ((ch < 0x80) && isdigit(UCHAR(ch))) { /* INTL: "C" locale. */ /* * Check for an XPG3-style %n$ specification. Note: there must * not be a mixture of XPG3 specs and non-XPG3 specs in the same * format string. */ value = strtoul(format-1, &end, 10); /* INTL: "C" locale. */ if (*end != '$') { goto notXpg; } format = end+1; format += UtfToUniChar(format, &ch); gotXpg = 1; if (gotSequential) { goto mixedXPG; } objIndex = value - 1; if ((objIndex < 0) || (numVars && (objIndex >= numVars))) { goto badIndex; |
︙ | ︙ | |||
343 344 345 346 347 348 349 | /* * Parse any width specifier. */ if ((ch < 0x80) && isdigit(UCHAR(ch))) { /* INTL: "C" locale. */ value = strtoul(format-1, (char **) &format, 10); /* INTL: "C" locale. */ flags |= SCAN_WIDTH; | | | | | 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | /* * Parse any width specifier. */ if ((ch < 0x80) && isdigit(UCHAR(ch))) { /* INTL: "C" locale. */ value = strtoul(format-1, (char **) &format, 10); /* INTL: "C" locale. */ flags |= SCAN_WIDTH; format += UtfToUniChar(format, &ch); } /* * Handle any size specifier. */ switch (ch) { case 'l': if (*format == 'l') { flags |= SCAN_BIG; format += 1; format += UtfToUniChar(format, &ch); break; } /* FALLTHRU */ case 'L': flags |= SCAN_LONGER; /* FALLTHRU */ case 'h': format += UtfToUniChar(format, &ch); } if (!(flags & SCAN_SUPPRESS) && numVars && (objIndex >= numVars)) { goto badIndex; } /* |
︙ | ︙ | |||
430 431 432 433 434 435 436 | case '[': if (flags & (SCAN_LONGER|SCAN_BIG)) { goto invalidFieldSize; } if (*format == '\0') { goto badSet; } | | | | | | 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | case '[': if (flags & (SCAN_LONGER|SCAN_BIG)) { goto invalidFieldSize; } if (*format == '\0') { goto badSet; } format += UtfToUniChar(format, &ch); if (ch == '^') { if (*format == '\0') { goto badSet; } format += UtfToUniChar(format, &ch); } if (ch == ']') { if (*format == '\0') { goto badSet; } format += UtfToUniChar(format, &ch); } while (ch != ']') { if (*format == '\0') { goto badSet; } format += UtfToUniChar(format, &ch); } break; badSet: Tcl_SetObjResult(interp, Tcl_NewStringObj( "unmatched [ in format string", -1)); Tcl_SetErrorCode(interp, "TCL", "FORMAT", "BRACKET", NULL); goto error; |
︙ | ︙ | |||
578 579 580 581 582 583 584 | int numVars, nconversions, totalVars = -1; int objIndex, offset, i, result, code; long value; const char *string, *end, *baseString; char op = 0; int width, underflow = 0; Tcl_WideInt wideValue; | | | 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 | int numVars, nconversions, totalVars = -1; int objIndex, offset, i, result, code; long value; const char *string, *end, *baseString; char op = 0; int width, underflow = 0; Tcl_WideInt wideValue; int ch, sch; Tcl_Obj **objs = NULL, *objPtr = NULL; int flags; if (objc < 3) { Tcl_WrongNumArgs(interp, 1, objv, "string format ?varName ...?"); return TCL_ERROR; |
︙ | ︙ | |||
623 624 625 626 627 628 629 | * mismatch. */ objIndex = 0; nconversions = 0; while (*format != '\0') { int parseFlag = TCL_PARSE_NO_WHITESPACE; | | | | | | | | | | | | 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 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 | * mismatch. */ objIndex = 0; nconversions = 0; while (*format != '\0') { int parseFlag = TCL_PARSE_NO_WHITESPACE; format += UtfToUniChar(format, &ch); flags = 0; /* * If we see whitespace in the format, skip whitespace in the string. */ if (Tcl_UniCharIsSpace(ch)) { offset = UtfToUniChar(string, &sch); while (Tcl_UniCharIsSpace(sch)) { if (*string == '\0') { goto done; } string += offset; offset = UtfToUniChar(string, &sch); } continue; } if (ch != '%') { literal: if (*string == '\0') { underflow = 1; goto done; } string += UtfToUniChar(string, &sch); if (ch != sch) { goto done; } continue; } format += UtfToUniChar(format, &ch); if (ch == '%') { goto literal; } /* * Check for assignment suppression ('*') or an XPG3-style assignment * ('%n$'). */ if (ch == '*') { flags |= SCAN_SUPPRESS; format += UtfToUniChar(format, &ch); } else if ((ch < 0x80) && isdigit(UCHAR(ch))) { /* INTL: "C" locale. */ char *formatEnd; value = strtoul(format-1, &formatEnd, 10);/* INTL: "C" locale. */ if (*formatEnd == '$') { format = formatEnd+1; format += UtfToUniChar(format, &ch); objIndex = (int) value - 1; } } /* * Parse any width specifier. */ if ((ch < 0x80) && isdigit(UCHAR(ch))) { /* INTL: "C" locale. */ width = (int) strtoul(format-1, (char **) &format, 10);/* INTL: "C" locale. */ format += UtfToUniChar(format, &ch); } else { width = 0; } /* * Handle any size specifier. */ switch (ch) { case 'l': if (*format == 'l') { flags |= SCAN_BIG; format += 1; format += UtfToUniChar(format, &ch); break; } /* FALLTHRU */ case 'L': flags |= SCAN_LONGER; /* FALLTHRU */ case 'h': format += UtfToUniChar(format, &ch); } /* * Handle the various field types. */ switch (ch) { |
︙ | ︙ | |||
791 792 793 794 795 796 797 | /* * Skip any leading whitespace at the beginning of a field unless the * format suppresses this behavior. */ if (!(flags & SCAN_NOSKIP)) { while (*string != '\0') { | | | 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 | /* * Skip any leading whitespace at the beginning of a field unless the * format suppresses this behavior. */ if (!(flags & SCAN_NOSKIP)) { while (*string != '\0') { offset = UtfToUniChar(string, &sch); if (!Tcl_UniCharIsSpace(sch)) { break; } string += offset; } if (*string == '\0') { underflow = 1; |
︙ | ︙ | |||
818 819 820 821 822 823 824 | */ if (width == 0) { width = ~0; } end = string; while (*end != '\0') { | | | 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | */ if (width == 0) { width = ~0; } end = string; while (*end != '\0') { offset = UtfToUniChar(end, &sch); if (Tcl_UniCharIsSpace(sch)) { break; } end += offset; if (--width == 0) { break; } |
︙ | ︙ | |||
846 847 848 849 850 851 852 | if (width == 0) { width = ~0; } end = string; format = BuildCharSet(&cset, format); while (*end != '\0') { | | | | 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 | if (width == 0) { width = ~0; } end = string; format = BuildCharSet(&cset, format); while (*end != '\0') { offset = UtfToUniChar(end, &sch); if (!CharInSet(&cset, sch)) { break; } end += offset; if (--width == 0) { break; } } |
︙ | ︙ | |||
873 874 875 876 877 878 879 880 881 882 883 | objs[objIndex++] = objPtr; } string = end; break; } case 'c': /* * Scan a single Unicode character. */ | > | < < < < < < < < | | 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 | objs[objIndex++] = objPtr; } string = end; break; } case 'c': /* * Scan a single Unicode character. */ string += UtfToUniChar(string, &sch); if (!(flags & SCAN_SUPPRESS)) { objPtr = Tcl_NewIntObj(sch); Tcl_IncrRefCount(objPtr); CLANG_ASSERT(objs); objs[objIndex++] = objPtr; } break; case 'i': |
︙ | ︙ |
Changes to jni/tcl/generic/tclUtf.c.
︙ | ︙ | |||
78 79 80 81 82 83 84 | /* * Functions used only in this module. */ static int UtfCount(int ch); static int Invalid(unsigned char *src); | < < < < < | 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | /* * Functions used only in this module. */ static int UtfCount(int ch); static int Invalid(unsigned char *src); /* *--------------------------------------------------------------------------- * * UtfCount -- * * Find the number of bytes in the Utf character "ch". |
︙ | ︙ | |||
1058 1059 1060 1061 1062 1063 1064 | len = TclUtfToUniChar(src, &ch); #if TCL_UTF_MAX == 4 upChar = ch; if (!len) { len += TclUtfToUniChar(src, &ch); upChar = (((upChar & 0x3FF) << 10) | (ch & 0x3FF)) + 0x10000; } | | | 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 | len = TclUtfToUniChar(src, &ch); #if TCL_UTF_MAX == 4 upChar = ch; if (!len) { len += TclUtfToUniChar(src, &ch); upChar = (((upChar & 0x3FF) << 10) | (ch & 0x3FF)) + 0x10000; } upChar = TclUCS4ToUpper(upChar); #else upChar = Tcl_UniCharToUpper(ch); #endif /* * 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. |
︙ | ︙ | |||
1132 1133 1134 1135 1136 1137 1138 | len = TclUtfToUniChar(src, &ch); #if TCL_UTF_MAX == 4 lowChar = ch; if (!len) { len += TclUtfToUniChar(src, &ch); lowChar = (((lowChar & 0x3FF) << 10) | (ch & 0x3FF)) + 0x10000; } | | | 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 | len = TclUtfToUniChar(src, &ch); #if TCL_UTF_MAX == 4 lowChar = ch; if (!len) { len += TclUtfToUniChar(src, &ch); lowChar = (((lowChar & 0x3FF) << 10) | (ch & 0x3FF)) + 0x10000; } lowChar = TclUCS4ToLower(lowChar); #else lowChar = Tcl_UniCharToLower(ch); #endif /* * To keep badly formed Utf strings from getting inflated by the * conversion (thereby causing a segfault), only copy the lower case |
︙ | ︙ | |||
1210 1211 1212 1213 1214 1215 1216 | len = TclUtfToUniChar(src, &ch); #if TCL_UTF_MAX == 4 titleChar = ch; if (!len) { len += TclUtfToUniChar(src, &ch); titleChar = (((titleChar & 0x3FF) << 10) | (ch & 0x3FF)) + 0x10000; } | | | 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 | len = TclUtfToUniChar(src, &ch); #if TCL_UTF_MAX == 4 titleChar = ch; if (!len) { len += TclUtfToUniChar(src, &ch); titleChar = (((titleChar & 0x3FF) << 10) | (ch & 0x3FF)) + 0x10000; } titleChar = TclUCS4ToTitle(titleChar); #else titleChar = Tcl_UniCharToTitle(ch); #endif if (len < UtfCount(titleChar)) { memmove(dst, src, len); dst += len; |
︙ | ︙ | |||
1244 1245 1246 1247 1248 1249 1250 | /* Special exception for Georgian Asomtavruli chars, no titlecase. */ #if TCL_UTF_MAX == 4 if (!len) { len += TclUtfToUniChar(src, &ch); lowChar = (((lowChar & 0x3FF) << 10) | (ch & 0x3FF)) + 0x10000; } if ((unsigned)(lowChar - 0x1C90) >= 0x30) { | | | 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 | /* Special exception for Georgian Asomtavruli chars, no titlecase. */ #if TCL_UTF_MAX == 4 if (!len) { len += TclUtfToUniChar(src, &ch); lowChar = (((lowChar & 0x3FF) << 10) | (ch & 0x3FF)) + 0x10000; } if ((unsigned)(lowChar - 0x1C90) >= 0x30) { lowChar = TclUCS4ToLower(lowChar); } #else if ((unsigned)(lowChar - 0x1C90) >= 0x30) { lowChar = Tcl_UniCharToLower(lowChar); } #endif |
︙ | ︙ | |||
1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 | int Tcl_UtfNcmp( const char *cs, /* UTF string to compare to ct. */ const char *ct, /* UTF string cs is compared to. */ unsigned long numChars) /* Number of UTF chars to compare. */ { Tcl_UniChar ch1 = 0, ch2 = 0; /* * Cannot use 'memcmp(cs, ct, n);' as byte representation of \u0000 (the * pair of bytes 0xC0,0x80) is larger than byte representation of \u0001 * (the byte 0x01.) */ while (numChars-- > 0) { /* * n must be interpreted as chars, not bytes. This should be called * only when both strings are of at least n chars long (no need for \0 * check) */ | > | > > > > > > > > > | | < < | | | < < > | > > > | > | 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 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 | int Tcl_UtfNcmp( const char *cs, /* UTF string to compare to ct. */ const char *ct, /* UTF string cs is compared to. */ unsigned long numChars) /* Number of UTF chars to compare. */ { Tcl_UniChar ch1 = 0, ch2 = 0; int uch1, uch2, len; /* * Cannot use 'memcmp(cs, ct, n);' as byte representation of \u0000 (the * pair of bytes 0xC0,0x80) is larger than byte representation of \u0001 * (the byte 0x01.) */ while (numChars-- > 0) { /* * n must be interpreted as chars, not bytes. This should be called * only when both strings are of at least n chars long (no need for \0 * check) */ len = TclUtfToUniChar(cs, &ch1); uch1 = ch1; #if TCL_UTF_MAX == 4 if (!len) { len = TclUtfToUniChar(cs, &ch1); uch1 = (((uch1&0x3FF)<<10) | (ch1&0x3FF)) + 0x10000; } #endif cs += len; len = TclUtfToUniChar(ct, &ch2); uch2 = ch2; #if TCL_UTF_MAX == 4 if (!len) { len = TclUtfToUniChar(ct, &ch2); uch2 = (((uch2&0x3FF)<<10) | (ch2&0x3FF)) + 0x10000; } #endif ct += len; if (uch1 != uch2) { return (uch1 - uch2); } } return 0; } /* *---------------------------------------------------------------------- * |
︙ | ︙ | |||
1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 | int Tcl_UtfNcasecmp( const char *cs, /* UTF string to compare to ct. */ const char *ct, /* UTF string cs is compared to. */ unsigned long numChars) /* Number of UTF chars to compare. */ { Tcl_UniChar ch1 = 0, ch2 = 0; while (numChars-- > 0) { /* | > > > > > > > | | | > | > > > > > > > > > | | < < | | | < < > | > | > > | | | | 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 | int Tcl_UtfNcasecmp( const char *cs, /* UTF string to compare to ct. */ const char *ct, /* UTF string cs is compared to. */ unsigned long numChars) /* Number of UTF chars to compare. */ { Tcl_UniChar ch1 = 0, ch2 = 0; int uch1, uch2, len; /* * Cannot use 'memcmp(cs, ct, n);' as byte representation of \u0000 (the * pair of bytes 0xC0,0x80) is larger than byte representation of \u0001 * (the byte 0x01.) */ while (numChars-- > 0) { /* * n must be interpreted as chars, not bytes. This should be called * only when both strings are of at least n chars long (no need for \0 * check) */ len = TclUtfToUniChar(cs, &ch1); uch1 = ch1; #if TCL_UTF_MAX == 4 if (!len) { len = TclUtfToUniChar(cs, &ch1); uch1 = (((uch1&0x3FF)<<10) | (ch1&0x3FF)) + 0x10000; } #endif cs += len; len = TclUtfToUniChar(ct, &ch2); uch2 = ch2; #if TCL_UTF_MAX == 4 if (!len) { len = TclUtfToUniChar(ct, &ch2); uch2 = (((uch2&0x3FF)<<10) | (ch2&0x3FF)) + 0x10000; } #endif ct += len; if (uch1 != uch2) { uch1 = TclUCS4ToLower(uch1); uch2 = TclUCS4ToLower(uch2); if (uch1 != uch2) { return (uch1 - uch2); } } } return 0; } /* |
︙ | ︙ | |||
1457 1458 1459 1460 1461 1462 1463 1464 1465 | int TclUtfCasecmp( const char *cs, /* UTF string to compare to ct. */ const char *ct) /* UTF string cs is compared to. */ { Tcl_UniChar ch1 = 0, ch2 = 0; while (*cs && *ct) { | > | > > > > > > > > > | | < < | | | < < > | > | > > | | | < | | | 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 | int TclUtfCasecmp( const char *cs, /* UTF string to compare to ct. */ const char *ct) /* UTF string cs is compared to. */ { Tcl_UniChar ch1 = 0, ch2 = 0; int uch1, uch2, len; while (*cs && *ct) { len = TclUtfToUniChar(cs, &ch1); uch1 = ch1; #if TCL_UTF_MAX == 4 if (!len) { len = TclUtfToUniChar(cs, &ch1); uch1 = (((uch1&0x3FF)<<10) | (ch1&0x3FF)) + 0x10000; } #endif cs += len; len = TclUtfToUniChar(ct, &ch2); uch2 = ch2; #if TCL_UTF_MAX == 4 if (!len) { len = TclUtfToUniChar(ct, &ch2); uch2 = (((uch2&0x3FF)<<10) | (ch2&0x3FF)) + 0x10000; } #endif ct += len; if (uch1 != uch2) { uch1 = TclUCS4ToLower(uch1); uch2 = TclUCS4ToLower(uch2); if (uch1 != uch2) { return (uch1 - uch2); } } } return UCHAR(*cs) - UCHAR(*ct); } /* *---------------------------------------------------------------------- * * Tcl_UniCharToUpper -- * * Compute the uppercase equivalent of the given Unicode character. * * Results: * Returns the uppercase Unicode character. * * Side effects: * None. * *---------------------------------------------------------------------- */ #if TCL_UTF_MAX == 4 int TclUCS4ToUpper( int ch) /* Unicode character to convert. */ { if (!UNICODE_OUT_OF_RANGE(ch)) { int info = GetUniCharInfo(ch); if (GetCaseType(info) & 0x04) { ch -= GetDelta(info); |
︙ | ︙ | |||
1547 1548 1549 1550 1551 1552 1553 | * Side effects: * None. * *---------------------------------------------------------------------- */ #if TCL_UTF_MAX == 4 | | | | 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 | * Side effects: * None. * *---------------------------------------------------------------------- */ #if TCL_UTF_MAX == 4 int TclUCS4ToLower( int ch) /* Unicode character to convert. */ { if (!UNICODE_OUT_OF_RANGE(ch)) { int info = GetUniCharInfo(ch); int mode = GetCaseType(info); if ((mode & 0x02) && (mode != 0x7)) { |
︙ | ︙ | |||
1596 1597 1598 1599 1600 1601 1602 | * Side effects: * None. * *---------------------------------------------------------------------- */ #if TCL_UTF_MAX == 4 | | | | 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 | * Side effects: * None. * *---------------------------------------------------------------------- */ #if TCL_UTF_MAX == 4 int TclUCS4ToTitle( int ch) /* Unicode character to convert. */ { if (!UNICODE_OUT_OF_RANGE(ch)) { int info = GetUniCharInfo(ch); int mode = GetCaseType(info); if (mode & 0x1) { |
︙ | ︙ | |||
1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 | int Tcl_UniCharNcmp( const Tcl_UniChar *ucs, /* Unicode string to compare to uct. */ const Tcl_UniChar *uct, /* Unicode string ucs is compared to. */ unsigned long numChars) /* Number of unichars to compare. */ { #ifdef WORDS_BIGENDIAN /* * We are definitely on a big-endian machine; memcmp() is safe */ return memcmp(ucs, uct, numChars*sizeof(Tcl_UniChar)); #else /* !WORDS_BIGENDIAN */ /* * We can't simply call memcmp() because that is not lexically correct. */ for ( ; numChars != 0; ucs++, uct++, numChars--) { if (*ucs != *uct) { return (*ucs - *uct); } } return 0; #endif /* WORDS_BIGENDIAN */ } /* *---------------------------------------------------------------------- * * Tcl_UniCharNcasecmp -- * | > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 | int Tcl_UniCharNcmp( const Tcl_UniChar *ucs, /* Unicode string to compare to uct. */ const Tcl_UniChar *uct, /* Unicode string ucs is compared to. */ unsigned long numChars) /* Number of unichars to compare. */ { #if TCL_UTF_MAX == 4 int lcs, lct, nums = numChars, numt = numChars; for ( ; nums != 0 && numt != 0; nums--, numt--, ucs++, uct++) { lcs = *ucs; lct = *uct; if ((nums > 1) && ((lcs & 0xFC00) == 0xD800)) { if ((ucs[1] & 0xFC00) == 0xDC00) { lcs = (((lcs&0x3FF)<<10) | (ucs[1]&0x3FF)) + 0x10000; ucs++; nums--; } } if ((numt > 1) && ((lct & 0xFC00) == 0xD800)) { if ((uct[1] & 0xFC00) == 0xDC00) { lct = (((lct&0x3FF)<<10) | (uct[1]&0x3FF)) + 0x10000; uct++; numt--; } } if (lcs != lct) { return (lcs - lct); } } return 0; #else #ifdef WORDS_BIGENDIAN /* * We are definitely on a big-endian machine; memcmp() is safe */ return memcmp(ucs, uct, numChars*sizeof(Tcl_UniChar)); #else /* !WORDS_BIGENDIAN */ /* * We can't simply call memcmp() because that is not lexically correct. */ for ( ; numChars != 0; ucs++, uct++, numChars--) { if (*ucs != *uct) { return (*ucs - *uct); } } return 0; #endif /* WORDS_BIGENDIAN */ #endif /* TCL_UTF_MAX == 4 */ } /* *---------------------------------------------------------------------- * * Tcl_UniCharNcasecmp -- * |
︙ | ︙ | |||
1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 | int Tcl_UniCharNcasecmp( const Tcl_UniChar *ucs, /* Unicode string to compare to uct. */ const Tcl_UniChar *uct, /* Unicode string ucs is compared to. */ unsigned long numChars) /* Number of unichars to compare. */ { for ( ; numChars != 0; numChars--, ucs++, uct++) { if (*ucs != *uct) { Tcl_UniChar lcs = Tcl_UniCharToLower(*ucs); Tcl_UniChar lct = Tcl_UniCharToLower(*uct); if (lcs != lct) { return (lcs - lct); } } } return 0; } /* *---------------------------------------------------------------------- * * Tcl_UniCharIsAlnum -- | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 | int Tcl_UniCharNcasecmp( const Tcl_UniChar *ucs, /* Unicode string to compare to uct. */ const Tcl_UniChar *uct, /* Unicode string ucs is compared to. */ unsigned long numChars) /* Number of unichars to compare. */ { #if TCL_UTF_MAX == 4 int lcs, lct, nums = numChars, numt = numChars; for ( ; nums != 0 && numt != 0; nums--, numt--, ucs++, uct++) { lcs = *ucs; lct = *uct; if ((nums > 1) && ((lcs & 0xFC00) == 0xD800)) { if ((ucs[1] & 0xFC00) == 0xDC00) { lcs = (((lcs&0x3FF)<<10) | (ucs[1]&0x3FF)) + 0x10000; ucs++; nums--; } } if ((numt > 1) && ((lct & 0xFC00) == 0xD800)) { if ((uct[1] & 0xFC00) == 0xDC00) { lct = (((lct&0x3FF)<<10) | (uct[1]&0x3FF)) + 0x10000; uct++; numt--; } } if (lcs != lct) { lcs = TclUCS4ToLower(lcs); lct = TclUCS4ToLower(lct); if (lcs != lct) { return (lcs - lct); } } } #else for ( ; numChars != 0; numChars--, ucs++, uct++) { if (*ucs != *uct) { Tcl_UniChar lcs = Tcl_UniCharToLower(*ucs); Tcl_UniChar lct = Tcl_UniCharToLower(*uct); if (lcs != lct) { return (lcs - lct); } } } #endif return 0; } /* *---------------------------------------------------------------------- * * Tcl_UniCharIsAlnum -- |
︙ | ︙ | |||
2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 | Tcl_UniCharCaseMatch( const Tcl_UniChar *uniStr, /* Unicode String. */ const Tcl_UniChar *uniPattern, /* Pattern, which may contain special * characters. */ int nocase) /* 0 for case sensitive, 1 for insensitive */ { Tcl_UniChar ch1 = 0, p; while (1) { p = *uniPattern; /* * See if we're at the end of both the pattern and the string. If so, | > > > > > > > > > > > | 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 | Tcl_UniCharCaseMatch( const Tcl_UniChar *uniStr, /* Unicode String. */ const Tcl_UniChar *uniPattern, /* Pattern, which may contain special * characters. */ int nocase) /* 0 for case sensitive, 1 for insensitive */ { #if TCL_UTF_MAX == 4 int strLen = 0, ptnLen = 0; while (uniStr[strLen] != 0) { strLen++; } while (uniPattern[ptnLen] != 0) { ptnLen++; } return TclUniCharMatch(uniStr, strLen, uniPattern, ptnLen, nocase); #else Tcl_UniChar ch1 = 0, p; while (1) { p = *uniPattern; /* * See if we're at the end of both the pattern and the string. If so, |
︙ | ︙ | |||
2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 | } } else if (*uniStr != *uniPattern) { return 0; } uniStr++; uniPattern++; } } /* *---------------------------------------------------------------------- * * TclUniCharMatch -- * | > | 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 | } } else if (*uniStr != *uniPattern) { return 0; } uniStr++; uniPattern++; } #endif } /* *---------------------------------------------------------------------- * * TclUniCharMatch -- * |
︙ | ︙ | |||
2311 2312 2313 2314 2315 2316 2317 | int strLen, /* Length of String */ const Tcl_UniChar *pattern, /* Pattern, which may contain special * characters. */ int ptnLen, /* Length of Pattern */ int nocase) /* 0 for case sensitive, 1 for insensitive */ { const Tcl_UniChar *stringEnd, *patternEnd; | | > > > > > > > > > > > > | 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 | int strLen, /* Length of String */ const Tcl_UniChar *pattern, /* Pattern, which may contain special * characters. */ int ptnLen, /* Length of Pattern */ int nocase) /* 0 for case sensitive, 1 for insensitive */ { const Tcl_UniChar *stringEnd, *patternEnd; int p; #if TCL_UTF_MAX == 4 int q; #endif stringEnd = string + strLen; patternEnd = pattern + ptnLen; while (1) { /* * See if we're at the end of both the pattern and the string. If so, * we succeeded. If we're at the end of the pattern but not at the end * of the string, we failed. */ if (pattern == patternEnd) { return (string == stringEnd); } p = *pattern; #if TCL_UTF_MAX == 4 if ((p & 0xFC00) == 0xD800) { if ((pattern + 1 < patternEnd) && ((pattern[1] & 0xFC00) == 0xDC00)) { p = (((p&0x3FF)<<10) | (pattern[1]&0x3FF)) + 0x10000; ++pattern; } } #endif if ((string == stringEnd) && (p != '*')) { return 0; } /* * Check for a "*" as the next pattern character. It matches any * substring. We handle this by skipping all the characters up to the |
︙ | ︙ | |||
2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 | while (*(++pattern) == '*') { /* empty body */ } if (pattern == patternEnd) { return 1; } p = *pattern; if (nocase) { p = Tcl_UniCharToLower(p); } while (1) { /* * Optimization for matching - cruise through the string * quickly if the next char in the pattern isn't a special * character. */ if ((p != '[') && (p != '?') && (p != '\\')) { if (nocase) { while ((string < stringEnd) && (p != *string) && (p != Tcl_UniCharToLower(*string))) { string++; } } else { while ((string < stringEnd) && (p != *string)) { string++; } } } if (TclUniCharMatch(string, stringEnd - string, pattern, patternEnd - pattern, nocase)) { return 1; } if (string == stringEnd) { return 0; } string++; } } /* * Check for a "?" as the next pattern character. It matches any * single character. */ if (p == '?') { pattern++; string++; continue; } /* * Check for a "[" as the next pattern character. It is followed by a * list of characters that are acceptable, or by a range (two * characters separated by "-"). */ if (p == '[') { | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > | 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 | while (*(++pattern) == '*') { /* empty body */ } if (pattern == patternEnd) { return 1; } p = *pattern; #if TCL_UTF_MAX == 4 if ((p & 0xFC00) == 0xD800) { if ((pattern + 1 < patternEnd) && ((pattern[1] & 0xFC00) == 0xDC00)) { p = (((p&0x3FF)<<10) | (pattern[1]&0x3FF)) + 0x10000; ++pattern; } } #endif if (nocase) { p = Tcl_UniCharToLower(p); } while (1) { /* * Optimization for matching - cruise through the string * quickly if the next char in the pattern isn't a special * character. */ if ((p != '[') && (p != '?') && (p != '\\')) { #if TCL_UTF_MAX == 4 while (string < stringEnd) { q = *string; if ((q & 0xFC00) == 0xD800) { if ((string + 1 < stringEnd) && ((string[1] & 0xFC00) == 0xDC00)) { q = (((q&0x3FF)<<10) | (string[1]&0x3FF)) + 0x10000; } } if ((p == q) || (nocase && (p == TclUCS4ToLower(q)))) { break; } if (q > 0xFFFF) { string++; } string++; } #else if (nocase) { while ((string < stringEnd) && (p != *string) && (p != Tcl_UniCharToLower(*string))) { string++; } } else { while ((string < stringEnd) && (p != *string)) { string++; } } #endif } if (TclUniCharMatch(string, stringEnd - string, pattern, patternEnd - pattern, nocase)) { return 1; } if (string == stringEnd) { return 0; } #if TCL_UTF_MAX == 4 if ((string[0] & 0xFC00) == 0xD800) { if ((string + 1 < stringEnd) && ((string[1] & 0xFC00) == 0xDC00)) { string++; } } #endif string++; } } /* * Check for a "?" as the next pattern character. It matches any * single character. */ if (p == '?') { pattern++; #if TCL_UTF_MAX == 4 if ((string[0] & 0xFC00) == 0xD800) { if ((string + 1 < stringEnd) && ((string[1] & 0xFC00) == 0xDC00)) { string++; } } #endif string++; continue; } /* * Check for a "[" as the next pattern character. It is followed by a * list of characters that are acceptable, or by a range (two * characters separated by "-"). */ if (p == '[') { int ch1, startChar, endChar; pattern++; #if TCL_UTF_MAX == 4 ch1 = *string; if ((ch1 & 0xFC00) == 0xD800) { if ((string + 1 < stringEnd) && ((string[1] & 0xFC00) == 0xDC00)) { ch1 = (((ch1&0x3FF)<<10) | (string[1]&0x3FF)) + 0x10000; string++; } } if (nocase) { ch1 = TclUCS4ToLower(ch1); } #else ch1 = (nocase ? Tcl_UniCharToLower(*string) : *string); #endif string++; while (1) { if ((*pattern == ']') || (pattern == patternEnd)) { return 0; } #if TCL_UTF_MAX == 4 startChar = *pattern; if ((startChar & 0xFC00) == 0xD800) { if ((pattern + 1 < patternEnd) && ((pattern[1] & 0xFC00) == 0xDC00)) { startChar = (((startChar&0x3FF)<<10) | (pattern[1]&0x3FF)) + 0x10000; pattern++; } } if (nocase) { startChar = TclUCS4ToLower(startChar); } #else startChar = (nocase ? Tcl_UniCharToLower(*pattern) : *pattern); #endif pattern++; if (*pattern == '-') { pattern++; if (pattern == patternEnd) { return 0; } #if TCL_UTF_MAX == 4 endChar = *pattern; if ((endChar & 0xFC00) == 0xD800) { if ((pattern + 1 < patternEnd) && ((pattern[1] & 0xFC00) == 0xDC00)) { endChar = (((endChar&0x3FF)<<10) | (pattern[1]&0x3FF)) + 0x10000; pattern++; } } if (nocase) { endChar = TclUCS4ToLower(endChar); } #else endChar = (nocase ? Tcl_UniCharToLower(*pattern) : *pattern); #endif pattern++; if (((startChar <= ch1) && (ch1 <= endChar)) || ((endChar <= ch1) && (ch1 <= startChar))) { /* * Matches ranges of form [a-z] or [z-a]. */ break; } } else if (startChar == ch1) { break; } } while (*pattern != ']') { if (pattern == patternEnd) { pattern--; break; } pattern++; } #if TCL_UTF_MAX == 4 if ((pattern[0] & 0xFC00) == 0xD800) { if ((pattern + 1 < patternEnd) && ((pattern[1] & 0xFC00) == 0xDC00)) { pattern++; } } #endif pattern++; continue; } /* * If the next pattern character is '\', just strip off the '\' so we * do exact matching on the character that follows. */ if (p == '\\') { if (++pattern == patternEnd) { return 0; } } /* * There's no special character. Just make sure that the next bytes of * each string match. */ #if TCL_UTF_MAX == 4 p = *pattern; if ((p & 0xFC00) == 0xD800) { if ((pattern + 1 < patternEnd) && ((pattern[1] & 0xFC00) == 0xDC00)) { p = (((p&0x3FF)<<10) | (pattern[1]&0x3FF)) + 0x10000; pattern++; } } q = *string; if ((q & 0xFC00) == 0xD800) { if ((string + 1 < stringEnd) && ((string[1] & 0xFC00) == 0xDC00)) { q = (((q&0x3FF)<<10) | (string[1]&0x3FF)) + 0x10000; string++; } } if (nocase) { if (TclUCS4ToLower(q) != TclUCS4ToLower(p)) { return 0; } } else if (q != p) { return 0; } #else if (nocase) { if (Tcl_UniCharToLower(*string) != Tcl_UniCharToLower(*pattern)) { return 0; } } else if (*string != *pattern) { return 0; } #endif string++; pattern++; } } /* * Local Variables: * mode: c * c-basic-offset: 4 * fill-column: 78 * End: */ |
Changes to jni/tcl/generic/tclUtil.c.
︙ | ︙ | |||
363 364 365 366 367 368 369 370 371 372 373 374 375 376 | * closely tied together with the rules for parsing and evaluating scripts, * and will need to evolve in sync. */ /* *---------------------------------------------------------------------- * * TclMaxListLength -- * * Given 'bytes' pointing to 'numBytes' bytes, scan through them and * count the number of whitespace runs that could be list element * separators. If 'numBytes' is -1, scan to the terminating '\0'. Not a * full list parser. Typically used to get a quick and dirty overestimate * of length size in order to allocate space for an actual list parser to | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | * closely tied together with the rules for parsing and evaluating scripts, * and will need to evolve in sync. */ /* *---------------------------------------------------------------------- * * UtfToUniChar -- * * Wrapper to Tcl_UtfToUniChar() capable of dealing with * UCS4 when compiled with TCL_UTF_MAX > 3. * * Results: * *chPtr is filled with the full unicode character, and the * return value is the number of bytes from the UTF-8 string that * were consumed. * * Side effects: * None. * *---------------------------------------------------------------------- */ static int #if TCL_UTF_MAX != 4 inline #endif UtfToUniChar( const char *src, int *chPtr) { Tcl_UniChar ch = 0; int uch, len; len = TclUtfToUniChar(src, &ch); uch = ch; #if TCL_UTF_MAX == 4 if (!len) { len = TclUtfToUniChar(src, &ch); uch = ((uch & 0x3FF) << 10) + 0x10000 + (ch & 0x3FF); } #endif *chPtr = uch; return len; } /* *---------------------------------------------------------------------- * * TclMaxListLength -- * * Given 'bytes' pointing to 'numBytes' bytes, scan through them and * count the number of whitespace runs that could be list element * separators. If 'numBytes' is -1, scan to the terminating '\0'. Not a * full list parser. Typically used to get a quick and dirty overestimate * of length size in order to allocate space for an actual list parser to |
︙ | ︙ | |||
1670 1671 1672 1673 1674 1675 1676 | Tcl_Backslash( const char *src, /* Points to the backslash character of a * backslash sequence. */ int *readPtr) /* Fill in with number of characters read from * src, unless NULL. */ { char buf[TCL_UTF_MAX*2]; | | | | 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 | Tcl_Backslash( const char *src, /* Points to the backslash character of a * backslash sequence. */ int *readPtr) /* Fill in with number of characters read from * src, unless NULL. */ { char buf[TCL_UTF_MAX*2]; int ch; buf[0] = '\0'; Tcl_UtfBackslash(src, readPtr, buf); UtfToUniChar(buf, &ch); return (char) ch; } /* *---------------------------------------------------------------------- * * TclTrimRight -- |
︙ | ︙ | |||
1699 1700 1701 1702 1703 1704 1705 | *---------------------------------------------------------------------- */ int TclTrimRight( const char *bytes, /* String to be trimmed... */ int numBytes, /* ...and its length in bytes */ | | | | > | > > | > > > > > > > > | > > > > > > > > > > > > > > > > > > > | > > | > > > > | > > > > > > | > < < | | | < < < | > > > | 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 | *---------------------------------------------------------------------- */ int TclTrimRight( const char *bytes, /* String to be trimmed... */ int numBytes, /* ...and its length in bytes */ /* Calls to UtfToUniChar() in this routine * rely on (bytes[numBytes] == '\0'). */ const char *trim, /* String of trim characters... */ int numTrim) /* ...and its length in bytes */ /* Calls to UtfToUniChar() in this routine * rely on (trim[numTrim] == '\0'). */ { const char *pp, *p = bytes + numBytes, *q; int i; Tcl_DString ds; /* Empty strings -> nothing to do */ if ((numBytes == 0) || (numTrim == 0)) { return 0; } /* * See if we can optimize. */ for (i = 0; i < numTrim; i++) { if (UCHAR(trim[i]) >= 0x80) { goto slowPath; } } /* * Same logic as below, but working with plain ASCII trim string. */ do { for (i = 0; i < numTrim; i++) { if (p[-1] == trim[i]) { break; } } if (i >= numTrim) { break; } p--; } while (p > bytes); goto done; /* * Make trim string into unicode array. */ slowPath: Tcl_DStringInit(&ds); q = trim; do { int uch = 0, qInc = UtfToUniChar(q, &uch); q += qInc; Tcl_DStringAppend(&ds, (char *) &uch, sizeof(int)); } while (q < trim + numTrim); numTrim = Tcl_DStringLength(&ds) / sizeof(int); /* * Outer loop: iterate over string to be trimmed. */ do { int uch, pInc = 0; pp = TclUtfPrev(p, bytes); do { pp += pInc; pInc = UtfToUniChar(pp, &uch); } while (pp + pInc < p); /* * Inner loop: scan trim string for match to current character. */ for (i = 0; i < numTrim; i++) { if (uch == ((int *)Tcl_DStringValue(&ds))[i]) { break; } } if (i >= numTrim) { /* * No match; trim task done; *p is last non-trimmed char. */ break; } p = pp; } while (p > bytes); Tcl_DStringFree(&ds); done: return numBytes - (p - bytes); } /* *---------------------------------------------------------------------- * * TclTrimLeft -- |
︙ | ︙ | |||
1779 1780 1781 1782 1783 1784 1785 | *---------------------------------------------------------------------- */ int TclTrimLeft( const char *bytes, /* String to be trimmed... */ int numBytes, /* ...and its length in bytes */ | | | | > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < | < < < < | | | < < < | > > > | 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 | *---------------------------------------------------------------------- */ int TclTrimLeft( const char *bytes, /* String to be trimmed... */ int numBytes, /* ...and its length in bytes */ /* Calls to UtfToUniChar() in this routine * rely on (bytes[numBytes] == '\0'). */ const char *trim, /* String of trim characters... */ int numTrim) /* ...and its length in bytes */ /* Calls to UtfToUniChar() in this routine * rely on (trim[numTrim] == '\0'). */ { const char *p = bytes, *q; int i; Tcl_DString ds; /* Empty strings -> nothing to do */ if ((numBytes == 0) || (numTrim == 0)) { return 0; } /* * See if we can optimize. */ for (i = 0; i < numTrim; i++) { if (UCHAR(trim[i]) >= 0x80) { goto slowPath; } } /* * Same logic as below, but working with plain ASCII trim string. */ do { for (i = 0; i < numTrim; i++) { if (p[0] == trim[i]) { break; } } if (i >= numTrim) { break; } p++; numBytes--; } while (numBytes > 0); goto done; /* * Make trim string into unicode array. */ slowPath: Tcl_DStringInit(&ds); q = trim; do { int uch = 0, qInc = UtfToUniChar(q, &uch); q += qInc; Tcl_DStringAppend(&ds, (char *) &uch, sizeof(int)); } while (q < trim + numTrim); numTrim = Tcl_DStringLength(&ds) / sizeof(int); /* * Outer loop: iterate over string to be trimmed. */ do { int uch = 0, pInc = UtfToUniChar(p, &uch); /* * Inner loop: scan trim string for match to current character. */ for (i = 0; i < numTrim; i++) { if (uch == ((int *)Tcl_DStringValue(&ds))[i]) { break; } } if (i >= numTrim) { /* * No match; trim task done; *p is first non-trimmed char. */ break; } p += pInc; numBytes -= pInc; } while (numBytes > 0); Tcl_DStringFree(&ds); done: return p - bytes; } /* *---------------------------------------------------------------------- * * TclTrim -- |
︙ | ︙ | |||
1874 1875 1876 1877 1878 1879 1880 | /* When bytes is NUL-terminated, returns 0 <= trimLeft <= numBytes */ trimLeft = TclTrimLeft(bytes, numBytes, trim, numTrim); numBytes -= trimLeft; /* If we did not trim the whole string, it starts with a character * that we will not trim. Skip over it. */ if (numBytes > 0) { | < | | < < < < < | 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 | /* When bytes is NUL-terminated, returns 0 <= trimLeft <= numBytes */ trimLeft = TclTrimLeft(bytes, numBytes, trim, numTrim); numBytes -= trimLeft; /* If we did not trim the whole string, it starts with a character * that we will not trim. Skip over it. */ if (numBytes > 0) { int len, uch; const char *first = bytes + trimLeft; len = UtfToUniChar(first, &uch); bytes += len; numBytes -= (bytes - first); if (numBytes > 0) { /* When bytes is NUL-terminated, returns * 0 <= trimRight <= numBytes */ trimRight = TclTrimRight(bytes, numBytes, trim, numTrim); |
︙ | ︙ | |||
2184 2185 2186 2187 2188 2189 2190 | int Tcl_StringCaseMatch( const char *str, /* String. */ const char *pattern, /* Pattern, which may contain special * characters. */ int nocase) /* 0 for case sensitive, 1 for insensitive */ { | | < | 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 | int Tcl_StringCaseMatch( const char *str, /* String. */ const char *pattern, /* Pattern, which may contain special * characters. */ int nocase) /* 0 for case sensitive, 1 for insensitive */ { int p, charLen, ch1, ch2; while (1) { p = *pattern; /* * See if we're at the end of both the pattern and the string. If so, * we succeeded. If we're at the end of the pattern but not at the end |
︙ | ︙ | |||
2226 2227 2228 2229 2230 2231 2232 | } /* * This is a special case optimization for single-byte utf. */ if (UCHAR(*pattern) < 0x80) { | | | | | | | | | | | | | | | | | | | | 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 | } /* * This is a special case optimization for single-byte utf. */ if (UCHAR(*pattern) < 0x80) { ch2 = (int) (nocase ? tolower(UCHAR(*pattern)) : UCHAR(*pattern)); } else { UtfToUniChar(pattern, &ch2); if (nocase) { ch2 = TclUCS4ToLower(ch2); } } while (1) { /* * Optimization for matching - cruise through the string * quickly if the next char in the pattern isn't a special * character */ if ((p != '[') && (p != '?') && (p != '\\')) { if (nocase) { while (*str) { charLen = UtfToUniChar(str, &ch1); if (ch2==ch1 || ch2==TclUCS4ToLower(ch1)) { break; } str += charLen; } } else { /* * There's no point in trying to make this code * shorter, as the number of bytes you want to compare * each time is non-constant. */ while (*str) { charLen = UtfToUniChar(str, &ch1); if (ch2 == ch1) { break; } str += charLen; } } } if (Tcl_StringCaseMatch(str, pattern, nocase)) { return 1; } if (*str == '\0') { return 0; } str += UtfToUniChar(str, &ch1); } } /* * Check for a "?" as the next pattern character. It matches any * single character. */ if (p == '?') { pattern++; str += UtfToUniChar(str, &ch1); continue; } /* * Check for a "[" as the next pattern character. It is followed by a * list of characters that are acceptable, or by a range (two * characters separated by "-"). */ if (p == '[') { int startChar = 0, endChar = 0; pattern++; if (UCHAR(*str) < 0x80) { ch1 = (int) (nocase ? tolower(UCHAR(*str)) : UCHAR(*str)); str++; } else { str += UtfToUniChar(str, &ch1); if (nocase) { ch1 = TclUCS4ToLower(ch1); } } while (1) { if ((*pattern == ']') || (*pattern == '\0')) { return 0; } if (UCHAR(*pattern) < 0x80) { startChar = (int) (nocase ? tolower(UCHAR(*pattern)) : UCHAR(*pattern)); pattern++; } else { pattern += UtfToUniChar(pattern, &startChar); if (nocase) { startChar = TclUCS4ToLower(startChar); } } if (*pattern == '-') { pattern++; if (*pattern == '\0') { return 0; } if (UCHAR(*pattern) < 0x80) { endChar = (int) (nocase ? tolower(UCHAR(*pattern)) : UCHAR(*pattern)); pattern++; } else { pattern += UtfToUniChar(pattern, &endChar); if (nocase) { endChar = TclUCS4ToLower(endChar); } } if (((startChar <= ch1) && (ch1 <= endChar)) || ((endChar <= ch1) && (ch1 <= startChar))) { /* * Matches ranges of form [a-z] or [z-a]. */ |
︙ | ︙ | |||
2380 2381 2382 2383 2384 2385 2386 | } /* * There's no special character. Just make sure that the next bytes of * each string match. */ | | | | | 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 | } /* * There's no special character. Just make sure that the next bytes of * each string match. */ str += UtfToUniChar(str, &ch1); pattern += UtfToUniChar(pattern, &ch2); if (nocase) { if (TclUCS4ToLower(ch1) != TclUCS4ToLower(ch2)) { return 0; } } else if (ch1 != ch2) { return 0; } } } |
︙ | ︙ |
jni/tcl/library/clock.tcl became a regular file.
︙ | ︙ |
Changes to jni/tcl/tests/cmdIL.test.
︙ | ︙ | |||
15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ::tcltest::loadTestedCommands catch [list package require -exact Tcltest [info patchlevel]] # Used for constraining memory leak tests testConstraint memory [llength [info commands memory]] testConstraint testobj [llength [info commands testobj]] test cmdIL-1.1 {Tcl_LsortObjCmd procedure} -returnCodes error -body { lsort } -result {wrong # args: should be "lsort ?-option value ...? list"} test cmdIL-1.2 {Tcl_LsortObjCmd procedure} -returnCodes error -body { lsort -foo {1 3 2 5} } -result {bad option "-foo": must be -ascii, -command, -decreasing, -dictionary, -increasing, -index, -indices, -integer, -nocase, -real, -stride, or -unique} | > | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | ::tcltest::loadTestedCommands catch [list package require -exact Tcltest [info patchlevel]] # Used for constraining memory leak tests testConstraint memory [llength [info commands memory]] testConstraint testobj [llength [info commands testobj]] testConstraint fullutf [expr {[format %c 0x010000] ne "\uFFFD"}] test cmdIL-1.1 {Tcl_LsortObjCmd procedure} -returnCodes error -body { lsort } -result {wrong # args: should be "lsort ?-option value ...? list"} test cmdIL-1.2 {Tcl_LsortObjCmd procedure} -returnCodes error -body { lsort -foo {1 3 2 5} } -result {bad option "-foo": must be -ascii, -command, -decreasing, -dictionary, -increasing, -index, -indices, -integer, -nocase, -real, -stride, or -unique} |
︙ | ︙ | |||
500 501 502 503 504 505 506 507 508 509 510 511 512 513 | test_lsort 0 } -result 0 -cleanup { rename test_lsort "" } test cmdIL-5.6 {lsort with multiple list-style index options} { lsort -index {1 2 3} -index 0 {{a b} {c d} {b e}} } {{a b} {b e} {c d}} # Compiled version test cmdIL-6.1 {lassign command syntax} -returnCodes error -body { apply {{} { lassign }} } -result {wrong # args: should be "lassign list ?varName ...?"} test cmdIL-6.2 {lassign command syntax} { apply {{} { lassign x }} | > > > > > > > > > > > > > > > > > > > > > | 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | test_lsort 0 } -result 0 -cleanup { rename test_lsort "" } test cmdIL-5.6 {lsort with multiple list-style index options} { lsort -index {1 2 3} -index 0 {{a b} {c d} {b e}} } {{a b} {b e} {c d}} test cmdIL-5.7 {lsort unicode beyond U+FFFF} fullutf { lsort {\uD83D\uDE03 \uD83D\uDE02 \uD83D\uDE04} } "\uD83D\uDE02 \uD83D\uDE03 \uD83D\udE04" test cmdIL-5.7 {lsort unicode beyond U+FFFF} fullutf { lsort -decreasing {\uD83D\uDE03 \uD83D\uDE02 \uD83D\uDE04} } "\uD83D\uDE04 \uD83D\uDE03 \uD83D\udE02" test cmdIL-5.8 {lsort unicode beyond U+FFFF} fullutf { lsort -nocase {\U0001F603 \U0001F602 \U0001F604} } "\U0001F602 \U0001F603 \U0001F604" test cmdIL-5.9 {lsort unicode beyond U+FFFF} fullutf { lsort -dictionary {\U0001F603x1 \U0001F602y1 \U0001F602y \U0001F603xx} } "\U0001F602y \U0001F602y1 \U0001F603x1 \U0001F603xx" test cmdIL-5.9 {lsort unicode beyond U+FFFF} fullutf { lsort -dictionary {b\U0001F60320 c\U0001F60230 c\U0001F6023x b\U0001F6032} } "b\U0001F6032 b\U0001F60320 c\U0001F6023x c\U0001F60230" test cmdIL-5.10 {lsort unicode beyond U+FFFF} fullutf { lsort -nocase {b\U00010428a B\U00010400C} } "b\U00010428a B\U00010400C" test cmdIL-5.11 {lsort unicode beyond U+FFFF} fullutf { lsort -dictionary -nocase {b\U00010428a B\U00010400C} } "b\U00010428a B\U00010400C" # Compiled version test cmdIL-6.1 {lassign command syntax} -returnCodes error -body { apply {{} { lassign }} } -result {wrong # args: should be "lassign list ?varName ...?"} test cmdIL-6.2 {lassign command syntax} { apply {{} { lassign x }} |
︙ | ︙ |
Changes to jni/tcl/tests/scan.test.
︙ | ︙ | |||
83 84 85 86 87 88 89 90 91 92 93 94 95 96 | } } } testConstraint ieeeFloatingPoint [testIEEE] testConstraint wideIs64bit \ [expr {(wide(0x80000000) > 0) && (wide(0x8000000000000000) < 0)}] test scan-1.1 {BuildCharSet, CharInSet} { list [scan foo {%[^o]} x] $x } {1 f} test scan-1.2 {BuildCharSet, CharInSet} { list [scan \]foo {%[]f]} x] $x } {1 \]f} | > | 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | } } } testConstraint ieeeFloatingPoint [testIEEE] testConstraint wideIs64bit \ [expr {(wide(0x80000000) > 0) && (wide(0x8000000000000000) < 0)}] testConstraint fullutf [expr {[format %c 0x010000] ne "\uFFFD"}] test scan-1.1 {BuildCharSet, CharInSet} { list [scan foo {%[^o]} x] $x } {1 f} test scan-1.2 {BuildCharSet, CharInSet} { list [scan \]foo {%[]f]} x] $x } {1 \]f} |
︙ | ︙ | |||
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 | return $d } Inf test scan-14.2 {negative infinity} { scan -Inf %g d return $d } -Inf # TODO - also need to scan NaN's catch {rename int_range {}} # cleanup ::tcltest::cleanupTests return # Local Variables: # mode: tcl # End: | > > > > > > > > > > > > > > > > > > > > > > > | 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 | return $d } Inf test scan-14.2 {negative infinity} { scan -Inf %g d return $d } -Inf # scan unicode test scan-15.1 {full unicode} fullutf { scan X\U1F602 X%c a return $a } [expr {0x1F602}] test scan-15.2 {full unicode} fullutf { scan \U1F602\uD83D\uDE04Hello %c%\[\U0001F604\]%s a b c return [list $a $b $c] } [list [expr {0x1F602}] \uD83D\uDE04 Hello] test scan-15.3 {full unicode} fullutf { scan \U1F602Hello\uD83D\uDE04 %c%\[^\U0001F604\]%s a b c return [list $a $b $c] } [list [expr {0x1F602}] Hello \uD83D\uDE04] test scan-15.4 {full unicode} fullutf { scan \U1F602\uD83D\uDE03Hello %\[\U0001F602-\U0001F604\] a return $a } \uD83D\uDE02\U1F603 test scan-15.5 {full unicode} fullutf { scan \U1F602\uD83D\uDE03Hello123 %\[\U0001F602-\U0001F604a-zA-Z\] a return $a } \uD83D\uDE02\U1F603Hello # TODO - also need to scan NaN's catch {rename int_range {}} # cleanup ::tcltest::cleanupTests return # Local Variables: # mode: tcl # End: |
Changes to jni/tcl/tests/split.test.
︙ | ︙ | |||
11 12 13 14 15 16 17 18 19 20 21 22 23 24 | # See the file "license.terms" for information on usage and redistribution of # this file, and for a DISCLAIMER OF ALL WARRANTIES. if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest namespace import -force ::tcltest::* } test split-1.1 {basic split commands} { split "a\n b\t\r c\n " } {a {} b {} {} c {} {}} test split-1.2 {basic split commands} { split "word 1xyzword 2zword 3" xyz } {{word 1} {} {} {word 2} {word 3}} | > | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | # See the file "license.terms" for information on usage and redistribution of # this file, and for a DISCLAIMER OF ALL WARRANTIES. if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest namespace import -force ::tcltest::* } testConstraint fullutf [expr {[format %c 0x010000] ne "\uFFFD"}] test split-1.1 {basic split commands} { split "a\n b\t\r c\n " } {a {} b {} {} c {} {}} test split-1.2 {basic split commands} { split "word 1xyzword 2zword 3" xyz } {{word 1} {} {} {word 2} {word 3}} |
︙ | ︙ | |||
66 67 68 69 70 71 72 | } {{} ab cd {} ef {}} test split-1.13 {basic split commands} { split "12,34,56," {,} } {12 34 56 {}} test split-1.14 {basic split commands} { split ",12,,,34,56," {,} } {{} 12 {} {} 34 56 {}} | | | | > > > > > > > > > > > > > > > | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | } {{} ab cd {} ef {}} test split-1.13 {basic split commands} { split "12,34,56," {,} } {12 34 56 {}} test split-1.14 {basic split commands} { split ",12,,,34,56," {,} } {{} 12 {} {} 34 56 {}} test split-1.15 {basic split commands} fullutf { split "a\U0001F4A9b" {} } "a \U0001F4A9 b" test split-1.16 {basic split commands} fullutf { split "\uD83D\uDE02Hello\uD83D\uDE02World\uD83D\uDE02" \U0001F602 } {{} Hello World {}} test split-1.17 {basic split commands} fullutf { split "\U0001F602Hello\U0001F602World\U0001F602" \uD83D\uDE02 } {{} Hello World {}} test split-1.18 {basic split commands} fullutf { split "\U0001F602\U0001F602\U0001F602" \uD83D\uDE02 } {{} {} {} {}} test split-1.19 {basic split commands} fullutf { proc foo args { tailcall split {*}$args } foo "\U0001F602Hello\U0001F602World\U0001F602" \U0001F602 } {{} Hello World {}} test split-2.1 {split errors} { list [catch split msg] $msg $errorCode } {1 {wrong # args: should be "split string ?splitChars?"} {TCL WRONGARGS}} test split-2.2 {split errors} { list [catch {split a b c} msg] $msg $errorCode } {1 {wrong # args: should be "split string ?splitChars?"} {TCL WRONGARGS}} |
︙ | ︙ |
Changes to jni/tcl/tests/string.test.
︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 30 31 32 33 | ::tcltest::loadTestedCommands catch [list package require -exact Tcltest [info patchlevel]] # Some tests require the testobj command testConstraint testobj [expr {[info commands testobj] != {}}] testConstraint testindexobj [expr {[info commands testindexobj] != {}}] testConstraint tip389 [expr {[string length \U010000] == 2}] testConstraint testbytestring [expr {[info commands testbytestring] != {}}] # Used for constraining memory leak tests testConstraint memory [llength [info commands memory]] test string-1.1 {error conditions} { | > | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | ::tcltest::loadTestedCommands catch [list package require -exact Tcltest [info patchlevel]] # Some tests require the testobj command testConstraint testobj [expr {[info commands testobj] != {}}] testConstraint testindexobj [expr {[info commands testindexobj] != {}}] testConstraint fullutf [expr {[format %c 0x010000] ne "\uFFFD"}] testConstraint tip389 [expr {[string length \U010000] == 2}] testConstraint testbytestring [expr {[info commands testbytestring] != {}}] # Used for constraining memory leak tests testConstraint memory [llength [info commands memory]] test string-1.1 {error conditions} { |
︙ | ︙ | |||
1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 | } 6 test string-21.13 {string wordend, unicode} { string wordend "xyz\u2045de fg" 0 } 3 test string-21.14 {string wordend, unicode} { string wordend "\uC700\uC700 abc" 8 } 6 test string-22.1 {string wordstart} { list [catch {string word a} msg] $msg } {1 {unknown or ambiguous subcommand "word": must be bytelength, cat, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, reverse, tolower, totitle, toupper, trim, trimleft, trimright, wordend, or wordstart}} test string-22.2 {string wordstart} { list [catch {string wordstart a} msg] $msg } {1 {wrong # args: should be "string wordstart string index"}} | > > > > > > > > > | 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 | } 6 test string-21.13 {string wordend, unicode} { string wordend "xyz\u2045de fg" 0 } 3 test string-21.14 {string wordend, unicode} { string wordend "\uC700\uC700 abc" 8 } 6 test string-21.15 {string trim, unicode} fullutf { string trim "\U1F602Hello world!\U1F602" \U1F602 } "Hello world!" test string-21.16 {string trimleft, unicode} fullutf { string trimleft "\U1F602Hello world!\U1F602" \U1F602 } "Hello world!\U1F602" test string-21.17 {string trimright, unicode} fullutf { string trimright "\U1F602Hello world!\U1F602" \U1F602 } "\U1F602Hello world!" test string-22.1 {string wordstart} { list [catch {string word a} msg] $msg } {1 {unknown or ambiguous subcommand "word": must be bytelength, cat, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, reverse, tolower, totitle, toupper, trim, trimleft, trimright, wordend, or wordstart}} test string-22.2 {string wordstart} { list [catch {string wordstart a} msg] $msg } {1 {wrong # args: should be "string wordstart string index"}} |
︙ | ︙ |
Changes to jni/tcl/tests/stringComp.test.
︙ | ︙ | |||
22 23 24 25 26 27 28 29 30 31 32 33 34 35 | ::tcltest::loadTestedCommands catch [list package require -exact Tcltest [info patchlevel]] # Some tests require the testobj command testConstraint testobj [expr {[info commands testobj] != {}}] testConstraint memory [llength [info commands memory]] if {[testConstraint memory]} { proc getbytes {} { set lines [split [memory info] \n] return [lindex $lines 3 3] } proc leaktest {script {iterations 3}} { | > | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | ::tcltest::loadTestedCommands catch [list package require -exact Tcltest [info patchlevel]] # Some tests require the testobj command testConstraint testobj [expr {[info commands testobj] != {}}] testConstraint fullutf [expr {[format %c 0x010000] ne "\uFFFD"}] testConstraint memory [llength [info commands memory]] if {[testConstraint memory]} { proc getbytes {} { set lines [split [memory info] \n] return [lindex $lines 3 3] } proc leaktest {script {iterations 3}} { |
︙ | ︙ | |||
181 182 183 184 185 186 187 188 189 190 191 192 | } 0 {} {binary neq} { string compare [binary format a100a 0 1] [binary format a100a 0 0] } 1 {} {binary neq inequal length} { string compare [binary format a20a 0 1] [binary format a100a 0 0] } 1 {} } { if {$tname eq ""} { continue } if {$tcode eq ""} { set tcode ok } test stringComp-2.[incr i] "string compare, $tname" \ -body [list eval $tbody] \ | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | | 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | } 0 {} {binary neq} { string compare [binary format a100a 0 1] [binary format a100a 0 0] } 1 {} {binary neq inequal length} { string compare [binary format a20a 0 1] [binary format a100a 0 0] } 1 {} {unicode corner cases} { string compare \uD7FF \uD800] } -1 {} {unicode corner cases} { string compare \uD800\uD7FF \uD800\uD800] } -1 {} {unicode corner cases} { string compare \uD800\uD800 \uD800\uD7FF] } 1 {} {unicode corner cases} { string compare \uDBFF \uDC00 } -1 {} {unicode corner cases} { string compare \uD83D \uDE00 } -1 {} {unicode corner cases} { string compare \uE000 \uDFFF } 1 {} {unicode beyond U+FFFF} { string compare \uFFFF \U00010000 } -1 {} {unicode beyond U+FFFF} { string compare \U00010000 \U0000FFFF } 1 {} {unicode beyond U+FFFF} { string compare ab \U0001F600\U0001F601\U0001F602\U0001F603 } -1 {} {unicode beyond U+FFFF} { string compare \U0001F600\U0001F601\U0001F602\U0001F603 ab } 1 {} {unicode beyond U+FFFF} { string compare \U0001F601\U0001F602 \U0001F600\U0001F601 } 1 {} {unicode beyond U+FFFF} { string compare \uD83D\uDE00\uD83D\uDE01 \U0001F600\U0001F601 } 0 {} {unicode beyond U+FFFF} { string compare \uD83D\uDE00 \uD83D\uDE01\U0001F600\U0001F601 } -1 {} } { if {$tname eq ""} { continue } if {$tcode eq ""} { set tcode ok } # not nice but... if {$tname in {{unicode corner cases} {unicode beyond U+FFFF}}} { set cnstr fullutf } else { set cnstr {} } test stringComp-2.[incr i] "string compare, $tname" \ -body [list eval $tbody] \ -returnCodes $tcode -result $tresult -constraints $cnstr test stringComp-2.[incr i] "string compare bc, $tname" \ -body "[list proc foo {} $tbody];foo" \ -returnCodes $tcode -result $tresult -constraints $cnstr if {"error" ni $tcode} { set tresult [expr {!$tresult}] } else { set tresult [string map {compare equal} $tresult] } set tbody [string map {compare equal} $tbody] test stringComp-2.[incr i] "string equal, $tname" \ -body [list eval $tbody] \ -returnCodes $tcode -result $tresult -constraints $cnstr test stringComp-2.[incr i] "string equal bc, $tname" \ -body "[list proc foo {} $tbody];foo" \ -returnCodes $tcode -result $tresult -constraints $cnstr } # need a few extra tests short abbr cmd test stringComp-3.1 {string compare, shortest method name} { proc foo {} {string co abcde ABCDE} foo } 1 |
︙ | ︙ | |||
687 688 689 690 691 692 693 694 695 696 697 698 699 700 | [string match *a*l*\u0000*123 $longString] \ [string match *a*l*\u0000*123* $longString] \ [string match *a*l*\u0000*cba* $longString] \ [string match *===* $longString] } foo } {0 1 1 1 0 0} ## string range test stringComp-12.1 {Bug 3588366: end-offsets before start} { apply {s { string range $s 0 end-5 }} 12345 } {} | > > > > > > > > > > > > > > > > > > > > | 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 | [string match *a*l*\u0000*123 $longString] \ [string match *a*l*\u0000*123* $longString] \ [string match *a*l*\u0000*cba* $longString] \ [string match *===* $longString] } foo } {0 1 1 1 0 0} test stringComp-11.55 {string match, unicode} fullutf { string match *\U1F602* Hello\U1F602World } 1 test stringComp-11.56 {string match, unicode} fullutf { string match *\[\U1F602\]* Hello\U1F602World } 1 test stringComp-11.57 {string match, unicode} fullutf { string match *\[\U1F602-\U1F604\]* Hello\U1F603World } 1 test stringComp-11.58 {string match, unicode} fullutf { proc foo {p s} { return [string match $p $s] } list \ [foo *\[\U1F602-\U1F604\]* Hello\uD83D\uDE03World] \ [foo *\[\U1F602-\U1F604\]* Hello\uD83D\uDE05World] \ [foo *\[\U1F602-\U1F604\]* Hello\uD83DWorld] \ [foo *\[\U1F602-\U1F604\]* Hello\uDE02World\uDE04] \ [foo *\[\U1F602-\U1F604\]* Hello\uD83DW\uDE03] } {1 0 0 0 0} ## string range test stringComp-12.1 {Bug 3588366: end-offsets before start} { apply {s { string range $s 0 end-5 }} 12345 } {} |
︙ | ︙ |
Changes to jni/tcl/tests/utf.test.
︙ | ︙ | |||
1494 1495 1496 1497 1498 1499 1500 | incr count } variable count 1 UniCharCaseCmpTest < a b UniCharCaseCmpTest > b a UniCharCaseCmpTest > B a UniCharCaseCmpTest > aBcB abca | | | | | | 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 | incr count } variable count 1 UniCharCaseCmpTest < a b UniCharCaseCmpTest > b a UniCharCaseCmpTest > B a UniCharCaseCmpTest > aBcB abca UniCharCaseCmpTest < \uFFFF [format %c 0x10000] fullutf UniCharCaseCmpTest < \uFFFF \U10000 fullutf UniCharCaseCmpTest > [format %c 0x10000] \uFFFF fullutf UniCharCaseCmpTest > \U10000 \uFFFF fullutf unset count rename UniCharCaseCmpTest {} |
︙ | ︙ |