Author: tridge
Date: 2006-03-21 11:37:11 +0000 (Tue, 21 Mar 2006)
New Revision: 14612

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=14612

Log:

added strncasecmp_m() and fixed strcasecmp_m() for invalid codepoints

Modified:
   branches/SAMBA_4_0/source/lib/util/util_str.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/util/util_str.c
===================================================================
--- branches/SAMBA_4_0/source/lib/util/util_str.c       2006-03-21 11:14:29 UTC 
(rev 14611)
+++ branches/SAMBA_4_0/source/lib/util/util_str.c       2006-03-21 11:37:11 UTC 
(rev 14612)
@@ -101,14 +101,53 @@
                if (c1 == INVALID_CODEPOINT ||
                    c2 == INVALID_CODEPOINT) {
                        /* what else can we do?? */
+                       return strcasecmp(s1, s2);
+               }
+
+               if (toupper_w(c1) != toupper_w(c2)) {
                        return c1 - c2;
                }
+       }
 
+       return *s1 - *s2;
+}
+
+/**
+ Case insensitive string compararison, length limited
+**/
+_PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n)
+{
+       codepoint_t c1=0, c2=0;
+       size_t size1, size2;
+
+       while (*s1 && *s2 && n) {
+               n--;
+
+               c1 = next_codepoint(s1, &size1);
+               c2 = next_codepoint(s2, &size2);
+
+               s1 += size1;
+               s2 += size2;
+
+               if (c1 == c2) {
+                       continue;
+               }
+
+               if (c1 == INVALID_CODEPOINT ||
+                   c2 == INVALID_CODEPOINT) {
+                       /* what else can we do?? */
+                       return strcasecmp(s1, s2);
+               }
+
                if (toupper_w(c1) != toupper_w(c2)) {
                        return c1 - c2;
                }
        }
 
+       if (n == 0) {
+               return 0;
+       }
+
        return *s1 - *s2;
 }
 

Reply via email to