MCPcopy Create free account
hub / github.com/F-Stack/f-stack / u8_strcmp

Function u8_strcmp

freebsd/contrib/openzfs/module/unicode/u8_textprep.c:1837–1905  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

1835 * can be requested and checked against.
1836 */
1837int
1838u8_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 */

Callers 2

zfs_renameFunction · 0.85
zfs_dirent_lockFunction · 0.85

Calls 4

strcmpFunction · 0.85
strncmpFunction · 0.85
do_case_compareFunction · 0.85
do_norm_compareFunction · 0.85

Tested by

no test coverage detected