X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libatalk%2Funicode%2Futil_unistr.c;h=5108a4c8e86f0ef8d73d97f7300f025eeae84b92;hb=22a32e7449133013789f3fc7ff6b32772b0c76cc;hp=3c9a194b5dd6169813d68c40e9b94577fe1a13d2;hpb=097ca98149a60e9b631cfe617064281eab68a450;p=netatalk.git diff --git a/libatalk/unicode/util_unistr.c b/libatalk/unicode/util_unistr.c index 3c9a194b..5108a4c8 100644 --- a/libatalk/unicode/util_unistr.c +++ b/libatalk/unicode/util_unistr.c @@ -22,8 +22,9 @@ #include #include +#include + #include "precompose.h" -#include "byteorder.h" /******************************************************************* Convert a string to lower case. @@ -179,8 +180,7 @@ wide & sp strcasechr() ucs2_t *strcasechr_w(const ucs2_t *s, ucs2_t c) { while (*s != 0) { -/* LOG(log_debug, logtype_default, "Comparing %X to %X (%X - %X)", c, *s, toupper_w(c), toupper_w(*s));*/ - if (toupper_w(c) == toupper_w(*s)) return (ucs2_t *)s; + if (tolower_w(c) == tolower_w(*s)) return (ucs2_t *)s; s++; } if (c == *s) return (ucs2_t *)s; @@ -192,7 +192,7 @@ ucs2_t *strcasechr_sp(const ucs2_t *s, uint32_t c_sp) { if (*s == 0) return NULL; while (s[1] != 0) { - if (toupper_sp(c_sp) == toupper_sp((uint32_t)*s << 16 | (uint32_t)s[1])) return (ucs2_t *)s; + if (tolower_sp(c_sp) == tolower_sp((uint32_t)*s << 16 | (uint32_t)s[1])) return (ucs2_t *)s; s++; } @@ -249,7 +249,7 @@ ucs2_t *strstr_w(const ucs2_t *s, const ucs2_t *ins) /******************************************************************* wide strcasestr() ********************************************************************/ -/* */ +/* surrogate pair support */ ucs2_t *strcasestr_w(const ucs2_t *s, const ucs2_t *ins) { @@ -260,9 +260,22 @@ ucs2_t *strcasestr_w(const ucs2_t *s, const ucs2_t *ins) slen = strlen_w(s); inslen = strlen_w(ins); r = (ucs2_t *)s; - while ((r = strcasechr_w(r, *ins))) { - if (strncasecmp_w(r, ins, inslen) == 0) return r; - r++; + + if ((0xD800 <= *ins) && (*ins < 0xDC00)) { + if ((0xDC00 <= ins[1]) && (ins[1] < 0xE000)) { + uint32_t ins_sp = (uint32_t)*ins << 16 | (uint32_t)ins[1]; + while ((r = strcasechr_sp(r, ins_sp))) { + if (strncasecmp_w(r, ins, inslen) == 0) return r; + r++; + } + } else { + return NULL; /* illegal sequence */ + } + } else { + while ((r = strcasechr_w(r, *ins))) { + if (strncasecmp_w(r, ins, inslen) == 0) return r; + r++; + } } return NULL; } @@ -279,12 +292,12 @@ int strcasecmp_w(const ucs2_t *a, const ucs2_t *b) while (*a && *b) { if ((0xD800 <= *a) && (*a < 0xDC00)) { - if (ret = tolower_sp((uint32_t)*a << 16 | (uint32_t)a[1]) - tolower_sp((uint32_t)*b << 16 | (uint32_t)b[1])) return ret; + if ((ret = tolower_sp((uint32_t)*a << 16 | (uint32_t)a[1]) - tolower_sp((uint32_t)*b << 16 | (uint32_t)b[1]))) return ret; a++; b++; if (!(*a && *b)) return (tolower_w(*a) - tolower_w(*b)); /* avoid buffer over run */ } else { - if (ret = tolower_w(*a) - tolower_w(*b)) return ret; + if ((ret = tolower_w(*a) - tolower_w(*b))) return ret; } a++; b++; @@ -305,13 +318,13 @@ int strncasecmp_w(const ucs2_t *a, const ucs2_t *b, size_t len) while ((n < len) && *a && *b) { if ((0xD800 <= *a) && (*a < 0xDC00)) { - if (ret = tolower_sp((uint32_t)*a << 16 | (uint32_t)a[1]) - tolower_sp((uint32_t)*b << 16 | (uint32_t)b[1])) return ret; + if ((ret = tolower_sp((uint32_t)*a << 16 | (uint32_t)a[1]) - tolower_sp((uint32_t)*b << 16 | (uint32_t)b[1]))) return ret; a++; b++; n++; if (!((n < len) && *a && *b)) return (tolower_w(*a) - tolower_w(*b)); } else { - if (ret = tolower_w(*a) - tolower_w(*b)) return ret; + if ((ret = tolower_w(*a) - tolower_w(*b))) return ret; } a++; b++; @@ -358,6 +371,8 @@ ucs2_t *strdup_w(const ucs2_t *src) /******************************************************************* copy a string with max len ********************************************************************/ +/* This function is not used. */ +/* NOTE: not check isolation of surrogate pair */ ucs2_t *strncpy_w(ucs2_t *dest, const ucs2_t *src, const size_t max) { @@ -377,7 +392,9 @@ ucs2_t *strncpy_w(ucs2_t *dest, const ucs2_t *src, const size_t max) /******************************************************************* append a string of len bytes and add a terminator ********************************************************************/ +/* These functions are not used. */ +/* NOTE: not check isolation of surrogate pair */ ucs2_t *strncat_w(ucs2_t *dest, const ucs2_t *src, const size_t max) { size_t start; @@ -394,7 +411,7 @@ ucs2_t *strncat_w(ucs2_t *dest, const ucs2_t *src, const size_t max) return dest; } - +/* no problem of surrogate pair */ ucs2_t *strcat_w(ucs2_t *dest, const ucs2_t *src) { size_t start; @@ -591,7 +608,7 @@ size_t precompose_w (ucs2_t *name, size_t inplen, ucs2_t *comp, size_t *outlen) base_sp = ((uint32_t)base << 16) | (uint32_t)comb; do { comb_sp = ((uint32_t)in[1] << 16) | (uint32_t)in[2]; - if (result_sp = do_precomposition_sp(base_sp, comb_sp)) { + if ((result_sp = do_precomposition_sp(base_sp, comb_sp))) { base_sp = result_sp; i += 4; in +=2; @@ -625,7 +642,7 @@ size_t precompose_w (ucs2_t *name, size_t inplen, ucs2_t *comp, size_t *outlen) } /* Binary Search for BMP */ - else if (result = do_precomposition(base, comb)) { + else if ((result = do_precomposition(base, comb))) { base = result; }