Diff
Not logged in

Differences From Artifact [1d09eea1b6]:

To Artifact [0cc57f9f6f]:


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
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







-
+











+
+
+
+
+
+
+
+



















-
+











+
+
+
+
+
+
+
+
+







 *---------------------------------------------------------------------------
 */

#if TCL_UTF_MAX > 3
char *
Tcl_UniCharToUtfDString(
    const int *uniStr,	/* Unicode string to convert to UTF-8. */
    int uniLength,		/* Length of Unicode string (must be >= 0). */
    int uniLength,		/* Length of Unicode string. */
    Tcl_DString *dsPtr)		/* UTF-8 representation of string is appended
				 * to this previously initialized DString. */
{
    const int *w, *wEnd;
    char *p, *string;
    int oldLength;

    /*
     * UTF-8 string length in bytes will be <= Unicode string length * 4.
     */

    if (uniLength < 0) {
	uniLength = 0;
	w = uniStr;
	while (*w != '\0') {
	    uniLength++;
	    w++;
	}
    }
    oldLength = Tcl_DStringLength(dsPtr);
    Tcl_DStringSetLength(dsPtr, oldLength + (uniLength + 1) * 4);
    string = Tcl_DStringValue(dsPtr) + oldLength;

    p = string;
    wEnd = uniStr + uniLength;
    for (w = uniStr; w < wEnd; ) {
	p += Tcl_UniCharToUtf(*w, p);
	w++;
    }
    Tcl_DStringSetLength(dsPtr, oldLength + (p - string));

    return string;
}
#endif /* TCL_UTF_MAX > 3 */

char *
Tcl_Utf16ToUtfDString(
    const unsigned short *uniStr,	/* Utf-16 string to convert to UTF-8. */
    int uniLength,		/* Length of Utf-16 string (must be >= 0). */
    int uniLength,		/* Length of Utf-16 string. */
    Tcl_DString *dsPtr)		/* UTF-8 representation of string is appended
				 * to this previously initialized DString. */
{
    const unsigned short *w, *wEnd;
    char *p, *string;
    int oldLength, len = 1;

    /*
     * UTF-8 string length in bytes will be <= Utf16 string length * 3.
     */

    if (uniLength < 0) {

	uniLength = 0;
	w = uniStr;
	while (*w != '\0') {
	    uniLength++;
	    w++;
	}
    }
    oldLength = Tcl_DStringLength(dsPtr);
    Tcl_DStringSetLength(dsPtr, oldLength + (uniLength + 1) * 3);
    string = Tcl_DStringValue(dsPtr) + oldLength;

    p = string;
    wEnd = uniStr + uniLength;
    for (w = uniStr; w < wEnd; ) {
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
705
706
707
708
709
710
711


712
713
714
715
716
717
718







-
-







 *
 *---------------------------------------------------------------------------
 */

#if TCL_UTF_MAX == 3
#	undef Tcl_UtfToUniChar
#	define Tcl_UtfToUniChar Tcl_UtfToUtf16
#	undef Tcl_UniCharLen
#	define Tcl_UniCharLen Tcl_Utf16Len
#endif

int
Tcl_NumUtfChars(
    register const char *src,	/* The UTF-8 string to measure. */
    int length)			/* The length of the string in bytes, or -1
				 * for strlen(string). */
1629
1630
1631
1632
1633
1634
1635
1636

1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662

1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683

1684
1685
1686
1687
1688
1689
1690
1644
1645
1646
1647
1648
1649
1650

1651
1652
1653














1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684

1685
1686
1687
1688
1689
1690
1691
1692







-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-










+




















-
+







 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

#if TCL_UTF_MAX > 3
#if TCL_UTF_MAX == 3 && !defined(TCL_NO_DEPRECATED) && TCL_MAJOR_VERSION < 9
int
Tcl_UniCharLen(
    const int *uniStr)	/* Unicode string to find length of. */
{
    int len = 0;

    while (*uniStr != '\0') {
	len++;
	uniStr++;
    }
    return len;
}
#endif /* TCL_UTF_MAX > 3 */

int
Tcl_Utf16Len(
    const unsigned short *utf16Str)	/* Unicode string to find length of. */
{
    int len = 0;

    while (*utf16Str != '\0') {
	len++;
	utf16Str++;
    }
    return len;
}
#endif /* TCL_UTF_MAX == 3 && !defined(TCL_NO_DEPRECATED) */

/*
 *----------------------------------------------------------------------
 *
 * Tcl_UniCharNcmp --
 *
 *	Compare at most numChars unichars of string ucs to string uct.
 *	Both ucs and uct are assumed to be at least numChars unichars long.
 *
 * Results:
 *	Return <0 if ucs < uct, 0 if ucs == uct, or >0 if ucs > uct.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

#if TCL_UTF_MAX > 3
int
Tcl_UniCharNcmp(
Tcl_Utf32Ncmp(
    const int *ucs,	/* Unicode string to compare to uct. */
    const int *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
1704
1705
1706
1707
1708
1709
1710
1711

1712
1713
1714
1715
1716
1717
1718
1706
1707
1708
1709
1710
1711
1712

1713
1714
1715
1716
1717
1718
1719
1720







-
+







    }
    return 0;
#endif /* WORDS_BIGENDIAN */
}
#endif /* TCL_UTF_MAX > 3 */

