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
|
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
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
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
|
+
-
+
-
-
+
+
+
-
-
-
-
-
+
+
+
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
if (*ucs != *uct) {
return (*ucs - *uct);
}
}
return 0;
#endif /* WORDS_BIGENDIAN */
}
/*
*----------------------------------------------------------------------
*
* Tcl_UniCharNcasecmp --
* TclUTF16Ncmp --
*
* Compare at most numChars unichars of string ucs to string uct case
* insensitive. Both ucs and uct are assumed to be at least numChars
* Compare at most numChars characters from UTF-16 sequence units1
* against characters from UTF-16 sequence units2. Caller is expected
* to guarantee that each sequence contains at least numChars characters.
* unichars long.
*
* Results:
* Return <0 if ucs < uct, 0 if ucs == uct, or >0 if ucs > uct.
*
* Side effects:
* None.
* Return <0 if units1 < units2,
* 0 if units1 == units2,
* >0 if units1 > units,
* when considering up to numChar characters from each.
*
*----------------------------------------------------------------------
*/
#if 1
static int
UTF16ToUCS4(
const unsigned short int *units,
const Tcl_UniChar *units, /* Pointer into an array of UCS-2 units */
/* Pointer into an array of UCS-2 units */
size_t count, /* How many units are available to read. */
int *ucs4Ptr) /* Write the UCS-4 result here. */
{
if (count == 0) {
/* Is this reasonable? Better to panic? */
*ucs4Ptr = 0;
return 0;
}
if ((sizeof(Tcl_UniChar) > 2) || (count == 1)
|| ((units[0] & 0xF800) != 0xD800)
|| ((units[1] & 0xF800) != 0xDC00)) {
/* We do not see a surrogate pair. Return 1st unit. */
*ucs4Ptr = units[0];
return 1;
}
/* Surrogate pair. Generate extended code point */
*ucs4Ptr = (0x10000 + ((units[0] & 0x3FF) << 10)) | (units[1] & 0x3FF);
return 2;
}
int
TclUtf16Ncmp(
const unsigned short int *units1, /* 1st UTF-16 sequence to compare */
const unsigned short int *units2, /* 2nd UTF-16 sequence to compare */
size_t numUnits1, /* # code units in 1st sequence */
size_t numUnits2, /* # code units in 2nd sequence */
size_t numChars) /* max # characters to compare */
{
while ((numChars > 0) && (numUnits1 > 0) && (numUnits2 > 0)) {
int ch1, ch2;
int delta1 = UTF16ToUCS4(units1, numUnits1, &ch1);
int delta2 = UTF16ToUCS4(units2, numUnits2, &ch2);
if (ch1 != ch2) {
return (ch1 - ch2);
}
units1 += delta1;
numUnits1 -= delta1;
units2 += delta2;
numUnits2 -= delta2;
numChars--;
}
if (numChars == 0) {
return 0;
}
/* Ran out of at least one sequence before seeing numChars characters */
Tcl_Panic("TclUtf16Ncmp request to compare too many characters");
}
/*
*----------------------------------------------------------------------
*
* Tcl_UniCharNcasecmp --
*
* Compare at most numChars unichars of string ucs to string uct case
* insensitive. 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 0
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. */
{
unsigned long snum = numChars;
|