lib/util: Make string_replace from s3 common
authorAndrew Bartlett <abartlet@samba.org>
Fri, 8 Apr 2011 03:04:26 +0000 (13:04 +1000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 13 Apr 2011 04:47:07 +0000 (14:47 +1000)
The s4 implementation didn't do multibyte strings, so was only good
for '/' which is known to be safe in all multibyte charsets.

Andrew Bartlett

Signed-off-by: Andrew Tridgell <tridge@samba.org>
lib/util/util_str.c
lib/util/util_str_common.c
source3/lib/util_str.c

index 7fa531f0e44d92716f4731f2d06afd48f0fcadba..cf1b07ff0fa01052e4a6b811fb3d512b6e144cef 100644 (file)
@@ -249,13 +249,3 @@ _PUBLIC_ bool strequal(const char *s1, const char *s2)
        return strcasecmp(s1,s2) == 0;
 }
 
-/**
- String replace.
-**/
-_PUBLIC_ void string_replace(char *s, char oldc, char newc)
-{
-       while (*s) {
-               if (*s == oldc) *s = newc;
-               s++;
-       }
-}
index 9999ee440ec7448a330a624aae8eba1c2847e371..e6671be8ad45650f015e2db897258349ac52b6fb 100644 (file)
@@ -59,3 +59,46 @@ _PUBLIC_ size_t ucs2_align(const void *base_ptr, const void *p, int flags)
                return 0;
        return PTR_DIFF(p, base_ptr) & 1;
 }
+
+/**
+ String replace.
+ NOTE: oldc and newc must be 7 bit characters
+**/
+void string_replace( char *s, char oldc, char newc )
+{
+       char *p;
+
+       /* this is quite a common operation, so we want it to be
+          fast. We optimise for the ascii case, knowing that all our
+          supported multi-byte character sets are ascii-compatible
+          (ie. they match for the first 128 chars) */
+
+       for (p = s; *p; p++) {
+               if (*p & 0x80) /* mb string - slow path. */
+                       break;
+               if (*p == oldc) {
+                       *p = newc;
+               }
+       }
+
+       if (!*p)
+               return;
+
+       /* Slow (mb) path. */
+#ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
+       /* With compose characters we must restart from the beginning. JRA. */
+       p = s;
+#endif
+
+       while (*p) {
+               size_t c_size;
+               next_codepoint(p, &c_size);
+
+               if (c_size == 1) {
+                       if (*p == oldc) {
+                               *p = newc;
+                       }
+               }
+               p += c_size;
+       }
+}
index a710fcc35b88e32458f5242415431ddc4217b62f..13aa78cc913036307b03862cd3693fe03fcd0a7a 100644 (file)
@@ -233,49 +233,6 @@ bool strisnormal(const char *s, int case_default)
 }
 
 
-/**
- String replace.
- NOTE: oldc and newc must be 7 bit characters
-**/
-void string_replace( char *s, char oldc, char newc )
-{
-       char *p;
-
-       /* this is quite a common operation, so we want it to be
-          fast. We optimise for the ascii case, knowing that all our
-          supported multi-byte character sets are ascii-compatible
-          (ie. they match for the first 128 chars) */
-
-       for (p = s; *p; p++) {
-               if (*p & 0x80) /* mb string - slow path. */
-                       break;
-               if (*p == oldc) {
-                       *p = newc;
-               }
-       }
-
-       if (!*p)
-               return;
-
-       /* Slow (mb) path. */
-#ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
-       /* With compose characters we must restart from the beginning. JRA. */
-       p = s;
-#endif
-
-       while (*p) {
-               size_t c_size;
-               next_codepoint(p, &c_size);
-
-               if (c_size == 1) {
-                       if (*p == oldc) {
-                               *p = newc;
-                       }
-               }
-               p += c_size;
-       }
-}
-
 /**
  *  Skip past some strings in a buffer - old version - no checks.
  *  **/