int
Tcl_Utf16Ncmp(
Tcl_UniCharNcmp(
    const unsigned short *ucs,	/* Unicode string to compare to uct. */
    const unsigned short *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
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
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







-
+



















-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

#if TCL_UTF_MAX > 3
int
Tcl_UniCharNcasecmp(
Tcl_Utf32Ncasecmp(
    const int *ucs,	/* Unicode string to compare to uct. */
    const int *uct,	/* Unicode string ucs is compared to. */
    unsigned long numChars)	/* Number of unichars to compare. */
{
    for ( ; numChars != 0; numChars--, ucs++, uct++) {
	if (*ucs != *uct) {
	    int lcs = Tcl_UniCharToLower(*ucs);
	    int lct = Tcl_UniCharToLower(*uct);

	    if (lcs != lct) {
		return (lcs - lct);
	    }
	}
    }
    return 0;
}
#endif /* TCL_UTF_MAX > 3 */

int
Tcl_Utf16Ncasecmp(
Tcl_UniCharNcasecmp(
    const unsigned short *ucs,	/* Utf16 string to compare to uct. */
    const unsigned short *uct,	/* Utf16 string ucs is compared to. */
    unsigned long numChars)	/* Number of Utf16 characters to compare. */
{
    for ( ; numChars != 0; numChars--, ucs++, uct++) {
	if (*ucs != *uct) {
	    int lcs = Tcl_UniCharToLower(*ucs);
2122
2123
2124
2125
2126
2127
2128
2129

2130
2131
2132
2133
2134
2135
2136
2124
2125
2126
2127
2128
2129
2130

2131
2132
2133
2134
2135
2136
2137
2138







-
+







 *	None.
 *
 *----------------------------------------------------------------------
 */

#if TCL_UTF_MAX > 3
int
Tcl_UniCharCaseMatch(
Tcl_Utf32CaseMatch(
    const int *uniStr,	/* Unicode String. */
    const int *uniPattern,
				/* Pattern, which may contain special
				 * characters. */
    int nocase)			/* 0 for case sensitive, 1 for insensitive */
{
    int ch1 = 0, p;
2189
2190
2191
2192
2193
2194
2195
2196

2197
2198
2199
2200
2201
2202
2203
2191
2192
2193
2194
2195
2196
2197

2198
2199
2200
2201
2202
2203
2204
2205







-
+







			}
		    } else {
			while (*uniStr && (p != *uniStr)) {
			    uniStr++;
			}
		    }
		}
		if (Tcl_UniCharCaseMatch(uniStr, uniPattern, nocase)) {
		if (Tcl_Utf32CaseMatch(uniStr, uniPattern, nocase)) {
		    return 1;
		}
		if (*uniStr == 0) {
		    return 0;
		}
		uniStr++;
	    }
2290
2291
2292
2293
2294
2295
2296
2297

2298
2299
2300
2301
2302
2303
2304
2292
2293
2294
2295
2296
2297
2298

2299
2300
2301
2302
2303
2304
2305
2306







-
+







	uniStr++;
	uniPattern++;
    }
}
#endif /* TCL_UTF_MAX > 3 */

int
Tcl_Utf16CaseMatch(
Tcl_UniCharCaseMatch(
    const unsigned short *uniStr,	/* Unicode String. */
    const unsigned short *uniPattern,
				/* Pattern, which may contain special
				 * characters. */
    int nocase)			/* 0 for case sensitive, 1 for insensitive */
{
    unsigned short ch1 = 0, p;
2357
2358
2359
2360
2361
2362
2363
2364

2365
2366
2367
2368
2369
2370
2371
2359
2360
2361
2362
2363
2364
2365

2366
2367
2368
2369
2370
2371
2372
2373







-
+







			}
		    } else {
			while (*uniStr && (p != *uniStr)) {
			    uniStr++;
			}
		    }
		}
		if (Tcl_Utf16CaseMatch(uniStr, uniPattern, nocase)) {
		if (Tcl_UniCharCaseMatch(uniStr, uniPattern, nocase)) {
		    return 1;
		}
		if (*uniStr == 0) {
		    return 0;
		}
		uniStr++;
	    }