You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2011/06/24 04:25:10 UTC

[lucy-commits] svn commit: r1139139 - in /incubator/lucy/trunk/clownfish/src: CFCUtil.c CFCUtil.h

Author: marvin
Date: Fri Jun 24 02:25:10 2011
New Revision: 1139139

URL: http://svn.apache.org/viewvc?rev=1139139&view=rev
Log:
Add CFCUtil_cat_strings().

Add utility function which concatenates a NULL-terminated list of strings,
reallocating as necessary.

Modified:
    incubator/lucy/trunk/clownfish/src/CFCUtil.c
    incubator/lucy/trunk/clownfish/src/CFCUtil.h

Modified: incubator/lucy/trunk/clownfish/src/CFCUtil.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCUtil.c?rev=1139139&r1=1139138&r2=1139139&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCUtil.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCUtil.c Fri Jun 24 02:25:10 2011
@@ -52,6 +52,22 @@ CFCUtil_strndup(const char *string, size
     return copy;
 }
 
+char*
+CFCUtil_cat_strings(char *string, ...) {
+    va_list args;
+    char *appended;
+    CFCUTIL_NULL_CHECK(string);
+    size_t size = strlen(string) + 1;
+    va_start(args, string);
+    while (NULL != (appended = va_arg(args, char*))) {
+        size += strlen(appended);
+        string = (char*)REALLOCATE(string, size);
+        strcat(string, appended);
+    }
+    va_end(args);
+    return string;
+}
+
 void
 CFCUtil_trim_whitespace(char *text) {
     if (!text) {

Modified: incubator/lucy/trunk/clownfish/src/CFCUtil.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCUtil.h?rev=1139139&r1=1139138&r2=1139139&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCUtil.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCUtil.h Fri Jun 24 02:25:10 2011
@@ -44,6 +44,12 @@ CFCUtil_strdup(const char *string);
 char*
 CFCUtil_strndup(const char *string, size_t len);
 
+/** Concatenate a NULL-terminated list of strings onto the first, reallocating
+ * with each argument. 
+ */
+char*
+CFCUtil_cat_strings(char *string, ...);
+
 /** Trim whitespace from the beginning and the end of a string.
  */
 void