lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [lucy-commits] [10/20] git commit: refs/heads/cfish-string-prep1 - Introduce StrIter_Ends_With
Date Sat, 07 Sep 2013 16:53:31 GMT
Introduce StrIter_Ends_With


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

Branch: refs/heads/cfish-string-prep1
Commit: cc66dbee8d63fe811ef41e12cef70cef7a7237fe
Parents: e1d95d2
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Sat Sep 7 15:17:08 2013 +0200
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Sat Sep 7 18:14:04 2013 +0200

----------------------------------------------------------------------
 clownfish/runtime/core/Clownfish/String.c       | 20 ++++++++++++++++++++
 clownfish/runtime/core/Clownfish/String.cfh     | 12 ++++++++++++
 .../runtime/core/Clownfish/Test/TestString.c    |  3 ++-
 3 files changed, 34 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/cc66dbee/clownfish/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.c b/clownfish/runtime/core/Clownfish/String.c
index 6bfcea7..c87864a 100644
--- a/clownfish/runtime/core/Clownfish/String.c
+++ b/clownfish/runtime/core/Clownfish/String.c
@@ -1066,6 +1066,26 @@ StrIter_Starts_With_UTF8_IMP(StringIterator *self, const char *prefix,
     return memcmp(string->ptr + byte_offset, prefix, size) == 0;
 }
 
+bool
+StrIter_Ends_With_IMP(StringIterator *self, String *postfix) {
+    return StrIter_Ends_With_UTF8_IMP(self, postfix->ptr, postfix->size);
+}
+
+bool
+StrIter_Ends_With_UTF8_IMP(StringIterator *self, const char *postfix,
+                             size_t size) {
+    String *string      = self->string;
+    size_t  byte_offset = self->byte_offset;
+
+    if (byte_offset > string->size) {
+        THROW(ERR, "Invalid StringIterator offset");
+    }
+
+    if (byte_offset < size) { return false; }
+
+    return memcmp(string->ptr + byte_offset - size, postfix, size) == 0;
+}
+
 void
 StrIter_Destroy_IMP(StringIterator *self) {
     DECREF(self->string);

http://git-wip-us.apache.org/repos/asf/lucy/blob/cc66dbee/clownfish/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.cfh b/clownfish/runtime/core/Clownfish/String.cfh
index 82a51c9..d8e32dd 100644
--- a/clownfish/runtime/core/Clownfish/String.cfh
+++ b/clownfish/runtime/core/Clownfish/String.cfh
@@ -466,6 +466,18 @@ class Clownfish::StringIterator cnick StrIter
     bool
     Starts_With_UTF8(StringIterator *self, const char *prefix, size_t size);
 
+    /** Test whether the content before the iterator ends with
+     * <code>postfix</code>.
+     */
+    bool
+    Ends_With(StringIterator *self, String *postfix);
+
+    /** Test whether the content before the iterator ends with the passed-in
+     * string.
+     */
+    bool
+    Ends_With_UTF8(StringIterator *self, const char *postfix, size_t size);
+
     public void
     Destroy(StringIterator *self);
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/cc66dbee/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 df04794..72f2ecf 100644
--- a/clownfish/runtime/core/Clownfish/Test/TestString.c
+++ b/clownfish/runtime/core/Clownfish/Test/TestString.c
@@ -459,6 +459,7 @@ test_iterator_substring(TestBatchRunner *runner) {
                   "StrIter_substring");
 
         TEST_TRUE(runner, StrIter_Starts_With(start, wanted), "Starts_With");
+        TEST_TRUE(runner, StrIter_Ends_With(end, wanted), "Ends_With");
 
         DECREF(wanted);
         DECREF(substring);
@@ -489,7 +490,7 @@ test_iterator_substring(TestBatchRunner *runner) {
 
 void
 TestStr_Run_IMP(TestString *self, TestBatchRunner *runner) {
-    TestBatchRunner_Plan(runner, (TestBatch*)self, 104);
+    TestBatchRunner_Plan(runner, (TestBatch*)self, 105);
     test_Cat(runner);
     test_Mimic_and_Clone(runner);
     test_Code_Point_At_and_From(runner);


Mime
View raw message