lib/util: Move next_token* functions to util_str.c
authorMartin Schwenke <martin@meltin.net>
Fri, 19 Sep 2014 03:30:26 +0000 (13:30 +1000)
committerVolker Lendecke <vl@samba.org>
Fri, 19 Sep 2014 16:11:11 +0000 (18:11 +0200)
This is part of an attempt to untangle charset from util.c.

Most of this was moved from util_str.c in commit
55903e6f9120f1ec58a8554813229975c3028a09.  next_token() was moved from
charset to util.c in commit 4be643d4ce33d5ce2bf9deacc3f6d0fde90cf626
so that it would be alongside next_token_talloc().

Now that util_str.c is in shared lib/util it is no longer necessary to
have these in util.c.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Volker Lendecke <vl@samba.org>
lib/util/util.c
lib/util/util_str.c

index ec70c342f37e5cbbcf3a60ec2c4f574afb46bc81..c421f18ca918f44991d7bde42c73e8b4259e6e49 100644 (file)
@@ -1043,152 +1043,6 @@ _PUBLIC_ size_t utf16_len_n(const void *src, size_t n)
        return len;
 }
 
-/**
- * @file
- * @brief String utilities.
- **/
-
-static bool next_token_internal_talloc(TALLOC_CTX *ctx,
-                               const char **ptr,
-                                char **pp_buff,
-                                const char *sep,
-                                bool ltrim)
-{
-       const char *s;
-       const char *saved_s;
-       char *pbuf;
-       bool quoted;
-       size_t len=1;
-
-       *pp_buff = NULL;
-       if (!ptr) {
-               return(false);
-       }
-
-       s = *ptr;
-
-       /* default to simple separators */
-       if (!sep) {
-               sep = " \t\n\r";
-       }
-
-       /* find the first non sep char, if left-trimming is requested */
-       if (ltrim) {
-               while (*s && strchr_m(sep,*s)) {
-                       s++;
-               }
-       }
-
-       /* nothing left? */
-       if (!*s) {
-               return false;
-       }
-
-       /* When restarting we need to go from here. */
-       saved_s = s;
-
-       /* Work out the length needed. */
-       for (quoted = false; *s &&
-                       (quoted || !strchr_m(sep,*s)); s++) {
-               if (*s == '\"') {
-                       quoted = !quoted;
-               } else {
-                       len++;
-               }
-       }
-
-       /* We started with len = 1 so we have space for the nul. */
-       *pp_buff = talloc_array(ctx, char, len);
-       if (!*pp_buff) {
-               return false;
-       }
-
-       /* copy over the token */
-       pbuf = *pp_buff;
-       s = saved_s;
-       for (quoted = false; *s &&
-                       (quoted || !strchr_m(sep,*s)); s++) {
-               if ( *s == '\"' ) {
-                       quoted = !quoted;
-               } else {
-                       *pbuf++ = *s;
-               }
-       }
-
-       *ptr = (*s) ? s+1 : s;
-       *pbuf = 0;
-
-       return true;
-}
-
-bool next_token_talloc(TALLOC_CTX *ctx,
-                       const char **ptr,
-                       char **pp_buff,
-                       const char *sep)
-{
-       return next_token_internal_talloc(ctx, ptr, pp_buff, sep, true);
-}
-
-/*
- * Get the next token from a string, return false if none found.  Handles
- * double-quotes.  This version does not trim leading separator characters
- * before looking for a token.
- */
-
-bool next_token_no_ltrim_talloc(TALLOC_CTX *ctx,
-                       const char **ptr,
-                       char **pp_buff,
-                       const char *sep)
-{
-       return next_token_internal_talloc(ctx, ptr, pp_buff, sep, false);
-}
-
-/**
- * Get the next token from a string, return False if none found.
- * Handles double-quotes.
- *
- * Based on a routine by GJC@VILLAGE.COM.
- * Extensively modified by Andrew.Tridgell@anu.edu.au
- **/
-_PUBLIC_ bool next_token(const char **ptr,char *buff, const char *sep, size_t bufsize)
-{
-       const char *s;
-       bool quoted;
-       size_t len=1;
-
-       if (!ptr)
-               return false;
-
-       s = *ptr;
-
-       /* default to simple separators */
-       if (!sep)
-               sep = " \t\n\r";
-
-       /* find the first non sep char */
-       while (*s && strchr_m(sep,*s))
-               s++;
-
-       /* nothing left? */
-       if (!*s)
-               return false;
-
-       /* copy over the token */
-       for (quoted = false; len < bufsize && *s && (quoted || !strchr_m(sep,*s)); s++) {
-               if (*s == '\"') {
-                       quoted = !quoted;
-               } else {
-                       len++;
-                       *buff++ = *s;
-               }
-       }
-
-       *ptr = (*s) ? s+1 : s;
-       *buff = 0;
-
-       return true;
-}
-
 struct anonymous_shared_header {
        union {
                size_t length;
index 9379304cfb8935b3e27436c16bb30d6c5db09d5e..58c9f7860d822a9514a9db621d557f7e4b55aff2 100644 (file)
@@ -133,3 +133,148 @@ _PUBLIC_ bool strequal(const char *s1, const char *s2)
        return strcasecmp_m(s1,s2) == 0;
 }
 
+/**
+ * @file
+ * @brief String utilities.
+ **/
+
+static bool next_token_internal_talloc(TALLOC_CTX *ctx,
+                               const char **ptr,
+                                char **pp_buff,
+                                const char *sep,
+                                bool ltrim)
+{
+       const char *s;
+       const char *saved_s;
+       char *pbuf;
+       bool quoted;
+       size_t len=1;
+
+       *pp_buff = NULL;
+       if (!ptr) {
+               return(false);
+       }
+
+       s = *ptr;
+
+       /* default to simple separators */
+       if (!sep) {
+               sep = " \t\n\r";
+       }
+
+       /* find the first non sep char, if left-trimming is requested */
+       if (ltrim) {
+               while (*s && strchr_m(sep,*s)) {
+                       s++;
+               }
+       }
+
+       /* nothing left? */
+       if (!*s) {
+               return false;
+       }
+
+       /* When restarting we need to go from here. */
+       saved_s = s;
+
+       /* Work out the length needed. */
+       for (quoted = false; *s &&
+                       (quoted || !strchr_m(sep,*s)); s++) {
+               if (*s == '\"') {
+                       quoted = !quoted;
+               } else {
+                       len++;
+               }
+       }
+
+       /* We started with len = 1 so we have space for the nul. */
+       *pp_buff = talloc_array(ctx, char, len);
+       if (!*pp_buff) {
+               return false;
+       }
+
+       /* copy over the token */
+       pbuf = *pp_buff;
+       s = saved_s;
+       for (quoted = false; *s &&
+                       (quoted || !strchr_m(sep,*s)); s++) {
+               if ( *s == '\"' ) {
+                       quoted = !quoted;
+               } else {
+                       *pbuf++ = *s;
+               }
+       }
+
+       *ptr = (*s) ? s+1 : s;
+       *pbuf = 0;
+
+       return true;
+}
+
+bool next_token_talloc(TALLOC_CTX *ctx,
+                       const char **ptr,
+                       char **pp_buff,
+                       const char *sep)
+{
+       return next_token_internal_talloc(ctx, ptr, pp_buff, sep, true);
+}
+
+/*
+ * Get the next token from a string, return false if none found.  Handles
+ * double-quotes.  This version does not trim leading separator characters
+ * before looking for a token.
+ */
+
+bool next_token_no_ltrim_talloc(TALLOC_CTX *ctx,
+                       const char **ptr,
+                       char **pp_buff,
+                       const char *sep)
+{
+       return next_token_internal_talloc(ctx, ptr, pp_buff, sep, false);
+}
+
+/**
+ * Get the next token from a string, return False if none found.
+ * Handles double-quotes.
+ *
+ * Based on a routine by GJC@VILLAGE.COM.
+ * Extensively modified by Andrew.Tridgell@anu.edu.au
+ **/
+_PUBLIC_ bool next_token(const char **ptr,char *buff, const char *sep, size_t bufsize)
+{
+       const char *s;
+       bool quoted;
+       size_t len=1;
+
+       if (!ptr)
+               return false;
+
+       s = *ptr;
+
+       /* default to simple separators */
+       if (!sep)
+               sep = " \t\n\r";
+
+       /* find the first non sep char */
+       while (*s && strchr_m(sep,*s))
+               s++;
+
+       /* nothing left? */
+       if (!*s)
+               return false;
+
+       /* copy over the token */
+       for (quoted = false; len < bufsize && *s && (quoted || !strchr_m(sep,*s)); s++) {
+               if (*s == '\"') {
+                       quoted = !quoted;
+               } else {
+                       len++;
+                       *buff++ = *s;
+               }
+       }
+
+       *ptr = (*s) ? s+1 : s;
+       *buff = 0;
+
+       return true;
+}