You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2013/09/02 21:16:32 UTC

[lucy-commits] [01/15] git commit: refs/heads/cfish-string-prep1 - Convert Search::Compiler to CharBuf

Updated Branches:
  refs/heads/cfish-string-prep1 976a687ff -> 56fb0e1dd


Convert Search::Compiler to CharBuf


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/04e9f412
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/04e9f412
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/04e9f412

Branch: refs/heads/cfish-string-prep1
Commit: 04e9f412c61b29f8471dab48cfff43695ad16ef2
Parents: 976a687
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Sep 2 19:32:11 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Sep 2 19:32:11 2013 +0200

----------------------------------------------------------------------
 core/Lucy/Search/Compiler.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/04e9f412/core/Lucy/Search/Compiler.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/Compiler.c b/core/Lucy/Search/Compiler.c
index 1b82cb7..4ffa29d 100644
--- a/core/Lucy/Search/Compiler.c
+++ b/core/Lucy/Search/Compiler.c
@@ -18,6 +18,8 @@
 #include "Lucy/Util/ToolSet.h"
 
 #include "Lucy/Search/Compiler.h"
+
+#include "Clownfish/CharBuf.h"
 #include "Lucy/Index/SegReader.h"
 #include "Lucy/Index/DocVector.h"
 #include "Lucy/Index/Similarity.h"
@@ -107,9 +109,11 @@ String*
 Compiler_To_String_IMP(Compiler *self) {
     CompilerIVARS *const ivars = Compiler_IVARS(self);
     String *stringified_query = Query_To_String(ivars->parent);
-    String *string = Str_new_from_trusted_utf8("compiler(", 9);
-    Str_Cat(string, stringified_query);
-    Str_Cat_Trusted_Str(string, ")", 1);
+    CharBuf *buf = CB_new_from_trusted_utf8("compiler(", 9);
+    CB_Cat(buf, stringified_query);
+    CB_Cat_Trusted_UTF8(buf, ")", 1);
+    String *string = CB_Yield_String(buf);
+    DECREF(buf);
     DECREF(stringified_query);
     return string;
 }


[lucy-commits] [10/15] git commit: refs/heads/cfish-string-prep1 - Convert TestSortSpec to CharBuf

Posted by nw...@apache.org.
Convert TestSortSpec to CharBuf


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/0f0ec865
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/0f0ec865
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/0f0ec865

Branch: refs/heads/cfish-string-prep1
Commit: 0f0ec865e25d0ff553c616aa529456759ea262e6
Parents: f028d09
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Sep 2 20:17:31 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Sep 2 21:12:30 2013 +0200

----------------------------------------------------------------------
 core/Lucy/Test/Search/TestSortSpec.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/0f0ec865/core/Lucy/Test/Search/TestSortSpec.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Search/TestSortSpec.c b/core/Lucy/Test/Search/TestSortSpec.c
index 3961a5e..ead2c3f 100644
--- a/core/Lucy/Test/Search/TestSortSpec.c
+++ b/core/Lucy/Test/Search/TestSortSpec.c
@@ -28,6 +28,7 @@
 #include "Lucy/Test/TestUtils.h"
 #include "Lucy/Search/SortSpec.h"
 
+#include "Clownfish/CharBuf.h"
 #include "Lucy/Analysis/StandardTokenizer.h"
 #include "Lucy/Document/Doc.h"
 #include "Lucy/Document/HitDoc.h"
@@ -269,11 +270,13 @@ typedef Obj* (*random_generator_t)();
 static Obj*
 S_random_string() {
     size_t length = 1 + rand() % 10;
-    String *string = Str_new(length);
+    CharBuf *buf = CB_new(length);
     while (length--) {
         uint32_t code_point = 'a' + rand() % ('z' - 'a' + 1);
-        Str_Cat_Char(string, code_point);
+        CB_Cat_Char(buf, code_point);
     }
+    String *string = CB_Yield_String(buf);
+    DECREF(buf);
     return (Obj*)string;
 }
 


[lucy-commits] [06/15] git commit: refs/heads/cfish-string-prep1 - Convert Util::Json to CharBuf

Posted by nw...@apache.org.
Convert Util::Json to CharBuf


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/5c9d7a78
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/5c9d7a78
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/5c9d7a78

Branch: refs/heads/cfish-string-prep1
Commit: 5c9d7a78375452a1db1f3e1dd43921112e2f08aa
Parents: 4be6f87
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Sep 2 19:57:54 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Sep 2 21:12:29 2013 +0200

----------------------------------------------------------------------
 core/Lucy/Util/Json.c | 118 ++++++++++++++++++++++++---------------------
 1 file changed, 62 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/5c9d7a78/core/Lucy/Util/Json.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/Json.c b/core/Lucy/Util/Json.c
index 674ff32..33295a1 100644
--- a/core/Lucy/Util/Json.c
+++ b/core/Lucy/Util/Json.c
@@ -20,6 +20,8 @@
 #include "Lucy/Util/ToolSet.h"
 
 #include "Lucy/Util/Json.h"
+
+#include "Clownfish/CharBuf.h"
 #include "Lucy/Store/Folder.h"
 #include "Lucy/Store/InStream.h"
 #include "Lucy/Store/OutStream.h"
@@ -40,7 +42,7 @@ LucyParseJsonTrace(FILE *trace, char *line_prefix);
 // Encode JSON for supplied "dump".  On failure, sets Err_error and returns
 // false.
 static bool
-S_to_json(Obj *dump, String *json, int32_t depth);
+S_to_json(Obj *dump, CharBuf *buf, int32_t depth);
 
 // Parse JSON from raw UTF-8 in memory.
 static Obj*
@@ -79,11 +81,11 @@ static const size_t INDENTATION_LEN = sizeof(indentation) - 1;
 
 // Append indentation spaces x depth.
 static void
-S_cat_whitespace(String *json, int32_t depth);
+S_cat_whitespace(CharBuf *buf, int32_t depth);
 
 // Set Err_error, appending escaped JSON in the vicinity of the error.
 static void
