]> git.ozlabs.org Git - ccan/blobdiff - ccan/tal/str/str.h
tal/str: use tal_ prefix.
[ccan] / ccan / tal / str / str.h
index 30086fde3f555a68b258350e931a559ad2eb96c8..f30911e2df6f246cb39897fe11f00af0c61d0918 100644 (file)
@@ -12,19 +12,22 @@ enum strsplit {
 };
 
 /**
- * strsplit - Split string into an array of substrings
- * @ctx: the parent to tal from (often NULL)
- * @string: the string to split
- * @delims: delimiters where lines should be split.
+ * tal_strsplit - Split string into an array of substrings
+ * @ctx: the context to tal from (often NULL).
+ * @string: the string to split (can be take()).
+ * @delims: delimiters where lines should be split (can be take()).
  * @flags: whether to include empty substrings.
  *
- * This function splits a single string into multiple strings.  The
- * original string is untouched: an array is allocated (using tal)
- * pointing to copies of each substring.  Multiple delimiters result
- * in empty substrings.  By definition, no delimiters will appear in
- * the substrings.
+ * This function splits a single string into multiple strings.
  *
- * The final char * in the array will be NULL.
+ * If @string is take(), the returned array will point into the
+ * mangled @string.
+ *
+ * Multiple delimiters result in empty substrings.  By definition, no
+ * delimiters will appear in the substrings.
+ *
+ * The final char * in the array will be NULL, and tal_count() will
+ * return the number of elements plus 1 (for that NULL).
  *
  * Example:
  *     #include <ccan/tal/str/str.h>
@@ -35,7 +38,7 @@ enum strsplit {
  *             unsigned int i, long_lines = 0;
  *
  *             // Can only fail on out-of-memory.
- *             lines = strsplit(NULL, string, "\n", STR_NO_EMPTY);
+ *             lines = tal_strsplit(NULL, string, "\n", STR_NO_EMPTY);
  *             for (i = 0; lines[i] != NULL; i++)
  *                     if (strlen(lines[i]) > 80)
  *                             long_lines++;
@@ -43,8 +46,8 @@ enum strsplit {
  *             return long_lines;
  *     }
  */
-char **strsplit(const void *ctx, const char *string, const char *delims,
-               enum strsplit flags);
+char **tal_strsplit(const tal_t *ctx,
+                   const char *string, const char *delims, enum strsplit flag);
 
 enum strjoin {
        STR_TRAIL,
@@ -52,10 +55,10 @@ enum strjoin {
 };
 
 /**
- * strjoin - Join an array of substrings into one long string
- * @ctx: the context to tal from (often NULL)
- * @strings: the NULL-terminated array of strings to join
- * @delim: the delimiter to insert between the strings
+ * tal_strjoin - Join an array of substrings into one long string
+ * @ctx: the context to tal from (often NULL).
+ * @strings: the NULL-terminated array of strings to join (can be take())
+ * @delim: the delimiter to insert between the strings (can be take())
  * @flags: whether to add a delimieter to the end
  *
  * This function joins an array of strings into a single string.  The
@@ -68,20 +71,20 @@ enum strjoin {
  *     {
  *             char **lines, *ret;
  *
- *             lines = strsplit(NULL, string, "\n", STR_EMPTY_OK);
- *             ret = strjoin(NULL, lines, "-- EOL\n", STR_TRAIL);
+ *             lines = tal_strsplit(NULL, string, "\n", STR_EMPTY_OK);
+ *             ret = tal_strjoin(NULL, lines, "-- EOL\n", STR_TRAIL);
  *             tal_free(lines);
  *             return ret;
  *     }
  */
-char *strjoin(const void *ctx, char *strings[], const char *delim,
-             enum strjoin flags);
+char *tal_strjoin(const void *ctx, char *strings[], const char *delim,
+                 enum strjoin flags);
 
 /**
- * strreg - match and extract from a string via (extended) regular expressions.
+ * tal_strreg - match/extract from a string via (extended) regular expressions.
  * @ctx: the context to tal from (often NULL)
- * @string: the string to try to match.
- * @regex: the regular expression to match.
+ * @string: the string to try to match (can be take())
+ * @regex: the regular expression to match (can be take())
  * ...: pointers to strings to allocate for subexpressions.
  *
  * Returns true if we matched, in which case any parenthesized
@@ -106,14 +109,15 @@ char *strjoin(const void *ctx, char *strings[], const char *delim,
  *             char *person, *input;
  *
  *             // Join args and trim trailing space.
- *             input = strjoin(NULL, argv+1, " ", STR_NO_TRAIL);
- *             if (strreg(NULL, input, "[Mm]y (first )?name is ([A-Za-z ]+)",
- *                        NULL, &person))
+ *             input = tal_strjoin(NULL, argv+1, " ", STR_NO_TRAIL);
+ *             if (tal_strreg(NULL, input,
+ *                            "[Mm]y (first )?name is ([A-Za-z ]+)",
+ *                            NULL, &person))
  *                     printf("Hello %s!\n", person);
  *             else
  *                     printf("Hello there!\n");
  *             return 0;
  *     }
  */
-bool strreg(const void *ctx, const char *string, const char *regex, ...);
+bool tal_strreg(const void *ctx, const char *string, const char *regex, ...);
 #endif /* CCAN_STR_TAL_H */