* The u8_strcmp() function compares two UTF-8 strings quite similar to * the strcmp(). For the comparison, however, Unicode Normalization specific * equivalency and Unicode simple case conversion mappings based equivalency * can be requested and checked against. */
| 1835 | * can be requested and checked against. |
| 1836 | */ |
| 1837 | int |
| 1838 | u8_strcmp(const char *s1, const char *s2, size_t n, int flag, size_t uv, |
| 1839 | int *errnum) |
| 1840 | { |
| 1841 | int f; |
| 1842 | size_t n1; |
| 1843 | size_t n2; |
| 1844 | |
| 1845 | *errnum = 0; |
| 1846 | |
| 1847 | /* |
| 1848 | * Check on the requested Unicode version, case conversion, and |
| 1849 | * normalization flag values. |
| 1850 | */ |
| 1851 | |
| 1852 | if (uv > U8_UNICODE_LATEST) { |
| 1853 | *errnum = ERANGE; |
| 1854 | uv = U8_UNICODE_LATEST; |
| 1855 | } |
| 1856 | |
| 1857 | if (flag == 0) { |
| 1858 | flag = U8_STRCMP_CS; |
| 1859 | } else { |
| 1860 | f = flag & (U8_STRCMP_CS | U8_STRCMP_CI_UPPER | |
| 1861 | U8_STRCMP_CI_LOWER); |
| 1862 | if (f == 0) { |
| 1863 | flag |= U8_STRCMP_CS; |
| 1864 | } else if (f != U8_STRCMP_CS && f != U8_STRCMP_CI_UPPER && |
| 1865 | f != U8_STRCMP_CI_LOWER) { |
| 1866 | *errnum = EBADF; |
| 1867 | flag = U8_STRCMP_CS; |
| 1868 | } |
| 1869 | |
| 1870 | f = flag & (U8_CANON_DECOMP | U8_COMPAT_DECOMP | U8_CANON_COMP); |
| 1871 | if (f && f != U8_STRCMP_NFD && f != U8_STRCMP_NFC && |
| 1872 | f != U8_STRCMP_NFKD && f != U8_STRCMP_NFKC) { |
| 1873 | *errnum = EBADF; |
| 1874 | flag = U8_STRCMP_CS; |
| 1875 | } |
| 1876 | } |
| 1877 | |
| 1878 | if (flag == U8_STRCMP_CS) { |
| 1879 | return (n == 0 ? strcmp(s1, s2) : strncmp(s1, s2, n)); |
| 1880 | } |
| 1881 | |
| 1882 | n1 = strlen(s1); |
| 1883 | n2 = strlen(s2); |
| 1884 | if (n != 0) { |
| 1885 | if (n < n1) |
| 1886 | n1 = n; |
| 1887 | if (n < n2) |
| 1888 | n2 = n; |
| 1889 | } |
| 1890 | |
| 1891 | /* |
| 1892 | * Simple case conversion can be done much faster and so we do |
| 1893 | * them separately here. |
| 1894 | */ |
no test coverage detected