Revision: 46840
          http://brlcad.svn.sourceforge.net/brlcad/?rev=46840&view=rev
Author:   brlcad
Date:     2011-09-21 18:47:16 +0000 (Wed, 21 Sep 2011)
Log Message:
-----------
change the signature of bu_vls_encode/bu_vls_decode to return pointers to the 
strings that were encoded/decoded.  this allows the functions to be chained 
together and embedded within printing statements without additional calls to 
bu_vls_addr().  tries to account for vls strings with existing content too.

Modified Paths:
--------------
    brlcad/trunk/include/bu.h
    brlcad/trunk/src/libbu/quote.c

Modified: brlcad/trunk/include/bu.h
===================================================================
--- brlcad/trunk/include/bu.h   2011-09-21 18:25:46 UTC (rev 46839)
+++ brlcad/trunk/include/bu.h   2011-09-21 18:47:16 UTC (rev 46840)
@@ -4892,7 +4892,8 @@
 
 /**
  * given an input string, wrap the string in double quotes if there is
- * a space.  escape any existing double quotes.
+ * a space and append it to the provided bu_vls.  escape any existing
+ * double quotes.
  *
  * TODO: consider a specifiable quote character and octal encoding
  * instead of double quote wrapping.  perhaps specifiable encode type:
@@ -4903,8 +4904,11 @@
  * the behavior of this routine is subject to change but should remain
  * a reversible operation when used in conjunction with
  * bu_vls_decode().
+ *
+ * returns a pointer to the encoded string (i.e., the substring held
+ * within the bu_vls)
  */
-BU_EXPORT extern void bu_vls_encode(struct bu_vls *vp, const char *str);
+BU_EXPORT extern const char *bu_vls_encode(struct bu_vls *vp, const char *str);
 
 
 /**
@@ -4913,8 +4917,11 @@
  *
  * the behavior of this routine is subject to change but should remain
  * the reverse operation of bu_vls_encode().
+ *
+ * returns a pointer to the decoded string (i.e., the substring held
+ * within the bu_vls)
  */
-BU_EXPORT extern void bu_vls_decode(struct bu_vls *vp, const char *str);
+BU_EXPORT extern const char *bu_vls_decode(struct bu_vls *vp, const char *str);
 
 
 /** @} */

Modified: brlcad/trunk/src/libbu/quote.c
===================================================================
--- brlcad/trunk/src/libbu/quote.c      2011-09-21 18:25:46 UTC (rev 46839)
+++ brlcad/trunk/src/libbu/quote.c      2011-09-21 18:47:16 UTC (rev 46840)
@@ -30,14 +30,19 @@
 static const char ESCAPE = '\\';
 
 
-void
+const char *
 bu_vls_encode(struct bu_vls *vp, const char *str)
 {
+    static const char *empty = "";
+    int skip = 0;
+
     if (UNLIKELY(!str))
-       return;
+       return empty;
 
     BU_CK_VLS(vp);
 
+    skip = bu_vls_strlen(vp);
+
     if (strchr(str, SPACE) == NULL) {
        /* no spaces, just watch for quotes */
        for (; *str != '\0'; str++) {
@@ -57,22 +62,29 @@
        }
        bu_vls_putc(vp, DQUOTE);
     }
+
+    return bu_vls_addr(vp) + skip;
 }
 
 
-void
+const char *
 bu_vls_decode(struct bu_vls *vp, const char *str)
 {
+    static const char *empty = "";
+
+    int skip = 0;
     int dquote = 0;
     int escape = 0;
 
     struct bu_vls quotebuf;
 
     if (UNLIKELY(!str))
-       return;
+       return empty;
 
     BU_CK_VLS(vp);
 
+    skip = bu_vls_strlen(vp);
+
     bu_vls_init(&quotebuf);
 
     for (; *str != '\0'; str++) {
@@ -124,6 +136,8 @@
     }
 
     bu_vls_free(&quotebuf);
+
+    return bu_vls_addr(vp) + skip;
 }
 
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to