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 2015/10/30 15:30:49 UTC

[14/15] lucy-clownfish git commit: Return STR_OOB if string iterator is done

Return STR_OOB if string iterator is done

Returning STR_OOB instead of STRITER_DONE aligns better with
Code_Point_At.


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

Branch: refs/heads/master
Commit: 16a4270cdcde34085954e2a26f29f03c3bb2ec0d
Parents: 6fadaae
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Oct 24 16:58:51 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Wed Oct 28 16:10:35 2015 +0100

----------------------------------------------------------------------
 runtime/core/Clownfish/String.c          | 18 ++++++++----------
 runtime/core/Clownfish/String.cfh        |  6 ++----
 runtime/core/Clownfish/Test/TestString.c |  4 ++--
 runtime/go/ext/clownfish.c               |  2 +-
 runtime/perl/xs/XSBind.c                 |  2 +-
 5 files changed, 14 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/16a4270c/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/String.c b/runtime/core/Clownfish/String.c
index dca2b46..db27001 100644
--- a/runtime/core/Clownfish/String.c
+++ b/runtime/core/Clownfish/String.c
@@ -200,7 +200,7 @@ Str_Hash_Sum_IMP(String *self) {
 
     const StrIter_Next_t next = METHOD_PTR(STRINGITERATOR, CFISH_StrIter_Next);
     int32_t code_point;
-    while (STRITER_DONE != (code_point = next(iter))) {
+    while (STR_OOB != (code_point = next(iter))) {
         hashvalue = ((hashvalue << 5) + hashvalue) ^ code_point;
     }
 
@@ -241,7 +241,7 @@ Str_BaseX_To_I64_IMP(String *self, uint32_t base) {
     }
 
     // Accumulate.
-    while (code_point != STRITER_DONE) {
+    while (code_point != STR_OOB) {
         if (isalnum(code_point)) {
             int32_t addend = isdigit(code_point)
                              ? code_point - '0'
@@ -468,8 +468,7 @@ int32_t
 Str_Code_Point_At_IMP(String *self, size_t tick) {
     StringIterator *iter = STACK_ITER(self, 0);
     StrIter_Advance(iter, tick);
-    int32_t code_point = StrIter_Next(iter);
-    return code_point == STRITER_DONE ? STR_OOB : code_point;
+    return StrIter_Next(iter);
 }
 
 int32_t
@@ -477,8 +476,7 @@ Str_Code_Point_From_IMP(String *self, size_t tick) {
     if (tick == 0) { return STR_OOB; }
     StringIterator *iter = STACK_ITER(self, self->size);
     StrIter_Recede(iter, tick - 1);
-    int32_t code_point = StrIter_Prev(iter);
-    return code_point == STRITER_DONE ? STR_OOB : code_point;
+    return StrIter_Prev(iter);
 }
 
 String*
@@ -628,7 +626,7 @@ StrIter_Next_IMP(StringIterator *self) {
     size_t  byte_offset = self->byte_offset;
     size_t  size        = string->size;
 
-    if (byte_offset >= size) { return STRITER_DONE; }
+    if (byte_offset >= size) { return STR_OOB; }
 
     const uint8_t *const ptr = (const uint8_t*)string->ptr;
     int32_t retval = ptr[byte_offset++];
@@ -681,7 +679,7 @@ int32_t
 StrIter_Prev_IMP(StringIterator *self) {
     size_t byte_offset = self->byte_offset;
 
-    if (byte_offset == 0) { return STRITER_DONE; }
+    if (byte_offset == 0) { return STR_OOB; }
 
     const uint8_t *const ptr = (const uint8_t*)self->string->ptr;
     int32_t retval = ptr[--byte_offset];
@@ -776,7 +774,7 @@ StrIter_Skip_Whitespace_IMP(StringIterator *self) {
     size_t  byte_offset = self->byte_offset;
     int32_t code_point;
 
-    while (STRITER_DONE != (code_point = StrIter_Next(self))) {
+    while (STR_OOB != (code_point = StrIter_Next(self))) {
         if (!StrHelp_is_whitespace(code_point)) { break; }
         byte_offset = self->byte_offset;
         ++num_skipped;
@@ -792,7 +790,7 @@ StrIter_Skip_Whitespace_Back_IMP(StringIterator *self) {
     size_t  byte_offset = self->byte_offset;
     int32_t code_point;
 
-    while (STRITER_DONE != (code_point = StrIter_Prev(self))) {
+    while (STR_OOB != (code_point = StrIter_Prev(self))) {
         if (!StrHelp_is_whitespace(code_point)) { break; }
         byte_offset = self->byte_offset;
         ++num_skipped;

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/16a4270c/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/String.cfh b/runtime/core/Clownfish/String.cfh
index a063095..014b6a1 100644
--- a/runtime/core/Clownfish/String.cfh
+++ b/runtime/core/Clownfish/String.cfh
@@ -319,13 +319,13 @@ public final class Clownfish::StringIterator nickname StrIter
     Has_Prev(StringIterator *self);
 
     /** Return the code point after the current position and advance the
-     * iterator. Return CFISH_STRITER_DONE at the end of the string.
+     * iterator. Return CFISH_STR_OOB at the end of the string.
      */
     public int32_t
     Next(StringIterator *self);
 
     /** Return the code point before the current position and go one step back.
-     * Return CFISH_STRITER_DONE at the start of the string.
+     * Return CFISH_STR_OOB at the start of the string.
      */
     public int32_t
     Prev(StringIterator *self);
@@ -396,14 +396,12 @@ __C__
     cfish_Str_init_stack_string(CFISH_ALLOCA_OBJ(CFISH_STRING), ptr, size)
 
 #define CFISH_STR_OOB       -1
-#define CFISH_STRITER_DONE  -1
 
 #ifdef CFISH_USE_SHORT_NAMES
   #define SSTR_BLANK             CFISH_SSTR_BLANK
   #define SSTR_WRAP_C            CFISH_SSTR_WRAP_C
   #define SSTR_WRAP_UTF8         CFISH_SSTR_WRAP_UTF8
   #define STR_OOB                CFISH_STR_OOB
-  #define STRITER_DONE           CFISH_STRITER_DONE
 #endif
 __END_C__
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/16a4270c/runtime/core/Clownfish/Test/TestString.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestString.c b/runtime/core/Clownfish/Test/TestString.c
index 3a11510..6fd5212 100644
--- a/runtime/core/Clownfish/Test/TestString.c
+++ b/runtime/core/Clownfish/Test/TestString.c
@@ -535,7 +535,7 @@ test_iterator(TestBatchRunner *runner) {
 
         TEST_TRUE(runner, !StrIter_Has_Next(iter),
                   "Has_Next at end of string");
-        TEST_INT_EQ(runner, StrIter_Next(iter), STRITER_DONE,
+        TEST_INT_EQ(runner, StrIter_Next(iter), STR_OOB,
                     "Next at end of string");
 
         StringIterator *tail = Str_Tail(string);
@@ -556,7 +556,7 @@ test_iterator(TestBatchRunner *runner) {
 
         TEST_TRUE(runner, !StrIter_Has_Prev(iter),
                   "Has_Prev at end of string");
-        TEST_INT_EQ(runner, StrIter_Prev(iter), STRITER_DONE,
+        TEST_INT_EQ(runner, StrIter_Prev(iter), STR_OOB,
                     "Prev at start of string");
 
         StringIterator *top = Str_Top(string);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/16a4270c/runtime/go/ext/clownfish.c
----------------------------------------------------------------------
diff --git a/runtime/go/ext/clownfish.c b/runtime/go/ext/clownfish.c
index 5d8c01f..884fe0e 100644
--- a/runtime/go/ext/clownfish.c
+++ b/runtime/go/ext/clownfish.c
@@ -182,7 +182,7 @@ Method_Host_Name_IMP(Method *self) {
     StringIterator *iter = StrIter_new(self->name, 0);
     CharBuf *charbuf = CB_new(Str_Get_Size(self->name));
     int32_t code_point;
-    while (STRITER_DONE != (code_point = StrIter_Next(iter))) {
+    while (STR_OOB != (code_point = StrIter_Next(iter))) {
         if (code_point != '_') {
             CB_Cat_Char(charbuf, code_point);
         }

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/16a4270c/runtime/perl/xs/XSBind.c
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c
index a261152..83007ab 100644
--- a/runtime/perl/xs/XSBind.c
+++ b/runtime/perl/xs/XSBind.c
@@ -782,7 +782,7 @@ CFISH_Method_Host_Name_IMP(cfish_Method *self) {
     cfish_CharBuf *buf = cfish_CB_new(CFISH_Str_Get_Size(name));
     cfish_StringIterator *iter = CFISH_Str_Top(name);
     int32_t code_point;
-    while (CFISH_STRITER_DONE != (code_point = CFISH_StrIter_Next(iter))) {
+    while (CFISH_STR_OOB != (code_point = CFISH_StrIter_Next(iter))) {
         if (code_point > 127) {
             THROW(CFISH_ERR, "Can't lowercase '%o'", name);
         }