-S_set_error(String *mess, char *json, char *limit, int line,
+S_set_error(CharBuf *buf, char *json, char *limit, int line,
             const char *func);
 #define SET_ERROR(_mess, _json, _end) \
     S_set_error(_mess, _json, _end, __LINE__, CFISH_ERR_FUNC_MACRO)
@@ -150,17 +152,18 @@ Json_to_json(Obj *dump) {
     }
 
     // Encode.
-    String *json = Str_new(31);
-    if (!S_to_json(dump, json, 0)) {
-        DECREF(json);
+    CharBuf *buf = CB_new(31);
+    String *json = NULL;
+    if (!S_to_json(dump, buf, 0)) {
         ERR_ADD_FRAME(Err_get_error());
-        json = NULL;
     }
     else {
         // Append newline.
-        Str_Cat_Trusted_Str(json, "\n", 1);
+        CB_Cat_Trusted_UTF8(buf, "\n", 1);
+        json = CB_Yield_String(buf);
     }
 
+    DECREF(buf);
     return json;
 }
 
@@ -172,9 +175,9 @@ Json_set_tolerant(bool tolerance) {
 static const int32_t MAX_DEPTH = 200;
 
 static void
-S_append_json_string(Obj *dump, String *json) {
+S_append_json_string(Obj *dump, CharBuf *buf) {
     // Append opening quote.
-    Str_Cat_Trusted_Str(json, "\"", 1);
+    CB_Cat_Trusted_UTF8(buf, "\"", 1);
 
     // Process string data.
     StackString *iterator = SSTR_WRAP((String*)dump);
@@ -184,7 +187,7 @@ S_append_json_string(Obj *dump, String *json) {
             // There is no need to escape any high characters, including those
             // above the BMP, as we assume that the destination channel can
             // handle arbitrary UTF-8 data.
-            Str_Cat_Char(json, code_point);
+            CB_Cat_Char(buf, code_point);
         }
         else {
             char buffer[7];
@@ -238,23 +241,23 @@ S_append_json_string(Obj *dump, String *json) {
                     buffer[0] = (char)code_point;
                     len = 1;
             }
-            Str_Cat_Trusted_Str(json, buffer, len);
+            CB_Cat_Trusted_UTF8(buf, buffer, len);
         }
     }
 
     // Append closing quote.
-    Str_Cat_Trusted_Str(json, "\"", 1);
+    CB_Cat_Trusted_UTF8(buf, "\"", 1);
 }
 
 static void
-S_cat_whitespace(String *json, int32_t depth) {
+S_cat_whitespace(CharBuf *buf, int32_t depth) {
     while (depth--) {
-        Str_Cat_Trusted_Str(json, indentation, INDENTATION_LEN);
+        CB_Cat_Trusted_UTF8(buf, indentation, INDENTATION_LEN);
     }
 }
 
 static bool
-S_to_json(Obj *dump, String *json, int32_t depth) {
+S_to_json(Obj *dump, CharBuf *buf, int32_t depth) {
     // Guard against infinite recursion in self-referencing data structures.
     if (depth > MAX_DEPTH) {
         String *mess = MAKE_MESS("Exceeded max depth of %i32", MAX_DEPTH);
@@ -263,58 +266,58 @@ S_to_json(Obj *dump, String *json, int32_t depth) {
     }
 
     if (!dump) {
-        Str_Cat_Trusted_Str(json, "null", 4);
+        CB_Cat_Trusted_UTF8(buf, "null", 4);
     }
     else if (dump == (Obj*)CFISH_TRUE) {
-        Str_Cat_Trusted_Str(json, "true", 4);
+        CB_Cat_Trusted_UTF8(buf, "true", 4);
     }
     else if (dump == (Obj*)CFISH_FALSE) {
-        Str_Cat_Trusted_Str(json, "false", 5);
+        CB_Cat_Trusted_UTF8(buf, "false", 5);
     }
     else if (Obj_Is_A(dump, STRING)) {
-        S_append_json_string(dump, json);
+        S_append_json_string(dump, buf);
     }
     else if (Obj_Is_A(dump, INTNUM)) {
-        Str_catf(json, "%i64", Obj_To_I64(dump));
+        CB_catf(buf, "%i64", Obj_To_I64(dump));
     }
     else if (Obj_Is_A(dump, FLOATNUM)) {
-        Str_catf(json, "%f64", Obj_To_F64(dump));
+        CB_catf(buf, "%f64", Obj_To_F64(dump));
     }
     else if (Obj_Is_A(dump, VARRAY)) {
         VArray *array = (VArray*)dump;
         size_t size = VA_Get_Size(array);
         if (size == 0) {
             // Put empty array on single line.
-            Str_Cat_Trusted_Str(json, "[]", 2);
+            CB_Cat_Trusted_UTF8(buf, "[]", 2);
             return true;
         }
         else if (size == 1) {
             Obj *elem = VA_Fetch(array, 0);
             if (!(Obj_Is_A(elem, HASH) || Obj_Is_A(elem, VARRAY))) {
                 // Put array containing single scalar element on one line.
-                Str_Cat_Trusted_Str(json, "[", 1);
-                if (!S_to_json(elem, json, depth + 1)) {
+                CB_Cat_Trusted_UTF8(buf, "[", 1);
+                if (!S_to_json(elem, buf, depth + 1)) {
                     return false;
                 }
-                Str_Cat_Trusted_Str(json, "]", 1);
+                CB_Cat_Trusted_UTF8(buf, "]", 1);
                 return true;
             }
         }
         // Fall back to spreading elements across multiple lines.
-        Str_Cat_Trusted_Str(json, "[", 1);
+        CB_Cat_Trusted_UTF8(buf, "[", 1);
         for (size_t i = 0; i < size; i++) {
-            Str_Cat_Trusted_Str(json, "\n", 1);
-            S_cat_whitespace(json, depth + 1);
-            if (!S_to_json(VA_Fetch(array, i), json, depth + 1)) {
+            CB_Cat_Trusted_UTF8(buf, "\n", 1);
+            S_cat_whitespace(buf, depth + 1);
+            if (!S_to_json(VA_Fetch(array, i), buf, depth + 1)) {
                 return false;
             }
             if (i + 1 < size) {
-                Str_Cat_Trusted_Str(json, ",", 1);
+                CB_Cat_Trusted_UTF8(buf, ",", 1);
             }
         }
-        Str_Cat_Trusted_Str(json, "\n", 1);
-        S_cat_whitespace(json, depth);
-        Str_Cat_Trusted_Str(json, "]", 1);
+        CB_Cat_Trusted_UTF8(buf, "\n", 1);
+        S_cat_whitespace(buf, depth);
+        CB_Cat_Trusted_UTF8(buf, "]", 1);
     }
     else if (Obj_Is_A(dump, HASH)) {
         Hash *hash = (Hash*)dump;
@@ -322,7 +325,7 @@ S_to_json(Obj *dump, String *json, int32_t depth) {
 
         // Put empty hash on single line.
         if (size == 0) {
-            Str_Cat_Trusted_Str(json, "{}", 2);
+            CB_Cat_Trusted_UTF8(buf, "{}", 2);
             return true;
         }
 
@@ -341,24 +344,24 @@ S_to_json(Obj *dump, String *json, int32_t depth) {
         VA_Sort(keys, NULL, NULL);
 
         // Spread pairs across multiple lines.
-        Str_Cat_Trusted_Str(json, "{", 1);
+        CB_Cat_Trusted_UTF8(buf, "{", 1);
         for (size_t i = 0; i < size; i++) {
             Obj *key = VA_Fetch(keys, i);
-            Str_Cat_Trusted_Str(json, "\n", 1);
-            S_cat_whitespace(json, depth + 1);
-            S_append_json_string(key, json);
-            Str_Cat_Trusted_Str(json, ": ", 2);
-            if (!S_to_json(Hash_Fetch(hash, key), json, depth + 1)) {
+            CB_Cat_Trusted_UTF8(buf, "\n", 1);
+            S_cat_whitespace(buf, depth + 1);
+            S_append_json_string(key, buf);
+            CB_Cat_Trusted_UTF8(buf, ": ", 2);
+            if (!S_to_json(Hash_Fetch(hash, key), buf, depth + 1)) {
                 DECREF(keys);
                 return false;
             }
             if (i + 1 < size) {
-                Str_Cat_Trusted_Str(json, ",", 1);
+                CB_Cat_Trusted_UTF8(buf, ",", 1);
             }
         }
-        Str_Cat_Trusted_Str(json, "\n", 1);
-        S_cat_whitespace(json, depth);
-        Str_Cat_Trusted_Str(json, "}", 1);
+        CB_Cat_Trusted_UTF8(buf, "\n", 1);
+        S_cat_whitespace(buf, depth);
+        CB_Cat_Trusted_UTF8(buf, "}", 1);
 
         DECREF(keys);
     }
@@ -471,7 +474,7 @@ S_do_parse_json(void *json_parser, char *json, size_t len) {
         }
         LucyParseJson(json_parser, token_type, value, &state);
         if (state.errors) {
-            SET_ERROR(Str_newf("JSON syntax error"), save, end);
+            SET_ERROR(CB_newf("JSON syntax error"), save, end);
             return NULL;
         }
     }
@@ -479,7 +482,7 @@ S_do_parse_json(void *json_parser, char *json, size_t len) {
     // Finish up.
     LucyParseJson(json_parser, 0, NULL, &state);
     if (state.errors) {
-        SET_ERROR(Str_newf("JSON syntax error"), json, end);
+        SET_ERROR(CB_newf("JSON syntax error"), json, end);
         return NULL;
     }
     return state.result;
@@ -518,7 +521,7 @@ S_parse_number(char **json_ptr, char *const limit) {
         }
     }
     if (!result) {
-        SET_ERROR(Str_newf("JSON syntax error"), top, limit);
+        SET_ERROR(CB_newf("JSON syntax error"), top, limit);
     }
     return result;
 }
@@ -545,7 +548,7 @@ S_parse_string(char **json_ptr, char *const limit) {
         }
     }
     if (!end) {
-        SET_ERROR(Str_newf("Unterminated string"), *json_ptr, limit);
+        SET_ERROR(CB_newf("Unterminated string"), *json_ptr, limit);
         return NULL;
     }
 
@@ -619,12 +622,12 @@ S_unescape_text(char *const top, char *const end) {
                         char *temp_ptr = temp;
                         if (num_end != temp_ptr + 4 || code_point < 0) {
                             FREEMEM(target_buf);
-                            SET_ERROR(Str_newf("Invalid \\u escape"), text - 5, end);
+                            SET_ERROR(CB_newf("Invalid \\u escape"), text - 5, end);
                             return NULL;
                         }
                         if (code_point >= 0xD800 && code_point <= 0xDFFF) {
                             FREEMEM(target_buf);
-                            SET_ERROR(Str_newf("Surrogate pairs not supported"),
+                            SET_ERROR(CB_newf("Surrogate pairs not supported"),
                                       text - 5, end);
                             return NULL;
                         }
@@ -634,7 +637,7 @@ S_unescape_text(char *const top, char *const end) {
                     break;
                 default:
                     FREEMEM(target_buf);
-                    SET_ERROR(Str_newf("Illegal escape"), text - 1, end);
+                    SET_ERROR(CB_newf("Illegal escape"), text - 1, end);
                     return NULL;
             }
         }
@@ -664,14 +667,14 @@ SI_check_keyword(char *json, char* end, const char *keyword, size_t len) {
 }
 
 static void
-S_set_error(String *mess, char *json, char *limit, int line,
+S_set_error(CharBuf *buf, char *json, char *limit, int line,
             const char *func) {
     if (func) {
-        Str_catf(mess, " at %s %s line %i32 near ", func, __FILE__,
+        CB_catf(buf, " at %s %s line %i32 near ", func, __FILE__,
                  (int32_t)line);
     }
     else {
-        Str_catf(mess, " at %s line %i32 near ", __FILE__, (int32_t)line);
+        CB_catf(buf, " at %s line %i32 near ", __FILE__, (int32_t)line);
     }
 
     // Append escaped text.
@@ -681,7 +684,10 @@ S_set_error(String *mess, char *json, char *limit, int line,
         len = end - json;
     }
     StackString *snippet = SSTR_WRAP_STR(json, len);
-    S_append_json_string((Obj*)snippet, mess);
+    S_append_json_string((Obj*)snippet, buf);
+
+    String *mess = CB_Yield_String(buf);
+    DECREF(buf);
 
     // Set Err_error.
     Err_set_error(Err_new(mess));


[lucy-commits] [09/15] git commit: refs/heads/cfish-string-prep1 - Introduce SStr_new_from_str, remove SStr_newf

Posted by nw...@apache.org.
Introduce SStr_new_from_str, remove SStr_newf


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/b38218a9
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/b38218a9
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/b38218a9

Branch: refs/heads/cfish-string-prep1
Commit: b38218a981ee4081dd45619924a123eb04d2ecd0
Parents: f8385c9
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Sep 2 20:57:31 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Sep 2 21:12:30 2013 +0200

----------------------------------------------------------------------
 clownfish/runtime/core/Clownfish/String.c   | 14 ++++++++------
 clownfish/runtime/core/Clownfish/String.cfh |  4 ++--
 core/Lucy/Index/ZombieKeyedHash.c           |  2 +-
 3 files changed, 11 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/b38218a9/clownfish/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.c b/clownfish/runtime/core/Clownfish/String.c
index e2d58b2..92cc1c4 100644
--- a/clownfish/runtime/core/Clownfish/String.c
+++ b/clownfish/runtime/core/Clownfish/String.c
@@ -910,17 +910,19 @@ SStr_new(void *allocation) {
 }
 
 StackString*
-SStr_newf(void *allocation, size_t alloc_size, const char *pattern, ...) {
+SStr_new_from_str(void *allocation, size_t alloc_size, String *string) {
     StackString *self
         = (StackString*)VTable_Init_Obj(STACKSTRING, allocation);
     self->cap  = alloc_size - sizeof(StackString);
-    self->size = 0;
+    self->size = Str_Get_Size(string);
     self->ptr  = ((char*)allocation) + sizeof(StackString);
 
-    va_list args;
-    va_start(args, pattern);
-    SStr_VCatF(self, pattern, args);
-    va_end(args);
+    if (alloc_size < sizeof(StackString) + self->size + 1) {
+        THROW(ERR, "alloc_size of StackString too small");
+    }
+
+    memcpy(self->ptr, Str_Get_Ptr8(string), self->size);
+    self->ptr[self->size] = '\0';
 
     return self;
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/b38218a9/clownfish/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.cfh b/clownfish/runtime/core/Clownfish/String.cfh
index 13cf2d8..8c4618f 100644
--- a/clownfish/runtime/core/Clownfish/String.cfh
+++ b/clownfish/runtime/core/Clownfish/String.cfh
@@ -377,10 +377,10 @@ class Clownfish::StackString cnick SStr
      * @param allocation A single block of memory which will be used for both
      * the StackString object and its buffer.
      * @param alloc_size The size of the allocation.
-     * @param pattern A format pattern.
+     * @param string String to be copied.
      */
     inert incremented StackString*
-    newf(void *allocation, size_t alloc_size, const char *pattern, ...);
+    new_from_str(void *allocation, size_t alloc_size, String *string);
 
     inert incremented StackString*
     wrap(void *allocation, const String *source);

http://git-wip-us.apache.org/repos/asf/lucy/blob/b38218a9/core/Lucy/Index/ZombieKeyedHash.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/ZombieKeyedHash.c b/core/Lucy/Index/ZombieKeyedHash.c
index b9ae141..2747888 100644
--- a/core/Lucy/Index/ZombieKeyedHash.c
+++ b/core/Lucy/Index/ZombieKeyedHash.c
@@ -49,7 +49,7 @@ ZKHash_Make_Key_IMP(ZombieKeyedHash *self, Obj *key, int32_t hash_sum) {
                 String *source = (String*)key;
                 size_t size = SStr_size() + Str_Get_Size(source) + 1;
                 void *allocation = MemPool_Grab(ivars->mem_pool, size);
-                retval = (Obj*)SStr_newf(allocation, size, "%o", source);
+                retval = (Obj*)SStr_new_from_str(allocation, size, source);
             }
             break;
         case FType_INT32: {


[lucy-commits] [07/15] git commit: refs/heads/cfish-string-prep1 - Eliminate Str_Cat_Char in Lucy::Test

Posted by nw...@apache.org.
Eliminate Str_Cat_Char in Lucy::Test


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/a94a2c12
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/a94a2c12
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/a94a2c12

Branch: refs/heads/cfish-string-prep1
Commit: a94a2c12658c795ffb9caccd90f609b813bc669f
Parents: ee8b20d
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Sep 2 20:20:04 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Sep 2 21:12:30 2013 +0200

----------------------------------------------------------------------
 core/Lucy/Test/Plan/TestFieldMisc.c | 3 +--
 core/Lucy/Test/Util/TestJson.c      | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/a94a2c12/core/Lucy/Test/Plan/TestFieldMisc.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Plan/TestFieldMisc.c b/core/Lucy/Test/Plan/TestFieldMisc.c
index 028ac35..1717c78 100644
--- a/core/Lucy/Test/Plan/TestFieldMisc.c
+++ b/core/Lucy/Test/Plan/TestFieldMisc.c
@@ -202,8 +202,7 @@ test_many_fields(TestBatchRunner *runner) {
         String *content;
 
         for (int c = 'a'; c <= 'z'; ++c) {
-            content = Str_new(1);
-            Str_Cat_Char(content, c);
+            content = Str_new_from_char(c);
             S_add_many_fields_doc(indexer, content, num_fields);
             DECREF(content);
         }

http://git-wip-us.apache.org/repos/asf/lucy/blob/a94a2c12/core/Lucy/Test/Util/TestJson.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Util/TestJson.c b/core/Lucy/Test/Util/TestJson.c
index b8efba7..3872a1d 100644
--- a/core/Lucy/Test/Util/TestJson.c
+++ b/core/Lucy/Test/Util/TestJson.c
@@ -115,8 +115,7 @@ static const char* quote_escapes_json[] = {
 static void
 test_escapes(TestBatchRunner *runner) {
     for (int i = 0; control_escapes[i] != NULL; i++) {
-        String *string = Str_new(1);
-        Str_Cat_Char(string, i);
+        String     *string  = Str_new_from_char(i);
         const char *escaped = control_escapes[i];
         String     *json    = Json_to_json((Obj*)string);
         String     *decoded = (String*)Json_from_json(json);


[lucy-commits] [11/15] git commit: refs/heads/cfish-string-prep1 - Introduce Str_init_from_trusted_utf8

Posted by nw...@apache.org.
Introduce Str_init_from_trusted_utf8


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/3e924ab7
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/3e924ab7
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/3e924ab7

Branch: refs/heads/cfish-string-prep1
Commit: 3e924ab7a3b42c9e23031a649bf9cd5e31654614
Parents: a94a2c1
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Sep 2 20:27:31 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Sep 2 21:12:30 2013 +0200

----------------------------------------------------------------------
 clownfish/runtime/core/Clownfish/String.c   | 7 ++++++-
 clownfish/runtime/core/Clownfish/String.cfh | 6 ++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/3e924ab7/clownfish/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.c b/clownfish/runtime/core/Clownfish/String.c
index 2a46393..e2d58b2 100644
--- a/clownfish/runtime/core/Clownfish/String.c
+++ b/clownfish/runtime/core/Clownfish/String.c
@@ -74,13 +74,18 @@ Str_new_from_utf8(const char *ptr, size_t size) {
     if (!StrHelp_utf8_valid(ptr, size)) {
         DIE_INVALID_UTF8(ptr, size);
     }
-    return Str_new_from_trusted_utf8(ptr, size);
+    String *self = (String*)VTable_Make_Obj(STRING);
+    return Str_init_from_trusted_utf8(self, ptr, size);
 }
 
 String*
 Str_new_from_trusted_utf8(const char *ptr, size_t size) {
     String *self = (String*)VTable_Make_Obj(STRING);
+    return Str_init_from_trusted_utf8(self, ptr, size);
+}
 
+String*
+Str_init_from_trusted_utf8(String *self, const char *ptr, size_t size) {
     // Derive.
     self->ptr = (char*)MALLOCATE(size + 1);
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/3e924ab7/clownfish/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.cfh b/clownfish/runtime/core/Clownfish/String.cfh
index db8689b..13cf2d8 100644
--- a/clownfish/runtime/core/Clownfish/String.cfh
+++ b/clownfish/runtime/core/Clownfish/String.cfh
@@ -45,6 +45,12 @@ class Clownfish::String cnick Str
     inert incremented String*
     new_from_trusted_utf8(const char *utf8, size_t size);
 
+    /** Initialize the String using the passed-in string.  Do not check
+     * validity of supplied UTF-8.
+     */
+    inert String*
+    init_from_trusted_utf8(String *self, const char *utf8, size_t size);
+
     /** Return a pointer to a new String which assumes ownership of the
      * passed-in string.  Check validity of supplied UTF-8.
      */


[lucy-commits] [12/15] git commit: refs/heads/cfish-string-prep1 - Remove Str_Cat and variants

Posted by nw...@apache.org.
Remove Str_Cat and variants


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/3948f787
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/3948f787
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/3948f787

Branch: refs/heads/cfish-string-prep1
Commit: 3948f7876a1e32456273d157cc2d84a3a259e243
Parents: 6b1837e
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Sep 2 21:07:37 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Sep 2 21:12:30 2013 +0200

----------------------------------------------------------------------
 clownfish/runtime/core/Clownfish/String.c       | 197 +------------------
 clownfish/runtime/core/Clownfish/String.cfh     |  45 +----
 .../runtime/core/Clownfish/Test/TestString.c    | 167 +---------------
 3 files changed, 7 insertions(+), 402 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/3948f787/clownfish/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.c b/clownfish/runtime/core/Clownfish/String.c
index 92cc1c4..499c79e 100644
--- a/clownfish/runtime/core/Clownfish/String.c
+++ b/clownfish/runtime/core/Clownfish/String.c
@@ -30,6 +30,7 @@
 #include "Clownfish/VTable.h"
 #include "Clownfish/String.h"
 
+#include "Clownfish/CharBuf.h"
 #include "Clownfish/Err.h"
 #include "Clownfish/Util/Memory.h"
 #include "Clownfish/Util/StringHelper.h"
@@ -135,11 +136,13 @@ Str_new_from_char(uint32_t code_point) {
 
 String*
 Str_newf(const char *pattern, ...) {
-    String *self = Str_new(strlen(pattern));
+    CharBuf *buf = CB_new(strlen(pattern));
     va_list args;
     va_start(args, pattern);
-    Str_VCatF(self, pattern, args);
+    CB_VCatF(buf, pattern, args);
     va_end(args);
+    String *self = CB_Yield_String(buf);
+    DECREF(buf);
     return self;
 }
 
@@ -199,169 +202,11 @@ S_die_invalid_pattern(const char *pattern) {
     THROW(ERR, "Invalid pattern.");
 }
 
-void
-Str_catf(String *self, const char *pattern, ...) {
-    va_list args;
-    va_start(args, pattern);
-    Str_VCatF(self, pattern, args);
-    va_end(args);
-}
-
-void
-Str_VCatF_IMP(String *self, const char *pattern, va_list args) {
-    size_t      pattern_len   = strlen(pattern);
-    const char *pattern_start = pattern;
-    const char *pattern_end   = pattern + pattern_len;
-    char        buf[64];
-
-    for (; pattern < pattern_end; pattern++) {
-        const char *slice_end = pattern;
-
-        // Consume all characters leading up to a '%'.
-        while (slice_end < pattern_end && *slice_end != '%') { slice_end++; }
-        if (pattern != slice_end) {
-            size_t size = slice_end - pattern;
-            Str_Cat_Trusted_Str(self, pattern, size);
-            pattern = slice_end;
-        }
-
-        if (pattern < pattern_end) {
-            pattern++; // Move past '%'.
-
-            switch (*pattern) {
-                case '%': {
-                        Str_Cat_Trusted_Str(self, "%", 1);
-                    }
-                    break;
-                case 'o': {
-                        Obj *obj = va_arg(args, Obj*);
-                        if (!obj) {
-                            Str_Cat_Trusted_Str(self, "[NULL]", 6);
-                        }
-                        else if (Obj_Is_A(obj, STRING)) {
-                            Str_Cat(self, (String*)obj);
-                        }
-                        else {
-                            String *string = Obj_To_String(obj);
-                            Str_Cat(self, string);
-                            DECREF(string);
-                        }
-                    }
-                    break;
-                case 'i': {
-                        int64_t val = 0;
-                        size_t size;
-                        if (pattern[1] == '8') {
-                            val = va_arg(args, int32_t);
-                            pattern++;
-                        }
-                        else if (pattern[1] == '3' && pattern[2] == '2') {
-                            val = va_arg(args, int32_t);
-                            pattern += 2;
-                        }
-                        else if (pattern[1] == '6' && pattern[2] == '4') {
-                            val = va_arg(args, int64_t);
-                            pattern += 2;
-                        }
-                        else {
-                            S_die_invalid_pattern(pattern_start);
-                        }
-                        size = sprintf(buf, "%" PRId64, val);
-                        Str_Cat_Trusted_Str(self, buf, size);
-                    }
-                    break;
-                case 'u': {
-                        uint64_t val = 0;
-                        size_t size;
-                        if (pattern[1] == '8') {
-                            val = va_arg(args, uint32_t);
-                            pattern += 1;
-                        }
-                        else if (pattern[1] == '3' && pattern[2] == '2') {
-                            val = va_arg(args, uint32_t);
-                            pattern += 2;
-                        }
-                        else if (pattern[1] == '6' && pattern[2] == '4') {
-                            val = va_arg(args, uint64_t);
-                            pattern += 2;
-                        }
-                        else {
-                            S_die_invalid_pattern(pattern_start);
-                        }
-                        size = sprintf(buf, "%" PRIu64, val);
-                        Str_Cat_Trusted_Str(self, buf, size);
-                    }
-                    break;
-                case 'f': {
-                        if (pattern[1] == '6' && pattern[2] == '4') {
-                            double num  = va_arg(args, double);
-                            char bigbuf[512];
-                            size_t size = sprintf(bigbuf, "%g", num);
-                            Str_Cat_Trusted_Str(self, bigbuf, size);
-                            pattern += 2;
-                        }
-                        else {
-                            S_die_invalid_pattern(pattern_start);
-                        }
-                    }
-                    break;
-                case 'x': {
-                        if (pattern[1] == '3' && pattern[2] == '2') {
-                            unsigned long val = va_arg(args, uint32_t);
-                            size_t size = sprintf(buf, "%.8lx", val);
-                            Str_Cat_Trusted_Str(self, buf, size);
-                            pattern += 2;
-                        }
-                        else {
-                            S_die_invalid_pattern(pattern_start);
-                        }
-                    }
-                    break;
-                case 's': {
-                        char *string = va_arg(args, char*);
-                        if (string == NULL) {
-                            Str_Cat_Trusted_Str(self, "[NULL]", 6);
-                        }
-                        else {
-                            size_t size = strlen(string);
-                            if (StrHelp_utf8_valid(string, size)) {
-                                Str_Cat_Trusted_Str(self, string, size);
-                            }
-                            else {
-                                Str_Cat_Trusted_Str(self, "[INVALID UTF8]", 14);
-                            }
-                        }
-                    }
-                    break;
-                default: {
-                        // Assume NULL-terminated pattern string, which
-                        // eliminates the need for bounds checking if '%' is
-                        // the last visible character.
-                        S_die_invalid_pattern(pattern_start);
-                    }
-            }
-        }
-    }
-}
-
 String*
 Str_To_String_IMP(String *self) {
     return Str_new_from_trusted_utf8(self->ptr, self->size);
 }
 
-void
-Str_Cat_Char_IMP(String *self, uint32_t code_point) {
-    const size_t MAX_UTF8_BYTES = 4;
-    if (self->size + MAX_UTF8_BYTES >= self->cap) {
-        S_grow(self, Memory_oversize(self->size + MAX_UTF8_BYTES,
-                                     sizeof(char)));
-    }
-    char *end = self->ptr + self->size;
-    size_t count = StrHelp_encode_utf8_char(code_point, (uint8_t*)end);
-    self->size += count;
-    *(end + count) = '\0';
-}
-
 int32_t
 Str_Swap_Chars_IMP(String *self, uint32_t match, uint32_t replacement) {
     int32_t num_swapped = 0;
@@ -500,38 +345,6 @@ Str_Immutable_Cat_Trusted_UTF8_IMP(String *self, const char* ptr, size_t size) {
                                       result_size + 1);
 }
 
-void
-Str_Cat_Str_IMP(String *self, const char* ptr, size_t size) {
-    if (!StrHelp_utf8_valid(ptr, size)) {
-        DIE_INVALID_UTF8(ptr, size);
-    }
-    Str_Cat_Trusted_Str_IMP(self, ptr, size);
-}
-
-void
-Str_Cat_Trusted_Str_IMP(String *self, const char* ptr, size_t size) {
-    const size_t new_size = self->size + size;
-    if (new_size >= self->cap) {
-        size_t amount = Memory_oversize(new_size, sizeof(char));
-        S_grow(self, amount);
-    }
-    memcpy((self->ptr + self->size), ptr, size);
-    self->size = new_size;
-    self->ptr[new_size] = '\0';
-}
-
-void
-Str_Cat_IMP(String *self, const String *other) {
-    const size_t new_size = self->size + other->size;
-    if (new_size >= self->cap) {
-        size_t amount = Memory_oversize(new_size, sizeof(char));
-        S_grow(self, amount);
-    }
-    memcpy((self->ptr + self->size), other->ptr, other->size);
-    self->size = new_size;
-    self->ptr[new_size] = '\0';
-}
-
 bool
 Str_Starts_With_IMP(String *self, const String *prefix) {
     return Str_Starts_With_Str_IMP(self, prefix->ptr, prefix->size);

http://git-wip-us.apache.org/repos/asf/lucy/blob/3948f787/clownfish/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.cfh b/clownfish/runtime/core/Clownfish/String.cfh
index 8c4618f..edc52e3 100644
--- a/clownfish/runtime/core/Clownfish/String.cfh
+++ b/clownfish/runtime/core/Clownfish/String.cfh
@@ -76,7 +76,7 @@ class Clownfish::String cnick Str
     new_from_char(uint32_t code_point);
 
     /** Return a pointer to a new String which contains formatted data
-     * expanded according to Str_VCatF.
+     * expanded according to CB_VCatF.
      *
      * Note: a user-supplied <code>pattern</code> string is a security hole
      * and must not be allowed.
@@ -119,43 +119,6 @@ class Clownfish::String cnick Str
     incremented String*
     Immutable_Cat_Trusted_UTF8(String *self, const char *ptr, size_t size);
 
-    /** Concatenate the passed-in string onto the end of the String.
-     */
-    void
-    Cat_Str(String *self, const char *ptr, size_t size);
-
-    /** Concatenate the contents of <code>other</code> onto the end of the
-     * caller.
-     */
-    void
-    Cat(String *self, const String *other);
-
-    /** Concatenate formatted arguments.  Similar to the printf family, but
-     * only accepts minimal options (just enough for decent error messages).
-     *
-     * Objects:  %o
-     * char*:    %s
-     * integers: %i8 %i32 %i64 %u8 %u32 %u64
-     * floats:   %f64
-     * hex:      %x32
-     *
-     * Note that all Clownfish Objects, including Strings, are printed via
-     * %o (which invokes Obj_To_String()).
-     */
-    void
-    VCatF(String *self, const char *pattern, va_list args);
-
-    /** Invokes Str_VCatF to concatenate formatted arguments.  Note that this
-     * is only a function and not a method.
-     */
-    inert void
-    catf(String *self, const char *pattern, ...);
-
-    /** Concatenate one Unicode character onto the end of the String.
-     */
-    void
-    Cat_Char(String *self, uint32_t code_point);
-
     /** Replace all instances of one character for the other.  For now, both
      * the source and replacement code points must be ASCII.
      */
@@ -307,12 +270,6 @@ class Clownfish::String cnick Str
      */
     incremented String*
     SubString(String *self, size_t offset, size_t len);
-
-    /** Concatenate the supplied text onto the end of the String.  Don't
-     * check for UTF-8 validity.
-     */
-    void
-    Cat_Trusted_Str(String *self, const char *ptr, size_t size);
 }
 
 class Clownfish::ViewCharBuf cnick ViewCB

http://git-wip-us.apache.org/repos/asf/lucy/blob/3948f787/clownfish/runtime/core/Clownfish/Test/TestString.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Test/TestString.c b/clownfish/runtime/core/Clownfish/Test/TestString.c
index 5a594a4..cfc2968 100644
--- a/clownfish/runtime/core/Clownfish/Test/TestString.c
+++ b/clownfish/runtime/core/Clownfish/Test/TestString.c
@@ -261,174 +261,9 @@ test_To_I64(TestBatchRunner *runner) {
 }
 
 
-static void
-test_vcatf_s(TestBatchRunner *runner) {
-    String *wanted = S_get_str("foo bar bizzle baz");
-    String *got = S_get_str("foo ");
-    Str_catf(got, "bar %s baz", "bizzle");
-    TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "%%s");
-    DECREF(wanted);
-    DECREF(got);
-}
-
-static void
-test_vcatf_null_string(TestBatchRunner *runner) {
-    String *wanted = S_get_str("foo bar [NULL] baz");
-    String *got = S_get_str("foo ");
-    Str_catf(got, "bar %s baz", NULL);
-    TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "%%s NULL");
-    DECREF(wanted);
-    DECREF(got);
-}
-
-static void
-test_vcatf_str(TestBatchRunner *runner) {
-    String *wanted = S_get_str("foo bar ZEKE baz");
-    String *catworthy = S_get_str("ZEKE");
-    String *got = S_get_str("foo ");
-    Str_catf(got, "bar %o baz", catworthy);
-    TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "%%o String");
-    DECREF(catworthy);
-    DECREF(wanted);
-    DECREF(got);
-}
-
-static void
-test_vcatf_obj(TestBatchRunner *runner) {
-    String    *wanted = S_get_str("ooga 20 booga");
-    Integer32 *i32 = Int32_new(20);
-    String    *got = S_get_str("ooga");
-    Str_catf(got, " %o booga", i32);
-    TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "%%o Obj");
-    DECREF(i32);
-    DECREF(wanted);
-    DECREF(got);
-}
-
-static void
-test_vcatf_null_obj(TestBatchRunner *runner) {
-    String *wanted = S_get_str("foo bar [NULL] baz");
-    String *got = S_get_str("foo ");
-    Str_catf(got, "bar %o baz", NULL);
-    TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "%%o NULL");
-    DECREF(wanted);
-    DECREF(got);
-}
-
-static void
-test_vcatf_i8(TestBatchRunner *runner) {
-    String *wanted = S_get_str("foo bar -3 baz");
-    int8_t num = -3;
-    String *got = S_get_str("foo ");
-    Str_catf(got, "bar %i8 baz", num);
-    TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "%%i8");
-    DECREF(wanted);
-    DECREF(got);
-}
-
-static void
-test_vcatf_i32(TestBatchRunner *runner) {
-    String *wanted = S_get_str("foo bar -100000 baz");
-    int32_t num = -100000;
-    String *got = S_get_str("foo ");
-    Str_catf(got, "bar %i32 baz", num);
-    TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "%%i32");
-    DECREF(wanted);
-    DECREF(got);
-}
-
-static void
-test_vcatf_i64(TestBatchRunner *runner) {
-    String *wanted = S_get_str("foo bar -5000000000 baz");
-    int64_t num = INT64_C(-5000000000);
-    String *got = S_get_str("foo ");
-    Str_catf(got, "bar %i64 baz", num);
-    TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "%%i64");
-    DECREF(wanted);
-    DECREF(got);
-}
-
-static void
-test_vcatf_u8(TestBatchRunner *runner) {
-    String *wanted = S_get_str("foo bar 3 baz");
-    uint8_t num = 3;
-    String *got = S_get_str("foo ");
-    Str_catf(got, "bar %u8 baz", num);
-    TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "%%u8");
-    DECREF(wanted);
-    DECREF(got);
-}
-
-static void
-test_vcatf_u32(TestBatchRunner *runner) {
-    String *wanted = S_get_str("foo bar 100000 baz");
-    uint32_t num = 100000;
-    String *got = S_get_str("foo ");
-    Str_catf(got, "bar %u32 baz", num);
-    TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "%%u32");
-    DECREF(wanted);
-    DECREF(got);
-}
-
-static void
-test_vcatf_u64(TestBatchRunner *runner) {
-    String *wanted = S_get_str("foo bar 5000000000 baz");
-    uint64_t num = UINT64_C(5000000000);
-    String *got = S_get_str("foo ");
-    Str_catf(got, "bar %u64 baz", num);
-    TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "%%u64");
-    DECREF(wanted);
-    DECREF(got);
-}
-
-static void
-test_vcatf_f64(TestBatchRunner *runner) {
-    String *wanted;
-    char buf[64];
-    float num = 1.3f;
-    String *got = S_get_str("foo ");
-    sprintf(buf, "foo bar %g baz", num);
-    wanted = Str_new_from_trusted_utf8(buf, strlen(buf));
-    Str_catf(got, "bar %f64 baz", num);
-    TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "%%f64");
-    DECREF(wanted);
-    DECREF(got);
-}
-
-static void
-test_vcatf_x32(TestBatchRunner *runner) {
-    String *wanted;
-    char buf[64];
-    unsigned long num = INT32_MAX;
-    String *got = S_get_str("foo ");
-#if (SIZEOF_LONG == 4)
-    sprintf(buf, "foo bar %.8lx baz", num);
-#elif (SIZEOF_INT == 4)
-    sprintf(buf, "foo bar %.8x baz", (unsigned)num);
-#endif
-    wanted = Str_new_from_trusted_utf8(buf, strlen(buf));
-    Str_catf(got, "bar %x32 baz", (uint32_t)num);
-    TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "%%x32");
-    DECREF(wanted);
-    DECREF(got);
-}
-
 void
 TestStr_Run_IMP(TestString *self, TestBatchRunner *runner) {
-    TestBatchRunner_Plan(runner, (TestBatch*)self, 53);
-    test_vcatf_s(runner);
-    test_vcatf_null_string(runner);
-    test_vcatf_str(runner);
-    test_vcatf_obj(runner);
-    test_vcatf_null_obj(runner);
-    test_vcatf_i8(runner);
-    test_vcatf_i32(runner);
-    test_vcatf_i64(runner);
-    test_vcatf_u8(runner);
-    test_vcatf_u32(runner);
-    test_vcatf_u64(runner);
-    test_vcatf_f64(runner);
-    test_vcatf_x32(runner);
+    TestBatchRunner_Plan(runner, (TestBatch*)self, 40);
     test_Cat(runner);
     test_Mimic_and_Clone(runner);
     test_Code_Point_At_and_From(runner);


[lucy-commits] [14/15] git commit: refs/heads/cfish-string-prep1 - Eliminate Str_Cat_Trusted_Str in Clownfish::String bindings

Posted by nw...@apache.org.
Eliminate Str_Cat_Trusted_Str in Clownfish::String bindings


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/f8385c9d
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/f8385c9d
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/f8385c9d

Branch: refs/heads/cfish-string-prep1
Commit: f8385c9d9a596e8286342a662bfef796a4d434e8
Parents: 3e924ab
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Sep 2 20:29:11 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Sep 2 21:12:30 2013 +0200

----------------------------------------------------------------------
 clownfish/runtime/perl/buildlib/Clownfish/Build/Binding.pm | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/f8385c9d/clownfish/runtime/perl/buildlib/Clownfish/Build/Binding.pm
----------------------------------------------------------------------
diff --git a/clownfish/runtime/perl/buildlib/Clownfish/Build/Binding.pm b/clownfish/runtime/perl/buildlib/Clownfish/Build/Binding.pm
index 6bed856..5edf4c0 100644
--- a/clownfish/runtime/perl/buildlib/Clownfish/Build/Binding.pm
+++ b/clownfish/runtime/perl/buildlib/Clownfish/Build/Binding.pm
@@ -158,8 +158,7 @@ CODE:
     STRLEN size;
     char *ptr = SvPVutf8(sv, size);
     cfish_String *self = (cfish_String*)XSBind_new_blank_obj(either_sv);
-    cfish_Str_init(self, size);
-    CFISH_Str_Cat_Trusted_Str(self, ptr, size);
+    cfish_Str_init_from_trusted_utf8(self, ptr, size);
     RETVAL = CFISH_OBJ_TO_SV_NOINC(self);
 }
 OUTPUT: RETVAL


[lucy-commits] [08/15] git commit: refs/heads/cfish-string-prep1 - Eliminate Str_Cat_Char in TestString

Posted by nw...@apache.org.
Eliminate Str_Cat_Char in TestString


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/6b1837e6
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/6b1837e6
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/6b1837e6

Branch: refs/heads/cfish-string-prep1
Commit: 6b1837e673178d8be613b713992c1026c9e4b640
Parents: b38218a
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Sep 2 21:05:41 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Sep 2 21:12:30 2013 +0200

----------------------------------------------------------------------
 .../runtime/core/Clownfish/Test/TestString.c    | 22 ++++++++++----------
 1 file changed, 11 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/6b1837e6/clownfish/runtime/core/Clownfish/Test/TestString.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Test/TestString.c b/clownfish/runtime/core/Clownfish/Test/TestString.c
index a3da8ce..5a594a4 100644
--- a/clownfish/runtime/core/Clownfish/Test/TestString.c
+++ b/clownfish/runtime/core/Clownfish/Test/TestString.c
@@ -26,6 +26,7 @@
 #include "Clownfish/Test/TestString.h"
 
 #include "Clownfish/String.h"
+#include "Clownfish/CharBuf.h"
 #include "Clownfish/Num.h"
 #include "Clownfish/Test.h"
 #include "Clownfish/TestHarness/TestBatchRunner.h"
@@ -192,13 +193,15 @@ test_Trim(TestBatchRunner *runner) {
     };
     uint32_t num_spaces = sizeof(spaces) / sizeof(uint32_t);
     uint32_t i;
-    String *got = Str_new(0);
+    String *got;
 
     // Surround a smiley with lots of whitespace.
-    for (i = 0; i < num_spaces; i++) { Str_Cat_Char(got, spaces[i]); }
-    Str_Cat_Char(got, 0x263A);
-    for (i = 0; i < num_spaces; i++) { Str_Cat_Char(got, spaces[i]); }
+    CharBuf *buf = CB_new(0);
+    for (i = 0; i < num_spaces; i++) { CB_Cat_Char(buf, spaces[i]); }
+    CB_Cat_Char(buf, 0x263A);
+    for (i = 0; i < num_spaces; i++) { CB_Cat_Char(buf, spaces[i]); }
 
+    got = CB_To_String(buf);
     TEST_TRUE(runner, Str_Trim_Top(got), "Trim_Top returns true on success");
     TEST_FALSE(runner, Str_Trim_Top(got),
                "Trim_Top returns false on failure");
@@ -207,19 +210,16 @@ test_Trim(TestBatchRunner *runner) {
                "Trim_Tail returns false on failure");
     TEST_TRUE(runner, Str_Equals_Str(got, smiley, smiley_len),
               "Trim_Top and Trim_Tail worked");
+    DECREF(got);
 
-    // Build the spacey smiley again.
-    Str_Truncate(got, 0);
-    for (i = 0; i < num_spaces; i++) { Str_Cat_Char(got, spaces[i]); }
-    Str_Cat_Char(got, 0x263A);
-    for (i = 0; i < num_spaces; i++) { Str_Cat_Char(got, spaces[i]); }
-
+    got = CB_To_String(buf);
     TEST_TRUE(runner, Str_Trim(got), "Trim returns true on success");
     TEST_FALSE(runner, Str_Trim(got), "Trim returns false on failure");
     TEST_TRUE(runner, Str_Equals_Str(got, smiley, smiley_len),
               "Trim worked");
-
     DECREF(got);
+
+    DECREF(buf);
 }
 
 static void


[lucy-commits] [15/15] git commit: refs/heads/cfish-string-prep1 - Rename Str_Immutable_Cat to Str_Cat

Posted by nw...@apache.org.
Rename Str_Immutable_Cat to Str_Cat


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/56fb0e1d
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/56fb0e1d
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/56fb0e1d

Branch: refs/heads/cfish-string-prep1
Commit: 56fb0e1dd764f960c7c60a4a235e77e406394540
Parents: 3948f78
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Sep 2 21:15:19 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Sep 2 21:15:19 2013 +0200

----------------------------------------------------------------------
 clownfish/runtime/core/Clownfish/Err.c             |  2 +-
 clownfish/runtime/core/Clownfish/String.c          | 10 +++++-----
 clownfish/runtime/core/Clownfish/String.cfh        |  6 +++---
 clownfish/runtime/core/Clownfish/Test/TestString.c |  6 +++---
 core/Lucy/Index/BackgroundMerger.c                 |  2 +-
 core/Lucy/Index/Indexer.c                          |  2 +-
 6 files changed, 14 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/56fb0e1d/clownfish/runtime/core/Clownfish/Err.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Err.c b/clownfish/runtime/core/Clownfish/Err.c
index 6d58301..92050cc 100644
--- a/clownfish/runtime/core/Clownfish/Err.c
+++ b/clownfish/runtime/core/Clownfish/Err.c
@@ -58,7 +58,7 @@ Err_To_String_IMP(Err *self) {
 
 void
 Err_Cat_Mess_IMP(Err *self, const String *mess) {
-    String *new_mess = Str_Immutable_Cat(self->mess, mess);
+    String *new_mess = Str_Cat(self->mess, mess);
     DECREF(self->mess);
     self->mess = new_mess;
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/56fb0e1d/clownfish/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.c b/clownfish/runtime/core/Clownfish/String.c
index 499c79e..07da5d8 100644
--- a/clownfish/runtime/core/Clownfish/String.c
+++ b/clownfish/runtime/core/Clownfish/String.c
@@ -321,20 +321,20 @@ Str_Mimic_IMP(String *self, Obj *other) {
 }
 
 String*
-Str_Immutable_Cat_IMP(String *self, const String *other) {
-    return Str_Immutable_Cat_Trusted_UTF8(self, other->ptr, other->size);
+Str_Cat_IMP(String *self, const String *other) {
+    return Str_Cat_Trusted_UTF8(self, other->ptr, other->size);
 }
 
 String*
-Str_Immutable_Cat_UTF8_IMP(String *self, const char* ptr, size_t size) {
+Str_Cat_UTF8_IMP(String *self, const char* ptr, size_t size) {
     if (!StrHelp_utf8_valid(ptr, size)) {
         DIE_INVALID_UTF8(ptr, size);
     }
-    return Str_Immutable_Cat_Trusted_UTF8(self, ptr, size);
+    return Str_Cat_Trusted_UTF8(self, ptr, size);
 }
 
 String*
-Str_Immutable_Cat_Trusted_UTF8_IMP(String *self, const char* ptr, size_t size) {
+Str_Cat_Trusted_UTF8_IMP(String *self, const char* ptr, size_t size) {
     size_t  result_size = self->size + size;
     char   *result_ptr  = (char*)MALLOCATE(result_size + 1);
     memcpy(result_ptr, self->ptr, self->size);

http://git-wip-us.apache.org/repos/asf/lucy/blob/56fb0e1d/clownfish/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.cfh b/clownfish/runtime/core/Clownfish/String.cfh
index edc52e3..f56b26c 100644
--- a/clownfish/runtime/core/Clownfish/String.cfh
+++ b/clownfish/runtime/core/Clownfish/String.cfh
@@ -106,18 +106,18 @@ class Clownfish::String cnick Str
     /** Return the concatenation of the String and <code>other</code>.
      */
     incremented String*
-    Immutable_Cat(String *self, const String *other);
+    Cat(String *self, const String *other);
 
     /** Return the concatenation of the String and the passed-in raw UTF-8.
      */
     incremented String*
-    Immutable_Cat_UTF8(String *self, const char *ptr, size_t size);
+    Cat_UTF8(String *self, const char *ptr, size_t size);
 
     /** Return the concatenation of the String and the passed-in raw UTF-8.
      * Don't check for UTF-8 validity.
      */
     incremented String*
-    Immutable_Cat_Trusted_UTF8(String *self, const char *ptr, size_t size);
+    Cat_Trusted_UTF8(String *self, const char *ptr, size_t size);
 
     /** Replace all instances of one character for the other.  For now, both
      * the source and replacement code points must be ASCII.

http://git-wip-us.apache.org/repos/asf/lucy/blob/56fb0e1d/clownfish/runtime/core/Clownfish/Test/TestString.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Test/TestString.c b/clownfish/runtime/core/Clownfish/Test/TestString.c
index cfc2968..5f8337c 100644
--- a/clownfish/runtime/core/Clownfish/Test/TestString.c
+++ b/clownfish/runtime/core/Clownfish/Test/TestString.c
@@ -53,19 +53,19 @@ test_Cat(TestBatchRunner *runner) {
     String *got;
 
     source = S_get_str("");
-    got = Str_Immutable_Cat(source, wanted);
+    got = Str_Cat(source, wanted);
     TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "Cat");
     DECREF(got);
     DECREF(source);
 
     source = S_get_str("a");
-    got = Str_Immutable_Cat_UTF8(source, smiley, smiley_len);
+    got = Str_Cat_UTF8(source, smiley, smiley_len);
     TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "Cat_UTF8");
     DECREF(got);
     DECREF(source);
 
     source = S_get_str("a");
-    got = Str_Immutable_Cat_Trusted_UTF8(source, smiley, smiley_len);
+    got = Str_Cat_Trusted_UTF8(source, smiley, smiley_len);
     TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "Cat_Trusted_UTF8");
     DECREF(got);
     DECREF(source);

http://git-wip-us.apache.org/repos/asf/lucy/blob/56fb0e1d/core/Lucy/Index/BackgroundMerger.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/BackgroundMerger.c b/core/Lucy/Index/BackgroundMerger.c
index 85ca89c..45bd39d 100644
--- a/core/Lucy/Index/BackgroundMerger.c
+++ b/core/Lucy/Index/BackgroundMerger.c
@@ -413,7 +413,7 @@ BGMerger_Prepare_Commit_IMP(BackgroundMerger *self) {
         // Write temporary snapshot file.
         DECREF(ivars->snapfile);
         String *snapfile = IxManager_Make_Snapshot_Filename(ivars->manager);
-        ivars->snapfile = Str_Immutable_Cat_Trusted_UTF8(snapfile, ".temp", 5);
+        ivars->snapfile = Str_Cat_Trusted_UTF8(snapfile, ".temp", 5);
         DECREF(snapfile);
         Folder_Delete(folder, ivars->snapfile);
         Snapshot_Write_File(snapshot, folder, ivars->snapfile);

http://git-wip-us.apache.org/repos/asf/lucy/blob/56fb0e1d/core/Lucy/Index/Indexer.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/Indexer.c b/core/Lucy/Index/Indexer.c
index a564049..815e7b4 100644
--- a/core/Lucy/Index/Indexer.c
+++ b/core/Lucy/Index/Indexer.c
@@ -508,7 +508,7 @@ Indexer_Prepare_Commit_IMP(Indexer *self) {
         // Derive snapshot and schema file names.
         DECREF(ivars->snapfile);
         String *snapfile = IxManager_Make_Snapshot_Filename(ivars->manager);
-        ivars->snapfile = Str_Immutable_Cat_Trusted_UTF8(snapfile, ".temp", 5);
+        ivars->snapfile = Str_Cat_Trusted_UTF8(snapfile, ".temp", 5);
         DECREF(snapfile);
         uint64_t schema_gen = IxFileNames_extract_gen(ivars->snapfile);
         char base36[StrHelp_MAX_BASE36_BYTES];


[lucy-commits] [04/15] git commit: refs/heads/cfish-string-prep1 - Convert Search::Query subclasses to CharBuf

Posted by nw...@apache.org.
Convert Search::Query subclasses to CharBuf


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/b34f1000
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/b34f1000
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/b34f1000

Branch: refs/heads/cfish-string-prep1
Commit: b34f1000eb6b09e281bf033de336e92dd127daf6
Parents: 04e9f41
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Sep 2 19:32:28 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Sep 2 21:12:29 2013 +0200

----------------------------------------------------------------------
 core/Lucy/Search/ANDQuery.c        | 12 ++++++++----
 core/Lucy/Search/ORQuery.c         | 12 ++++++++----
 core/Lucy/Search/PhraseQuery.c     | 16 ++++++++++------
 core/LucyX/Search/ProximityQuery.c | 16 ++++++++++------
 4 files changed, 36 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/b34f1000/core/Lucy/Search/ANDQuery.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/ANDQuery.c b/core/Lucy/Search/ANDQuery.c
index b23f4f5..0ef378e 100644
--- a/core/Lucy/Search/ANDQuery.c
+++ b/core/Lucy/Search/ANDQuery.c
@@ -19,6 +19,8 @@
 #include "Lucy/Util/ToolSet.h"
 
 #include "Lucy/Search/ANDQuery.h"
+
+#include "Clownfish/CharBuf.h"
 #include "Lucy/Index/DocVector.h"
 #include "Lucy/Index/SegReader.h"
 #include "Lucy/Index/Similarity.h"
@@ -47,18 +49,20 @@ ANDQuery_To_String_IMP(ANDQuery *self) {
     uint32_t num_kids = VA_Get_Size(ivars->children);
     if (!num_kids) { return Str_new_from_trusted_utf8("()", 2); }
     else {
-        String *retval = Str_new_from_trusted_utf8("(", 1);
+        CharBuf *buf = CB_new_from_trusted_utf8("(", 1);
         for (uint32_t i = 0; i < num_kids; i++) {
             String *kid_string = Obj_To_String(VA_Fetch(ivars->children, i));
-            Str_Cat(retval, kid_string);
+            CB_Cat(buf, kid_string);
             DECREF(kid_string);
             if (i == num_kids - 1) {
-                Str_Cat_Trusted_Str(retval, ")", 1);
+                CB_Cat_Trusted_UTF8(buf, ")", 1);
             }
             else {
-                Str_Cat_Trusted_Str(retval, " AND ", 5);
+                CB_Cat_Trusted_UTF8(buf, " AND ", 5);
             }
         }
+        String *retval = CB_Yield_String(buf);
+        DECREF(buf);
         return retval;
     }
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/b34f1000/core/Lucy/Search/ORQuery.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/ORQuery.c b/core/Lucy/Search/ORQuery.c
index 9d15704..3ee0cfd 100644
--- a/core/Lucy/Search/ORQuery.c
+++ b/core/Lucy/Search/ORQuery.c
@@ -19,6 +19,8 @@
 #include "Lucy/Util/ToolSet.h"
 
 #include "Lucy/Search/ORQuery.h"
+
+#include "Clownfish/CharBuf.h"
 #include "Lucy/Index/SegReader.h"
 #include "Lucy/Index/Similarity.h"
 #include "Lucy/Search/ORMatcher.h"
@@ -62,19 +64,21 @@ ORQuery_To_String_IMP(ORQuery *self) {
     uint32_t num_kids = VA_Get_Size(ivars->children);
     if (!num_kids) { return Str_new_from_trusted_utf8("()", 2); }
     else {
-        String *retval = Str_new_from_trusted_utf8("(", 1);
+        CharBuf *buf = CB_new_from_trusted_utf8("(", 1);
         uint32_t last_kid = num_kids - 1;
         for (uint32_t i = 0; i < num_kids; i++) {
             String *kid_string = Obj_To_String(VA_Fetch(ivars->children, i));
-            Str_Cat(retval, kid_string);
+            CB_Cat(buf, kid_string);
             DECREF(kid_string);
             if (i == last_kid) {
-                Str_Cat_Trusted_Str(retval, ")", 1);
+                CB_Cat_Trusted_UTF8(buf, ")", 1);
             }
             else {
-                Str_Cat_Trusted_Str(retval, " OR ", 4);
+                CB_Cat_Trusted_UTF8(buf, " OR ", 4);
             }
         }
+        String *retval = CB_Yield_String(buf);
+        DECREF(buf);
         return retval;
     }
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/b34f1000/core/Lucy/Search/PhraseQuery.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/PhraseQuery.c b/core/Lucy/Search/PhraseQuery.c
index 5bc3edb..4f02f61 100644
--- a/core/Lucy/Search/PhraseQuery.c
+++ b/core/Lucy/Search/PhraseQuery.c
@@ -20,6 +20,8 @@
 #include "Lucy/Util/ToolSet.h"
 
 #include "Lucy/Search/PhraseQuery.h"
+
+#include "Clownfish/CharBuf.h"
 #include "Lucy/Index/DocVector.h"
 #include "Lucy/Index/Posting.h"
 #include "Lucy/Index/Posting/ScorePosting.h"
@@ -137,18 +139,20 @@ String*
 PhraseQuery_To_String_IMP(PhraseQuery *self) {
     PhraseQueryIVARS *const ivars = PhraseQuery_IVARS(self);
     uint32_t  num_terms = VA_Get_Size(ivars->terms);
-    String   *retval    = Str_Clone(ivars->field);
-    Str_Cat_Trusted_Str(retval, ":\"", 2);
+    CharBuf  *buf       = CB_new_from_str(ivars->field);
+    CB_Cat_Trusted_UTF8(buf, ":\"", 2);
     for (uint32_t i = 0; i < num_terms; i++) {
-        Obj     *term        = VA_Fetch(ivars->terms, i);
+        Obj    *term        = VA_Fetch(ivars->terms, i);
         String *term_string = Obj_To_String(term);
-        Str_Cat(retval, term_string);
+        CB_Cat(buf, term_string);
         DECREF(term_string);
         if (i < num_terms - 1) {
-            Str_Cat_Trusted_Str(retval, " ",  1);
+            CB_Cat_Trusted_UTF8(buf, " ",  1);
         }
     }
-    Str_Cat_Trusted_Str(retval, "\"", 1);
+    CB_Cat_Trusted_UTF8(buf, "\"", 1);
+    String *retval = CB_Yield_String(buf);
+    DECREF(buf);
     return retval;
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/b34f1000/core/LucyX/Search/ProximityQuery.c
----------------------------------------------------------------------
diff --git a/core/LucyX/Search/ProximityQuery.c b/core/LucyX/Search/ProximityQuery.c
index 33e4865..903995a 100644
--- a/core/LucyX/Search/ProximityQuery.c
+++ b/core/LucyX/Search/ProximityQuery.c
@@ -20,6 +20,8 @@
 #include "Lucy/Util/ToolSet.h"
 
 #include "LucyX/Search/ProximityQuery.h"
+
+#include "Clownfish/CharBuf.h"
 #include "Lucy/Index/DocVector.h"
 #include "Lucy/Index/Posting.h"
 #include "Lucy/Index/Posting/ScorePosting.h"
@@ -148,19 +150,21 @@ String*
 ProximityQuery_To_String_IMP(ProximityQuery *self) {
     ProximityQueryIVARS *const ivars = ProximityQuery_IVARS(self);
     uint32_t num_terms = VA_Get_Size(ivars->terms);
-    String *retval = Str_Clone(ivars->field);
-    Str_Cat_Trusted_Str(retval, ":\"", 2);
+    CharBuf *buf = CB_new_from_str(ivars->field);
+    CB_Cat_Trusted_UTF8(buf, ":\"", 2);
     for (uint32_t i = 0; i < num_terms; i++) {
         Obj *term = VA_Fetch(ivars->terms, i);
         String *term_string = Obj_To_String(term);
-        Str_Cat(retval, term_string);
+        CB_Cat(buf, term_string);
         DECREF(term_string);
         if (i < num_terms - 1) {
-            Str_Cat_Trusted_Str(retval, " ",  1);
+            CB_Cat_Trusted_UTF8(buf, " ",  1);
         }
     }
-    Str_Cat_Trusted_Str(retval, "\"", 1);
-    Str_catf(retval, "~%u32", ivars->within);
+    CB_Cat_Trusted_UTF8(buf, "\"", 1);
+    CB_catf(buf, "~%u32", ivars->within);
+    String *retval = CB_Yield_String(buf);
+    DECREF(buf);
     return retval;
 }
 


[lucy-commits] [05/15] git commit: refs/heads/cfish-string-prep1 - Convert Search::QueryParser to CharBuf

Posted by nw...@apache.org.
Convert Search::QueryParser to CharBuf


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/3a47204f
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/3a47204f
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/3a47204f

Branch: refs/heads/cfish-string-prep1
Commit: 3a47204fd82ee9845ff71aeeeea8e71cdb53c77e
Parents: b34f100
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Sep 2 19:43:01 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Sep 2 21:12:29 2013 +0200

----------------------------------------------------------------------
 core/Lucy/Search/QueryParser.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/3a47204f/core/Lucy/Search/QueryParser.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/QueryParser.c b/core/Lucy/Search/QueryParser.c
index 9728e55..0219432 100644
--- a/core/Lucy/Search/QueryParser.c
+++ b/core/Lucy/Search/QueryParser.c
@@ -20,6 +20,8 @@
 #include "Lucy/Util/ToolSet.h"
 
 #include "Lucy/Search/QueryParser.h"
+
+#include "Clownfish/CharBuf.h"
 #include "Lucy/Search/QueryParser/ParserElem.h"
 #include "Lucy/Search/QueryParser/QueryLexer.h"
 #include "Lucy/Analysis/Analyzer.h"
@@ -823,13 +825,13 @@ QParser_Expand_IMP(QueryParser *self, Query *query) {
 }
 
 static String*
-S_unescape(QueryParser *self, String *orig, String *target) {
+S_unescape(QueryParser *self, String *orig, CharBuf *buf) {
     StackString *source = SSTR_WRAP(orig);
     uint32_t code_point;
     UNUSED_VAR(self);
 
-    Str_Set_Size(target, 0);
-    Str_Grow(target, Str_Get_Size(orig) + 4);
+    CB_Set_Size(buf, 0);
+    CB_Grow(buf, Str_Get_Size(orig) + 4);
 
     while (0 != (code_point = SStr_Nibble(source))) {
         if (code_point == '\\') {
@@ -838,19 +840,19 @@ S_unescape(QueryParser *self, String *orig, String *target) {
                 || next_code_point == '"'
                 || next_code_point == '\\'
                ) {
-                Str_Cat_Char(target, next_code_point);
+                CB_Cat_Char(buf, next_code_point);
             }
             else {
-                Str_Cat_Char(target, code_point);
-                if (next_code_point) { Str_Cat_Char(target, next_code_point); }
+                CB_Cat_Char(buf, code_point);
+                if (next_code_point) { CB_Cat_Char(buf, next_code_point); }
             }
         }
         else {
-            Str_Cat_Char(target, code_point);
+            CB_Cat_Char(buf, code_point);
         }
     }
 
-    return target;
+    return CB_To_String(buf);
 }
 
 Query*
@@ -889,8 +891,8 @@ QParser_Expand_Leaf_IMP(QueryParser *self, Query *query) {
         fields = (VArray*)INCREF(ivars->fields);
     }
 
-    String *unescaped = Str_new(SStr_Get_Size(source_text));
-    VArray *queries   = VA_new(VA_Get_Size(fields));
+    CharBuf *unescape_buf = CB_new(SStr_Get_Size(source_text));
+    VArray  *queries      = VA_new(VA_Get_Size(fields));
     for (uint32_t i = 0, max = VA_Get_Size(fields); i < max; i++) {
         String   *field    = (String*)VA_Fetch(fields, i);
         Analyzer *analyzer = ivars->analyzer
@@ -905,7 +907,7 @@ QParser_Expand_Leaf_IMP(QueryParser *self, Query *query) {
         else {
             // Extract token texts.
             String *split_source
-                = S_unescape(self, (String*)source_text, unescaped);
+                = S_unescape(self, (String*)source_text, unescape_buf);
             VArray *maybe_texts = Analyzer_Split(analyzer, split_source);
             uint32_t num_maybe_texts = VA_Get_Size(maybe_texts);
             VArray *token_texts = VA_new(num_maybe_texts);
@@ -935,6 +937,7 @@ QParser_Expand_Leaf_IMP(QueryParser *self, Query *query) {
 
             DECREF(token_texts);
             DECREF(maybe_texts);
+            DECREF(split_source);
         }
     }
 
@@ -953,7 +956,7 @@ QParser_Expand_Leaf_IMP(QueryParser *self, Query *query) {
     }
 
     // Clean up.
-    DECREF(unescaped);
+    DECREF(unescape_buf);
     DECREF(queries);
     DECREF(fields);
 


[lucy-commits] [13/15] git commit: refs/heads/cfish-string-prep1 - Introduce Str_new_from_char

Posted by nw...@apache.org.
Introduce Str_new_from_char


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/ee8b20d5
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/ee8b20d5
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/ee8b20d5

Branch: refs/heads/cfish-string-prep1
Commit: ee8b20d55fc566c6d99a481e4d5e2da7e670aa92
Parents: 0f0ec86
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Sep 2 20:19:40 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Sep 2 21:12:30 2013 +0200

----------------------------------------------------------------------
 clownfish/runtime/core/Clownfish/String.c   | 11 +++++++++++
 clownfish/runtime/core/Clownfish/String.cfh |  5 +++++
 2 files changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/ee8b20d5/clownfish/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.c b/clownfish/runtime/core/Clownfish/String.c
index a2f0a3f..2a46393 100644
--- a/clownfish/runtime/core/Clownfish/String.c
+++ b/clownfish/runtime/core/Clownfish/String.c
@@ -118,6 +118,17 @@ Str_new_steal_str(char *ptr, size_t size, size_t cap) {
 }
 
 String*
+Str_new_from_char(uint32_t code_point) {
+    const size_t MAX_UTF8_BYTES = 4;
+    String *self = (String*)VTable_Make_Obj(STRING);
+    self->ptr  = (char*)MALLOCATE(MAX_UTF8_BYTES + 1);
+    self->cap  = MAX_UTF8_BYTES + 1;
+    self->size = StrHelp_encode_utf8_char(code_point, (uint8_t*)self->ptr);
+    self->ptr[self->size] = '\0';
+    return self;
+}
+
+String*
 Str_newf(const char *pattern, ...) {
     String *self = Str_new(strlen(pattern));
     va_list args;

http://git-wip-us.apache.org/repos/asf/lucy/blob/ee8b20d5/clownfish/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.cfh b/clownfish/runtime/core/Clownfish/String.cfh
index 529cc70..db8689b 100644
--- a/clownfish/runtime/core/Clownfish/String.cfh
+++ b/clownfish/runtime/core/Clownfish/String.cfh
@@ -64,6 +64,11 @@ class Clownfish::String cnick Str
     init_steal_trusted_str(decremented String *self, char *ptr,
                            size_t size, size_t cap);
 
+    /** Return a String which holds a single character.
+     */
+    inert incremented String*
+    new_from_char(uint32_t code_point);
+
     /** Return a pointer to a new String which contains formatted data
      * expanded according to Str_VCatF.
      *


[lucy-commits] [02/15] git commit: refs/heads/cfish-string-prep1 - Eliminate Str_catf in Store::InStream

Posted by nw...@apache.org.
Eliminate Str_catf in Store::InStream


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/f028d091
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/f028d091
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/f028d091

Branch: refs/heads/cfish-string-prep1
Commit: f028d0910a8b2ebd8558f0d19ca696e3b8c74998
Parents: 5c9d7a7
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Sep 2 20:00:53 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Sep 2 21:12:29 2013 +0200

----------------------------------------------------------------------
 core/Lucy/Store/InStream.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/f028d091/core/Lucy/Store/InStream.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/InStream.c b/core/Lucy/Store/InStream.c
index cb975ce..d68efa4 100644
--- a/core/Lucy/Store/InStream.c
+++ b/core/Lucy/Store/InStream.c
@@ -219,7 +219,9 @@ S_fill(InStream *self, int64_t amount) {
     }
     else {
         Err *error = Err_get_error();
-        Str_catf(Err_Get_Mess(error), " (%o)", ivars->filename);
+        String *str = Str_newf(" (%o)", ivars->filename);
+        Err_Cat_Mess(error, str);
+        DECREF(str);
         RETHROW(INCREF(error));
     }
 }


[lucy-commits] [03/15] git commit: refs/heads/cfish-string-prep1 - Fix CharBuf usage in Highlighter

Posted by nw...@apache.org.
Fix CharBuf usage in Highlighter


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/4be6f870
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/4be6f870
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/4be6f870

Branch: refs/heads/cfish-string-prep1
Commit: 4be6f8703c58719283f89ca4da8fa75899f56e7c
Parents: 3a47204
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Sep 2 19:43:49 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Sep 2 21:12:29 2013 +0200

----------------------------------------------------------------------
 core/Lucy/Highlight/Highlighter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/4be6f870/core/Lucy/Highlight/Highlighter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Highlight/Highlighter.c b/core/Lucy/Highlight/Highlighter.c
index b245eae..d98c027 100644
--- a/core/Lucy/Highlight/Highlighter.c
+++ b/core/Lucy/Highlight/Highlighter.c
@@ -765,7 +765,7 @@ S_encode_entities(String *text, CharBuf *buf) {
         }
     }
 
-    return CB_Yield_String(buf);
+    return CB_To_String(buf);
 }