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:39 UTC
[04/15] lucy-clownfish git commit: Change Code_Point_{At|From} return
value
Change Code_Point_{At|From} return value
Make Code_Point_{At|From} return STR_OOB (-1) instead of 0 if the tick
is out of bounds. This allows to process strings containing U+0000.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/77d6dfd6
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/77d6dfd6
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/77d6dfd6
Branch: refs/heads/master
Commit: 77d6dfd6dae2d60be0424adfa82a197c769ab95d
Parents: 0bfc349
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Thu Oct 22 15:46:42 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Wed Oct 28 15:35:18 2015 +0100
----------------------------------------------------------------------
runtime/core/Clownfish/String.c | 6 +++---
runtime/core/Clownfish/String.cfh | 8 ++++----
runtime/core/Clownfish/Test/TestString.c | 8 ++++----
3 files changed, 11 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/77d6dfd6/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/String.c b/runtime/core/Clownfish/String.c
index dd6d5dd..7d0b871 100644
--- a/runtime/core/Clownfish/String.c
+++ b/runtime/core/Clownfish/String.c
@@ -432,16 +432,16 @@ 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 ? 0 : code_point;
+ return code_point == STRITER_DONE ? STR_OOB : code_point;
}
int32_t
Str_Code_Point_From_IMP(String *self, size_t tick) {
- if (tick == 0) { return 0; }
+ 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 ? 0 : code_point;
+ return code_point == STRITER_DONE ? STR_OOB : code_point;
}
String*
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/77d6dfd6/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/String.cfh b/runtime/core/Clownfish/String.cfh
index 55b56a4..9501970 100644
--- a/runtime/core/Clownfish/String.cfh
+++ b/runtime/core/Clownfish/String.cfh
@@ -246,15 +246,13 @@ public final class Clownfish::String nickname Str
Trim_Tail(String *self);
/** Return the Unicode code point located `tick` code points in from the
- * top. Return 0 if out of bounds. (XXX It would be
- * better to throw an exception, but that's not practical with UTF-8 and
- * no cached length.)
+ * top. Return CFISH_STR_OOB if out of bounds.
*/
int32_t
Code_Point_At(String *self, size_t tick);
/** Return the Unicode code point located `tick` code points counting
- * backwards from the end. Return 0 if out of bounds.
+ * backwards from the end. Return CFISH_STR_OOB if out of bounds.
*/
int32_t
Code_Point_From(String *self, size_t tick);
@@ -388,11 +386,13 @@ __C__
#define CFISH_SSTR_WRAP_UTF8(ptr, size) \
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_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/77d6dfd6/runtime/core/Clownfish/Test/TestString.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestString.c b/runtime/core/Clownfish/Test/TestString.c
index d3cc38c..275166b 100644
--- a/runtime/core/Clownfish/Test/TestString.c
+++ b/runtime/core/Clownfish/Test/TestString.c
@@ -194,12 +194,12 @@ test_Code_Point_At_and_From(TestBatchRunner *runner) {
code_points[i], "Code_Point_From %ld", (long)from);
}
- TEST_INT_EQ(runner, Str_Code_Point_At(string, num_code_points), 0,
+ TEST_INT_EQ(runner, Str_Code_Point_At(string, num_code_points), STR_OOB,
"Code_Point_At %ld", (long)num_code_points);
- TEST_INT_EQ(runner, Str_Code_Point_From(string, 0), 0,
+ TEST_INT_EQ(runner, Str_Code_Point_From(string, 0), STR_OOB,
"Code_Point_From 0");
- TEST_INT_EQ(runner, Str_Code_Point_From(string, num_code_points + 1), 0,
- "Code_Point_From %ld", (long)(num_code_points + 1));
+ TEST_INT_EQ(runner, Str_Code_Point_From(string, num_code_points + 1),
+ STR_OOB, "Code_Point_From %ld", (long)(num_code_points + 1));
DECREF(string);
}