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/07 18:53:22 UTC
[lucy-commits] [01/20] git commit: refs/heads/cfish-string-prep1 - Allow NULL
arguments to StrIter_substring
Updated Branches:
refs/heads/cfish-string-prep1 1f51cae0f -> ee3c8ed8f
Allow NULL arguments to StrIter_substring
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/e3a2f928
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/e3a2f928
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/e3a2f928
Branch: refs/heads/cfish-string-prep1
Commit: e3a2f9280851e957f678752300a98595236eec02
Parents: 0d0cb67
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Sep 7 12:39:22 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Sep 7 18:12:45 2013 +0200
----------------------------------------------------------------------
clownfish/runtime/core/Clownfish/String.c | 39 +++++++++++++++-----
clownfish/runtime/core/Clownfish/String.cfh | 4 +-
.../runtime/core/Clownfish/Test/TestString.c | 20 +++++++++-
3 files changed, 51 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/e3a2f928/clownfish/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.c b/clownfish/runtime/core/Clownfish/String.c
index 01a7939..ce10b7f 100644
--- a/clownfish/runtime/core/Clownfish/String.c
+++ b/clownfish/runtime/core/Clownfish/String.c
@@ -790,20 +790,41 @@ StrIter_new(String *string, size_t byte_offset) {
String*
StrIter_substring(StringIterator *top, StringIterator *tail) {
- String *string = top->string;
+ String *string;
+ size_t top_offset;
+ size_t tail_offset;
- if (string != tail->string) {
- THROW(ERR, "StrIter_substring: strings don't match");
+ if (tail == NULL) {
+ if (top == NULL) {
+ THROW(ERR, "StrIter_substring: Both top and tail are NULL");
+ }
+ string = top->string;
+ tail_offset = string->size;
+ }
+ else {
+ string = tail->string;
+ if (top != NULL && string != top->string) {
+ THROW(ERR, "StrIter_substring: strings don't match");
+ }
+
+ tail_offset = tail->byte_offset;
+ if (tail_offset > string->size) {
+ THROW(ERR, "Invalid StringIterator offset");
+ }
}
- if (top->byte_offset > tail->byte_offset) {
- THROW(ERR, "StrIter_substring: top is behind tail");
+
+ if (top == NULL) {
+ top_offset = 0;
}
- if (tail->byte_offset > string->size) {
- THROW(ERR, "Invalid StringIterator offset");
+ else {
+ top_offset = top->byte_offset;
+ if (top_offset > tail_offset) {
+ THROW(ERR, "StrIter_substring: top is behind tail");
+ }
}
- return Str_new_from_trusted_utf8(string->ptr + top->byte_offset,
- tail->byte_offset - top->byte_offset);
+ return Str_new_from_trusted_utf8(string->ptr + top_offset,
+ tail_offset - top_offset);
}
StringIterator*
http://git-wip-us.apache.org/repos/asf/lucy/blob/e3a2f928/clownfish/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.cfh b/clownfish/runtime/core/Clownfish/String.cfh
index bf9a4a9..b49d957 100644
--- a/clownfish/runtime/core/Clownfish/String.cfh
+++ b/clownfish/runtime/core/Clownfish/String.cfh
@@ -386,8 +386,8 @@ class Clownfish::StringIterator cnick StrIter
new(String *string, size_t byte_offset);
/** Return the substring between the top and tail iterators.
- * @param offset Offset from the top, in code points.
- * @param len The desired length of the substring, in code points.
+ * @param offset Top iterator. Use start of string if NULL.
+ * @param len Tail iterator. Use end of string if NULL.
*/
inert incremented String*
substring(StringIterator *top, StringIterator *tail);
http://git-wip-us.apache.org/repos/asf/lucy/blob/e3a2f928/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 4b937f8..df04794 100644
--- a/clownfish/runtime/core/Clownfish/Test/TestString.c
+++ b/clownfish/runtime/core/Clownfish/Test/TestString.c
@@ -464,6 +464,24 @@ test_iterator_substring(TestBatchRunner *runner) {
DECREF(substring);
}
+ {
+ String *substring = StrIter_substring(end, NULL);
+ String *wanted = Str_newf("%sd", smiley);
+ TEST_TRUE(runner, Str_Equals(substring, (Obj*)wanted),
+ "StrIter_substring with NULL tail");
+ DECREF(wanted);
+ DECREF(substring);
+ }
+
+ {
+ String *substring = StrIter_substring(NULL, start);
+ String *wanted = Str_newf("a%s", smiley);
+ TEST_TRUE(runner, Str_Equals(substring, (Obj*)wanted),
+ "StrIter_substring with NULL top");
+ DECREF(wanted);
+ DECREF(substring);
+ }
+
DECREF(start);
DECREF(end);
DECREF(string);
@@ -471,7 +489,7 @@ test_iterator_substring(TestBatchRunner *runner) {
void
TestStr_Run_IMP(TestString *self, TestBatchRunner *runner) {
- TestBatchRunner_Plan(runner, (TestBatch*)self, 102);
+ TestBatchRunner_Plan(runner, (TestBatch*)self, 104);
test_Cat(runner);
test_Mimic_and_Clone(runner);
test_Code_Point_At_and_From(runner);
[lucy-commits] [15/20] git commit: refs/heads/cfish-string-prep1 - Convert
Store::SharedLock to StringIterator
Posted by nw...@apache.org.
Convert Store::SharedLock to StringIterator
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/430ba969
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/430ba969
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/430ba969
Branch: refs/heads/cfish-string-prep1
Commit: 430ba969d64f96003ba6f16cc1be011e0076b785
Parents: 07945bd
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Sep 7 16:56:44 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Sep 7 18:14:05 2013 +0200
----------------------------------------------------------------------
core/Lucy/Store/SharedLock.c | 36 ++++++++++++++++++++++--------------
1 file changed, 22 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/430ba969/core/Lucy/Store/SharedLock.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/SharedLock.c b/core/Lucy/Store/SharedLock.c
index a49b661..7ff1fc6 100644
--- a/core/Lucy/Store/SharedLock.c
+++ b/core/Lucy/Store/SharedLock.c
@@ -138,22 +138,30 @@ ShLock_Is_Locked_IMP(SharedLock *self) {
while (DH_Next(dh)) {
String *entry = DH_Get_Entry(dh);
// Translation: $locked = 1 if $entry =~ /^\Q$name-\d+\.lock$/
- if (Str_Starts_With(entry, ivars->name)
- && Str_Ends_With_Str(entry, ".lock", 5)
- ) {
- StackString *scratch = SSTR_WRAP(entry);
- SStr_Chop(scratch, sizeof(".lock") - 1);
- while (isdigit(SStr_Code_Point_From(scratch, 1))) {
- SStr_Chop(scratch, 1);
- }
- if (SStr_Code_Point_From(scratch, 1) == '-') {
- SStr_Chop(scratch, 1);
- if (SStr_Equals(scratch, (Obj*)ivars->name)) {
- DECREF(entry);
- DECREF(dh);
- return true;
+ if (Str_Starts_With(entry, ivars->name)) {
+ StringIterator *iter = Str_Top(entry);
+ StrIter_Advance(iter, Str_Length(ivars->name));
+ uint32_t code_point = StrIter_Next(iter);
+ if (code_point == '-') {
+ code_point = StrIter_Next(iter);
+ if (code_point != STRITER_DONE && isdigit(code_point)) {
+ while (STRITER_DONE != (code_point = StrIter_Next(iter))) {
+ if (!isdigit(code_point)) { break; }
+ }
+ if (code_point == '.'
+ && StrIter_Starts_With_UTF8(iter, "lock", 4)
+ ) {
+ StrIter_Advance(iter, 4);
+ if (!StrIter_Has_Next(iter)) {
+ DECREF(iter);
+ DECREF(entry);
+ DECREF(dh);
+ return true;
+ }
+ }
}
}
+ DECREF(iter);
}
DECREF(entry);
}
[lucy-commits] [17/20] git commit: refs/heads/cfish-string-prep1 - Convert
Store::Folder to StringIterator
Posted by nw...@apache.org.
Convert Store::Folder to StringIterator
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/a3d2e27c
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/a3d2e27c
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/a3d2e27c
Branch: refs/heads/cfish-string-prep1
Commit: a3d2e27cb52346b30b630be93f589d91e814d485
Parents: a0efa07
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Sep 7 15:59:03 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Sep 7 18:14:05 2013 +0200
----------------------------------------------------------------------
core/Lucy/Store/Folder.c | 51 ++++++++++++++++++++++---------------------
1 file changed, 26 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/a3d2e27c/core/Lucy/Store/Folder.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/Folder.c b/core/Lucy/Store/Folder.c
index 4a97db2..066d20e 100644
--- a/core/Lucy/Store/Folder.c
+++ b/core/Lucy/Store/Folder.c
@@ -423,30 +423,28 @@ Folder_Consolidate_IMP(Folder *self, const String *path) {
}
static Folder*
-S_enclosing_folder(Folder *self, StackString *path) {
- size_t path_component_len = 0;
+S_enclosing_folder(Folder *self, StringIterator *path) {
uint32_t code_point;
- // Strip trailing slash.
- if (SStr_Code_Point_From(path, 0) == '/') { SStr_Chop(path, 1); }
-
// Find first component of the file path.
- StackString *scratch = SSTR_WRAP((String*)path);
- StackString *path_component = SSTR_WRAP((String*)path);
- while (0 != (code_point = SStr_Nibble(scratch))) {
- if (code_point == '/') {
- SStr_Truncate(path_component, path_component_len);
- SStr_Nip(path, path_component_len + 1);
+ String *path_component = NULL;
+ StringIterator *iter = StrIter_Clone(path);
+ while (STRITER_DONE != (code_point = StrIter_Next(iter))) {
+ if (code_point == '/' && StrIter_Has_Next(iter)) {
+ StrIter_Recede(iter, 1);
+ path_component = StrIter_substring(path, iter);
+ StrIter_Advance(iter, 1);
+ StrIter_Assign(path, iter);
break;
}
- path_component_len++;
}
+ DECREF(iter);
// If we've eaten up the entire filepath, self is enclosing folder.
- if (SStr_Get_Size(scratch) == 0) { return self; }
+ if (!path_component) { return self; }
- Folder *local_folder
- = Folder_Local_Find_Folder(self, (String*)path_component);
+ Folder *local_folder = Folder_Local_Find_Folder(self, path_component);
+ DECREF(path_component);
if (!local_folder) {
/* This element of the filepath doesn't exist, or it's not a
* directory. However, there are filepath characters left over,
@@ -461,8 +459,10 @@ S_enclosing_folder(Folder *self, StackString *path) {
Folder*
Folder_Enclosing_Folder_IMP(Folder *self, const String *path) {
- StackString *scratch = SSTR_WRAP(path);
- return S_enclosing_folder(self, scratch);
+ StringIterator *iter = Str_Top(path);
+ Folder *folder = S_enclosing_folder(self, iter);
+ DECREF(iter);
+ return folder;
}
Folder*
@@ -471,15 +471,16 @@ Folder_Find_Folder_IMP(Folder *self, const String *path) {
return self;
}
else {
- StackString *scratch = SSTR_WRAP(path);
- Folder *enclosing_folder = S_enclosing_folder(self, scratch);
- if (!enclosing_folder) {
- return NULL;
- }
- else {
- return Folder_Local_Find_Folder(enclosing_folder,
- (String*)scratch);
+ Folder *folder = NULL;
+ StringIterator *iter = Str_Top(path);
+ Folder *enclosing_folder = S_enclosing_folder(self, iter);
+ if (enclosing_folder) {
+ String *folder_name = StrIter_substring(iter, NULL);
+ folder = Folder_Local_Find_Folder(enclosing_folder, folder_name);
+ DECREF(folder_name);
}
+ DECREF(iter);
+ return folder;
}
}
[lucy-commits] [19/20] git commit: refs/heads/cfish-string-prep1 - Convert
Clownfish::VTable to StringIterator
Posted by nw...@apache.org.
Convert Clownfish::VTable to StringIterator
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/fed2b10a
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/fed2b10a
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/fed2b10a
Branch: refs/heads/cfish-string-prep1
Commit: fed2b10a3761d3d82bd6f392675670bc50b2e8b5
Parents: d7ed091
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Sep 7 18:06:54 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Sep 7 18:14:05 2013 +0200
----------------------------------------------------------------------
clownfish/runtime/core/Clownfish/VTable.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/fed2b10a/clownfish/runtime/core/Clownfish/VTable.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/VTable.c b/clownfish/runtime/core/Clownfish/VTable.c
index 30ddea2..92ee50a 100644
--- a/clownfish/runtime/core/Clownfish/VTable.c
+++ b/clownfish/runtime/core/Clownfish/VTable.c
@@ -328,9 +328,9 @@ VTable_singleton(const String *class_name, VTable *parent) {
static String*
S_scrunch_string(String *source) {
CharBuf *buf = CB_new(Str_Get_Size(source));
- StackString *iterator = SSTR_WRAP(source);
- while (SStr_Get_Size(iterator)) {
- uint32_t code_point = SStr_Nibble(iterator);
+ StringIterator *iter = Str_Top(source);
+ uint32_t code_point;
+ while (STRITER_DONE != (code_point = StrIter_Next(iter))) {
if (code_point > 127) {
THROW(ERR, "Can't fold case for %o", source);
}
@@ -339,6 +339,7 @@ S_scrunch_string(String *source) {
}
}
String *retval = CB_Yield_String(buf);
+ DECREF(iter);
DECREF(buf);
return retval;
}
[lucy-commits] [07/20] git commit: refs/heads/cfish-string-prep1 - Eliminate
SStr_Chop in IndexManager
Posted by nw...@apache.org.
Eliminate SStr_Chop in IndexManager
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/f374f95b
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/f374f95b
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/f374f95b
Branch: refs/heads/cfish-string-prep1
Commit: f374f95b57fe279ec688d8f7318b6d75c407fbd4
Parents: 414375f
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Sep 7 14:41:51 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Sep 7 18:14:04 2013 +0200
----------------------------------------------------------------------
core/Lucy/Index/IndexManager.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/f374f95b/core/Lucy/Index/IndexManager.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/IndexManager.c b/core/Lucy/Index/IndexManager.c
index e2a8009..b1b29b4 100644
--- a/core/Lucy/Index/IndexManager.c
+++ b/core/Lucy/Index/IndexManager.c
@@ -304,7 +304,6 @@ IxManager_Remove_Merge_Data_IMP(IndexManager *self) {
Lock*
IxManager_Make_Snapshot_Read_Lock_IMP(IndexManager *self,
const String *filename) {
- StackString *lock_name = SSTR_WRAP(filename);
LockFactory *lock_factory = S_obtain_lock_factory(self);
if (!Str_Starts_With_Str(filename, "snapshot_", 9)
@@ -314,9 +313,13 @@ IxManager_Make_Snapshot_Read_Lock_IMP(IndexManager *self,
}
// Truncate ".json" from end of snapshot file name.
- SStr_Chop(lock_name, sizeof(".json") - 1);
+ size_t lock_name_len = Str_Length(filename) - (sizeof(".json") - 1);
+ String *lock_name = Str_SubString(filename, 0, lock_name_len);
- return LockFact_Make_Shared_Lock(lock_factory, (String*)lock_name, 1000, 100);
+ Lock *lock = LockFact_Make_Shared_Lock(lock_factory, lock_name, 1000, 100);
+
+ DECREF(lock_name);
+ return lock;
}
void
[lucy-commits] [05/20] git commit: refs/heads/cfish-string-prep1 - Convert
QueryLexer to StringIterator
Posted by nw...@apache.org.
Convert QueryLexer to StringIterator
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/414375fc
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/414375fc
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/414375fc
Branch: refs/heads/cfish-string-prep1
Commit: 414375fcbdf66f2210db385c21ef7e21f331f500
Parents: 153446a
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Sep 7 14:29:48 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Sep 7 18:14:04 2013 +0200
----------------------------------------------------------------------
core/Lucy/Search/QueryParser/QueryLexer.c | 176 +++++++++++++------------
1 file changed, 92 insertions(+), 84 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/414375fc/core/Lucy/Search/QueryParser/QueryLexer.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/QueryParser/QueryLexer.c b/core/Lucy/Search/QueryParser/QueryLexer.c
index df2f965..1073e98 100644
--- a/core/Lucy/Search/QueryParser/QueryLexer.c
+++ b/core/Lucy/Search/QueryParser/QueryLexer.c
@@ -35,17 +35,17 @@
#define TOKEN_QUERY LUCY_QPARSER_TOKEN_QUERY
static ParserElem*
-S_consume_keyword(StackString *qstring, const char *keyword,
+S_consume_keyword(StringIterator *iter, const char *keyword,
size_t keyword_len, int type);
static ParserElem*
-S_consume_field(StackString *qstring);
+S_consume_field(StringIterator *iter);
static ParserElem*
-S_consume_text(StackString *qstring);
+S_consume_text(StringIterator *iter);
static ParserElem*
-S_consume_quoted_string(StackString *qstring);
+S_consume_quoted_string(StringIterator *iter);
QueryLexer*
QueryLexer_new() {
@@ -73,101 +73,103 @@ QueryLexer_Set_Heed_Colons_IMP(QueryLexer *self, bool heed_colons) {
VArray*
QueryLexer_Tokenize_IMP(QueryLexer *self, const String *query_string) {
QueryLexerIVARS *const ivars = QueryLexer_IVARS(self);
- String *copy = query_string
- ? Str_Clone(query_string)
- : Str_new_from_trusted_utf8("", 0);
- StackString *qstring = SSTR_WRAP((String*)copy);
+
VArray *elems = VA_new(0);
- SStr_Trim(qstring);
+ if (!query_string) { return elems; }
+
+ StringIterator *iter = Str_Top(query_string);
- while (SStr_Get_Size(qstring)) {
+ while (StrIter_Has_Next(iter)) {
ParserElem *elem = NULL;
- if (SStr_Trim_Top(qstring)) {
+ if (StrIter_Skip_Next_Whitespace(iter)) {
// Fast-forward past whitespace.
continue;
}
if (ivars->heed_colons) {
- ParserElem *elem = S_consume_field(qstring);
+ ParserElem *elem = S_consume_field(iter);
if (elem) {
VA_Push(elems, (Obj*)elem);
}
}
- uint32_t code_point = SStr_Code_Point_At(qstring, 0);
+ uint32_t code_point = StrIter_Next(iter);
switch (code_point) {
case '(':
- SStr_Nip(qstring, 1);
elem = ParserElem_new(TOKEN_OPEN_PAREN, NULL);
break;
case ')':
- SStr_Nip(qstring, 1);
elem = ParserElem_new(TOKEN_CLOSE_PAREN, NULL);
break;
case '+':
- if (SStr_Get_Size(qstring) > 1
- && !StrHelp_is_whitespace(SStr_Code_Point_At(qstring, 1))
+ if (StrIter_Has_Next(iter)
+ && !StrIter_Skip_Next_Whitespace(iter)
) {
elem = ParserElem_new(TOKEN_PLUS, NULL);
}
else {
elem = ParserElem_new(TOKEN_STRING, (Obj*)Str_newf("+"));
}
- SStr_Nip(qstring, 1);
break;
case '-':
- if (SStr_Get_Size(qstring) > 1
- && !StrHelp_is_whitespace(SStr_Code_Point_At(qstring, 1))
+ if (StrIter_Has_Next(iter)
+ && !StrIter_Skip_Next_Whitespace(iter)
) {
elem = ParserElem_new(TOKEN_MINUS, NULL);
}
else {
elem = ParserElem_new(TOKEN_STRING, (Obj*)Str_newf("-"));
}
- SStr_Nip(qstring, 1);
break;
case '"':
- elem = S_consume_quoted_string(qstring);
+ StrIter_Recede(iter, 1);
+ elem = S_consume_quoted_string(iter);
break;
case 'O':
- elem = S_consume_keyword(qstring, "OR", 2, TOKEN_OR);
+ StrIter_Recede(iter, 1);
+ elem = S_consume_keyword(iter, "OR", 2, TOKEN_OR);
if (!elem) {
- elem = S_consume_text(qstring);
+ elem = S_consume_text(iter);
}
break;
case 'A':
- elem = S_consume_keyword(qstring, "AND", 3, TOKEN_AND);
+ StrIter_Recede(iter, 1);
+ elem = S_consume_keyword(iter, "AND", 3, TOKEN_AND);
if (!elem) {
- elem = S_consume_text(qstring);
+ elem = S_consume_text(iter);
}
break;
case 'N':
- elem = S_consume_keyword(qstring, "NOT", 3, TOKEN_NOT);
+ StrIter_Recede(iter, 1);
+ elem = S_consume_keyword(iter, "NOT", 3, TOKEN_NOT);
if (!elem) {
- elem = S_consume_text(qstring);
+ elem = S_consume_text(iter);
}
break;
default:
- elem = S_consume_text(qstring);
+ StrIter_Recede(iter, 1);
+ elem = S_consume_text(iter);
break;
}
VA_Push(elems, (Obj*)elem);
}
- DECREF(copy);
return elems;
}
static ParserElem*
-S_consume_keyword(StackString *qstring, const char *keyword,
+S_consume_keyword(StringIterator *iter, const char *keyword,
size_t keyword_len, int type) {
- if (!SStr_Starts_With_Str(qstring, keyword, keyword_len)) {
+ if (!StrIter_Starts_With_UTF8(iter, keyword, keyword_len)) {
return NULL;
}
- uint32_t lookahead = SStr_Code_Point_At(qstring, keyword_len);
- if (!lookahead) {
+ StringIterator *temp = StrIter_Clone(iter);
+ StrIter_Advance(temp, keyword_len);
+ uint32_t lookahead = StrIter_Next(temp);
+ if (lookahead == STRITER_DONE) {
+ DECREF(temp);
return NULL;
}
if (StrHelp_is_whitespace(lookahead)
@@ -177,42 +179,48 @@ S_consume_keyword(StackString *qstring, const char *keyword,
|| lookahead == '+'
|| lookahead == '-'
) {
- SStr_Nip(qstring, keyword_len);
+ StrIter_Recede(temp, 1);
+ StrIter_Assign(iter, temp);
+ DECREF(temp);
return ParserElem_new(type, NULL);
}
+ DECREF(temp);
return NULL;
}
static ParserElem*
-S_consume_field(StackString *qstring) {
- size_t tick = 0;
+S_consume_field(StringIterator *iter) {
+ StringIterator *temp = StrIter_Clone(iter);
// Field names constructs must start with a letter or underscore.
- uint32_t code_point = SStr_Code_Point_At(qstring, tick);
- if (isalpha(code_point) || code_point == '_') {
- tick++;
+ uint32_t code_point = StrIter_Next(temp);
+ if (code_point == STRITER_DONE) {
+ DECREF(temp);
+ return NULL;
}
- else {
+ if (!(isalpha(code_point) || code_point == '_')) {
+ DECREF(temp);
return NULL;
}
- // Only alphanumerics and underscores are allowed in field names.
- while (1) {
- code_point = SStr_Code_Point_At(qstring, tick);
- if (isalnum(code_point) || code_point == '_') {
- tick++;
- }
- else if (code_point == ':') {
- tick++;
- break;
+ // Only alphanumerics and underscores are allowed in field names.
+ while (':' != (code_point = StrIter_Next(temp))) {
+ if (code_point == STRITER_DONE) {
+ DECREF(temp);
+ return NULL;
}
- else {
+ if (!(isalnum(code_point) || code_point != '_')) {
+ DECREF(temp);
return NULL;
}
}
// Field name constructs must be followed by something sensible.
- uint32_t lookahead = SStr_Code_Point_At(qstring, tick);
+ uint32_t lookahead = StrIter_Next(temp);
+ if (lookahead == STRITER_DONE) {
+ DECREF(temp);
+ return NULL;
+ }
if (!(isalnum(lookahead)
|| lookahead == '_'
|| lookahead > 127
@@ -220,71 +228,71 @@ S_consume_field(StackString *qstring) {
|| lookahead == '('
)
) {
+ DECREF(temp);
return NULL;
}
// Consume string data.
- StackString *field = SSTR_WRAP((String*)qstring);
- SStr_Truncate(field, tick - 1);
- SStr_Nip(qstring, tick);
- return ParserElem_new(TOKEN_FIELD, (Obj*)SStr_Clone(field));
+ StrIter_Recede(temp, 2); // Back up over lookahead and colon.
+ String *field = StrIter_substring(iter, temp);
+ StrIter_Advance(temp, 1); // Skip colon.
+ StrIter_Assign(iter, temp);
+ DECREF(temp);
+ return ParserElem_new(TOKEN_FIELD, (Obj*)field);
}
static ParserElem*
-S_consume_text(StackString *qstring) {
- StackString *text = SSTR_WRAP((String*)qstring);
- size_t tick = 0;
+S_consume_text(StringIterator *iter) {
+ StringIterator *temp = StrIter_Clone(iter);
+
while (1) {
- uint32_t code_point = SStr_Nibble(qstring);
+ uint32_t code_point = StrIter_Next(temp);
if (code_point == '\\') {
- code_point = SStr_Nibble(qstring);
- tick++;
- if (code_point == 0) {
+ code_point = StrIter_Next(temp);
+ if (code_point == STRITER_DONE) {
break;
}
}
+ else if (code_point == STRITER_DONE) {
+ break;
+ }
else if (StrHelp_is_whitespace(code_point)
|| code_point == '"'
|| code_point == '('
|| code_point == ')'
- || code_point == 0
) {
+ StrIter_Recede(temp, 1);
break;
}
- tick++;
}
- SStr_Truncate(text, tick);
- return ParserElem_new(TOKEN_STRING, (Obj*)SStr_Clone(text));
+ String *text = StrIter_substring(iter, temp);
+ StrIter_Assign(iter, temp);
+ DECREF(temp);
+ return ParserElem_new(TOKEN_STRING, (Obj*)text);
}
static ParserElem*
-S_consume_quoted_string(StackString *qstring) {
- StackString *text = SSTR_WRAP((String*)qstring);
- if (SStr_Nibble(qstring) != '"') {
+S_consume_quoted_string(StringIterator *iter) {
+ StringIterator *temp = StrIter_Clone(iter);
+
+ if (StrIter_Next(temp) != '"') {
THROW(ERR, "Internal error: expected a quote");
}
- size_t tick = 1;
while (1) {
- uint32_t code_point = SStr_Nibble(qstring);
- if (code_point == '"') {
- tick += 1;
- break;
- }
- else if (code_point == 0) {
+ uint32_t code_point = StrIter_Next(temp);
+ if (code_point == STRITER_DONE || code_point == '"') {
break;
}
else if (code_point == '\\') {
- SStr_Nibble(qstring);
- tick += 2;
- }
- else {
- tick += 1;
+ StrIter_Next(temp);
}
}
- SStr_Truncate(text, tick);
- return ParserElem_new(TOKEN_STRING, (Obj*)SStr_Clone(text));
+ String *text = StrIter_substring(iter, temp);
+ StrIter_Assign(iter, temp);
+ DECREF(temp);
+ return ParserElem_new(TOKEN_STRING, (Obj*)text);
}
[lucy-commits] [06/20] git commit: refs/heads/cfish-string-prep1 - Convert rest of
Highlighter to StringIterators
Posted by nw...@apache.org.
Convert rest of Highlighter to StringIterators
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/153446a0
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/153446a0
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/153446a0
Branch: refs/heads/cfish-string-prep1
Commit: 153446a0450dbb7427cd3a0989e0f257af143201
Parents: cc66dbe
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Sep 7 12:46:54 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Sep 7 18:14:04 2013 +0200
----------------------------------------------------------------------
core/Lucy/Highlight/Highlighter.c | 59 +++++++++++++++++++---------------
1 file changed, 33 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/153446a0/core/Lucy/Highlight/Highlighter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Highlight/Highlighter.c b/core/Lucy/Highlight/Highlighter.c
index dc2f0a3..5a7f13f 100644
--- a/core/Lucy/Highlight/Highlighter.c
+++ b/core/Lucy/Highlight/Highlighter.c
@@ -466,12 +466,13 @@ Highlighter_Raw_Excerpt_IMP(Highlighter *self, const String *field_val,
String*
Highlighter_Highlight_Excerpt_IMP(Highlighter *self, VArray *spans,
String *raw_excerpt, int32_t top) {
- int32_t hl_start = 0;
- int32_t hl_end = 0;
- StackString *temp = SSTR_WRAP(raw_excerpt);
- CharBuf *buf = CB_new(Str_Get_Size(raw_excerpt) + 32);
- CharBuf *encode_buf = NULL;
- int32_t raw_excerpt_end = top + Str_Length(raw_excerpt);
+ int32_t hl_start = 0;
+ int32_t hl_end = 0;
+ StringIterator *iter = Str_Top(raw_excerpt);
+ StringIterator *temp = Str_Top(raw_excerpt);
+ CharBuf *buf = CB_new(Str_Get_Size(raw_excerpt) + 32);
+ CharBuf *encode_buf = NULL;
+ int32_t raw_excerpt_end = top + Str_Length(raw_excerpt);
for (uint32_t i = 0, max = VA_Get_Size(spans); i < max; i++) {
Span *span = (Span*)VA_Fetch(spans, i);
@@ -492,28 +493,28 @@ Highlighter_Highlight_Excerpt_IMP(Highlighter *self, VArray *spans,
}
}
else {
- String *encoded;
-
if (hl_start < hl_end) {
// Highlight previous section
int32_t highlighted_len = hl_end - hl_start;
- StackString *to_cat = SSTR_WRAP((String*)temp);
- SStr_Truncate(to_cat, highlighted_len);
- encoded = S_do_encode(self, (String*)to_cat, &encode_buf);
+ StrIter_Assign(temp, iter);
+ StrIter_Advance(iter, highlighted_len);
+ String *to_cat = StrIter_substring(temp, iter);
+ String *encoded = S_do_encode(self, to_cat, &encode_buf);
String *hl_frag = Highlighter_Highlight(self, encoded);
CB_Cat(buf, hl_frag);
- SStr_Nip(temp, highlighted_len);
DECREF(hl_frag);
DECREF(encoded);
+ DECREF(to_cat);
}
int32_t non_highlighted_len = relative_start - hl_end;
- StackString *to_cat = SSTR_WRAP((String*)temp);
- SStr_Truncate(to_cat, non_highlighted_len);
- encoded = S_do_encode(self, (String*)to_cat, &encode_buf);
+ StrIter_Assign(temp, iter);
+ StrIter_Advance(iter, non_highlighted_len);
+ String *to_cat = StrIter_substring(temp, iter);
+ String *encoded = S_do_encode(self, to_cat, &encode_buf);
CB_Cat(buf, (String*)encoded);
- SStr_Nip(temp, non_highlighted_len);
DECREF(encoded);
+ DECREF(to_cat);
hl_start = relative_start;
hl_end = relative_end;
@@ -524,26 +525,30 @@ Highlighter_Highlight_Excerpt_IMP(Highlighter *self, VArray *spans,
if (hl_start < hl_end) {
// Highlight final section
int32_t highlighted_len = hl_end - hl_start;
- StackString *to_cat = SSTR_WRAP((String*)temp);
- SStr_Truncate(to_cat, highlighted_len);
- String *encoded = S_do_encode(self, (String*)to_cat, &encode_buf);
+ StrIter_Assign(temp, iter);
+ StrIter_Advance(iter, highlighted_len);
+ String *to_cat = StrIter_substring(temp, iter);
+ String *encoded = S_do_encode(self, to_cat, &encode_buf);
String *hl_frag = Highlighter_Highlight(self, encoded);
CB_Cat(buf, hl_frag);
- SStr_Nip(temp, highlighted_len);
DECREF(hl_frag);
DECREF(encoded);
}
// Last text, beyond last highlight span.
- if (SStr_Get_Size(temp)) {
- String *encoded = S_do_encode(self, (String*)temp, &encode_buf);
+ if (StrIter_Has_Next(iter)) {
+ String *to_cat = StrIter_substring(iter, NULL);
+ String *encoded = S_do_encode(self, to_cat, &encode_buf);
CB_Cat(buf, encoded);
DECREF(encoded);
+ DECREF(to_cat);
}
String *highlighted = CB_Yield_String(buf);
DECREF(encode_buf);
DECREF(buf);
+ DECREF(temp);
+ DECREF(iter);
return highlighted;
}
@@ -575,13 +580,13 @@ S_do_encode(Highlighter *self, String *text, CharBuf **encode_buf) {
static String*
S_encode_entities(String *text, CharBuf *buf) {
- StackString *temp = SSTR_WRAP(text);
+ StringIterator *iter = Str_Top(text);
size_t space = 0;
const int MAX_ENTITY_BYTES = 9; // &#dddddd;
// Scan first so that we only allocate once.
uint32_t code_point;
- while (0 != (code_point = SStr_Nibble(temp))) {
+ while (STRITER_DONE != (code_point = StrIter_Next(iter))) {
if (code_point > 127
|| (!isgraph(code_point) && !isspace(code_point))
|| code_point == '<'
@@ -598,8 +603,9 @@ S_encode_entities(String *text, CharBuf *buf) {
CB_Grow(buf, space);
CB_Set_Size(buf, 0);
- SStr_Assign(temp, text);
- while (0 != (code_point = SStr_Nibble(temp))) {
+ DECREF(iter);
+ iter = Str_Top(text);
+ while (STRITER_DONE != (code_point = StrIter_Next(iter))) {
if (code_point > 127
|| (!isgraph(code_point) && !isspace(code_point))
) {
@@ -622,6 +628,7 @@ S_encode_entities(String *text, CharBuf *buf) {
}
}
+ DECREF(iter);
return CB_To_String(buf);
}
[lucy-commits] [18/20] git commit: refs/heads/cfish-string-prep1 - Remove String
methods Nip, Nibble, Chop, and Truncate
Posted by nw...@apache.org.
Remove String methods Nip, Nibble, Chop, and Truncate
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/ee3c8ed8
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/ee3c8ed8
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/ee3c8ed8
Branch: refs/heads/cfish-string-prep1
Commit: ee3c8ed8f7703e449f4527f52b08f8342f785777
Parents: fed2b10
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Sep 7 18:10:48 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Sep 7 18:14:05 2013 +0200
----------------------------------------------------------------------
clownfish/runtime/core/Clownfish/String.c | 58 --------------------
clownfish/runtime/core/Clownfish/String.cfh | 27 ---------
.../runtime/core/Clownfish/Test/TestString.c | 38 +------------
3 files changed, 1 insertion(+), 122 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/ee3c8ed8/clownfish/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.c b/clownfish/runtime/core/Clownfish/String.c
index c87864a..d1d36d1 100644
--- a/clownfish/runtime/core/Clownfish/String.c
+++ b/clownfish/runtime/core/Clownfish/String.c
@@ -484,15 +484,6 @@ Str_Length_IMP(String *self) {
return SStrIter_Advance(iter, SIZE_MAX);
}
-size_t
-Str_Truncate_IMP(String *self, size_t count) {
- uint32_t num_code_points;
- StackString *iterator = SSTR_WRAP(self);
- num_code_points = SStr_Nip(iterator, count);
- self->size -= iterator->size;
- return num_code_points;
-}
-
uint32_t
Str_Code_Point_At_IMP(String *self, size_t tick) {
StackStringIterator *iter = STR_STACKTOP(self);
@@ -666,55 +657,6 @@ ViewCB_Trim_Top_IMP(ViewCharBuf *self) {
return count;
}
-size_t
-ViewCB_Nip_IMP(ViewCharBuf *self, size_t count) {
- size_t num_nipped;
- char *ptr = self->ptr;
- char *end = ptr + self->size;
- for (num_nipped = 0;
- ptr < end && count--;
- ptr += StrHelp_UTF8_COUNT[*(uint8_t*)ptr]
- ) {
- num_nipped++;
- }
- if (ptr > end) {
- DIE_INVALID_UTF8(self->ptr, self->size);
- }
- self->size = end - ptr;
- self->ptr = ptr;
- return num_nipped;
-}
-
-int32_t
-ViewCB_Nibble_IMP(ViewCharBuf *self) {
- if (self->size == 0) {
- return 0;
- }
- else {
- int32_t retval = (int32_t)StrHelp_decode_utf8_char(self->ptr);
- size_t consumed = StrHelp_UTF8_COUNT[*(uint8_t*)self->ptr];
- if (consumed > self->size) {
- DIE_INVALID_UTF8(self->ptr, self->size);
- }
- self->ptr += consumed;
- self->size -= consumed;
- return retval;
- }
-}
-
-size_t
-ViewCB_Chop_IMP(ViewCharBuf *self, size_t count) {
- size_t num_chopped = 0;
- char *top = self->ptr;
- const char *ptr = top + self->size;
- for (num_chopped = 0; num_chopped < count; num_chopped++) {
- const char *end = ptr;
- if (NULL == (ptr = StrHelp_back_utf8_char(ptr, top))) { break; }
- self->size -= (end - ptr);
- }
- return num_chopped;
-}
-
char*
ViewCB_Grow_IMP(ViewCharBuf *self, size_t size) {
UNUSED_VAR(size);
http://git-wip-us.apache.org/repos/asf/lucy/blob/ee3c8ed8/clownfish/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.cfh b/clownfish/runtime/core/Clownfish/String.cfh
index d8e32dd..bf56e22 100644
--- a/clownfish/runtime/core/Clownfish/String.cfh
+++ b/clownfish/runtime/core/Clownfish/String.cfh
@@ -239,15 +239,6 @@ class Clownfish::String cnick Str
uint32_t
Trim_Tail(String *self);
- /** Truncate the String so that it contains no more than
- * <code>count</code>characters.
- *
- * @param count Maximum new length, in Unicode code points.
- * @return The number of code points left in the string after truncation.
- */
- size_t
- Truncate(String *self, size_t count);
-
/** Return the Unicode code point at the specified number of code points
* in. Return 0 if the string length is exceeded. (XXX It would be
* better to throw an exception, but that's not practical with UTF-8 and
@@ -316,24 +307,6 @@ class Clownfish::ViewCharBuf cnick ViewCB
uint32_t
Trim_Top(ViewCharBuf *self);
- /** Remove characters (measured in code points) from the top of the
- * ViewCharBuf. Returns the number nipped.
- */
- size_t
- Nip(ViewCharBuf *self, size_t count);
-
- /** Remove one character from the top of the ViewCharBuf. Returns the
- * code point, or 0 if the string was empty.
- */
- int32_t
- Nibble(ViewCharBuf *self);
-
- /** Remove characters (measured in code points) from the end of the
- * ViewCharBuf. Returns the number chopped.
- */
- size_t
- Chop(ViewCharBuf *self, size_t count);
-
/** Throws an error. */
char*
Grow(ViewCharBuf *self, size_t size);
http://git-wip-us.apache.org/repos/asf/lucy/blob/ee3c8ed8/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 72f2ecf..75616fd 100644
--- a/clownfish/runtime/core/Clownfish/Test/TestString.c
+++ b/clownfish/runtime/core/Clownfish/Test/TestString.c
@@ -174,40 +174,6 @@ test_SubString(TestBatchRunner *runner) {
}
static void
-test_Nip_and_Chop(TestBatchRunner *runner) {
- String *wanted;
- String *string;
- StackString *got;
-
- wanted = Str_newf("%sb%sc", smiley, smiley);
- string = Str_newf("a%s%sb%sc", smiley, smiley, smiley);
- got = SSTR_WRAP(string);
- SStr_Nip(got, 2);
- TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "Nip");
- DECREF(wanted);
- DECREF(string);
-
- wanted = Str_newf("a%s%s", smiley, smiley);
- string = Str_newf("a%s%sb%sc", smiley, smiley, smiley);
- got = SSTR_WRAP(string);
- SStr_Chop(got, 3);
- TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "Chop");
- DECREF(wanted);
- DECREF(string);
-}
-
-
-static void
-test_Truncate(TestBatchRunner *runner) {
- String *wanted = Str_newf("a%s", smiley, smiley);
- String *got = Str_newf("a%s%sb%sc", smiley, smiley, smiley);
- Str_Truncate(got, 2);
- TEST_TRUE(runner, Str_Equals(wanted, (Obj*)got), "Truncate");
- DECREF(wanted);
- DECREF(got);
-}
-
-static void
test_Trim(TestBatchRunner *runner) {
String *got;
@@ -490,14 +456,12 @@ test_iterator_substring(TestBatchRunner *runner) {
void
TestStr_Run_IMP(TestString *self, TestBatchRunner *runner) {
- TestBatchRunner_Plan(runner, (TestBatch*)self, 105);
+ TestBatchRunner_Plan(runner, (TestBatch*)self, 102);
test_Cat(runner);
test_Mimic_and_Clone(runner);
test_Code_Point_At_and_From(runner);
test_Find(runner);
test_SubString(runner);
- test_Nip_and_Chop(runner);
- test_Truncate(runner);
test_Trim(runner);
test_To_F64(runner);
test_To_I64(runner);
[lucy-commits] [12/20] git commit: refs/heads/cfish-string-prep1 - Eliminate
SStr_Nibble in Store::FSFolder
Posted by nw...@apache.org.
Eliminate SStr_Nibble in Store::FSFolder
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/a0efa07b
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/a0efa07b
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/a0efa07b
Branch: refs/heads/cfish-string-prep1
Commit: a0efa07b6ae32c66161e212155f37459cd1fe747
Parents: fd388fc
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Sep 7 15:27:29 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Sep 7 18:14:05 2013 +0200
----------------------------------------------------------------------
core/Lucy/Store/FSFolder.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/a0efa07b/core/Lucy/Store/FSFolder.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/FSFolder.c b/core/Lucy/Store/FSFolder.c
index f7d777f..e923d33 100644
--- a/core/Lucy/Store/FSFolder.c
+++ b/core/Lucy/Store/FSFolder.c
@@ -297,12 +297,7 @@ S_create_dir(const String *path) {
static bool
S_is_local_entry(const String *path) {
- StackString *scratch = SSTR_WRAP(path);
- uint32_t code_point;
- while (0 != (code_point = SStr_Nibble(scratch))) {
- if (code_point == '/') { return false; }
- }
- return true;
+ return Str_Find_Str(path, "/", 1) == -1;
}
/***************************************************************************/
[lucy-commits] [09/20] git commit: refs/heads/cfish-string-prep1 - Convert
QueryParser to StringIterator
Posted by nw...@apache.org.
Convert QueryParser to StringIterator
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/c7e18751
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/c7e18751
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/c7e18751
Branch: refs/heads/cfish-string-prep1
Commit: c7e187512b3771833ce0091fea052cf350c47d4e
Parents: c56353b
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Sep 7 15:18:42 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Sep 7 18:14:04 2013 +0200
----------------------------------------------------------------------
core/Lucy/Search/QueryParser.c | 52 +++++++++++++++++++++----------------
1 file changed, 30 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/c7e18751/core/Lucy/Search/QueryParser.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/QueryParser.c b/core/Lucy/Search/QueryParser.c
index 0219432..21100d4 100644
--- a/core/Lucy/Search/QueryParser.c
+++ b/core/Lucy/Search/QueryParser.c
@@ -826,16 +826,16 @@ QParser_Expand_IMP(QueryParser *self, Query *query) {
static String*
S_unescape(QueryParser *self, String *orig, CharBuf *buf) {
- StackString *source = SSTR_WRAP(orig);
+ StringIterator *iter = Str_Top(orig);
uint32_t code_point;
UNUSED_VAR(self);
CB_Set_Size(buf, 0);
CB_Grow(buf, Str_Get_Size(orig) + 4);
- while (0 != (code_point = SStr_Nibble(source))) {
+ while (STRITER_DONE != (code_point = StrIter_Next(iter))) {
if (code_point == '\\') {
- uint32_t next_code_point = SStr_Nibble(source);
+ uint32_t next_code_point = StrIter_Next(iter);
if (next_code_point == ':'
|| next_code_point == '"'
|| next_code_point == '\\'
@@ -844,7 +844,9 @@ S_unescape(QueryParser *self, String *orig, CharBuf *buf) {
}
else {
CB_Cat_Char(buf, code_point);
- if (next_code_point) { CB_Cat_Char(buf, next_code_point); }
+ if (next_code_point != STRITER_DONE) {
+ CB_Cat_Char(buf, next_code_point);
+ }
}
}
else {
@@ -852,34 +854,38 @@ S_unescape(QueryParser *self, String *orig, CharBuf *buf) {
}
}
+ DECREF(iter);
return CB_To_String(buf);
}
Query*
QParser_Expand_Leaf_IMP(QueryParser *self, Query *query) {
QueryParserIVARS *const ivars = QParser_IVARS(self);
- LeafQuery *leaf_query = (LeafQuery*)query;
- Schema *schema = ivars->schema;
- StackString *source_text = SStr_BLANK();
- bool is_phrase = false;
- bool ambiguous = false;
+ LeafQuery *leaf_query = (LeafQuery*)query;
+ Schema *schema = ivars->schema;
+ bool is_phrase = false;
+ bool ambiguous = false;
// Determine whether we can actually process the input.
- if (!Query_Is_A(query, LEAFQUERY)) { return NULL; }
- if (!Str_Get_Size(LeafQuery_Get_Text(leaf_query))) { return NULL; }
- SStr_Assign(source_text, LeafQuery_Get_Text(leaf_query));
+ if (!Query_Is_A(query, LEAFQUERY)) { return NULL; }
+ String *full_text = LeafQuery_Get_Text(leaf_query);
+ if (!Str_Get_Size(full_text)) { return NULL; }
// If quoted, always generate PhraseQuery.
- SStr_Trim(source_text);
- if (SStr_Code_Point_At(source_text, 0) == '"') {
+ StringIterator *top = Str_Top(full_text);
+ StringIterator *tail = Str_Tail(full_text);
+ StrIter_Skip_Next_Whitespace(top);
+ StrIter_Skip_Prev_Whitespace(tail);
+ if (StrIter_Starts_With_UTF8(top, "\"", 1)) {
is_phrase = true;
- SStr_Nip(source_text, 1);
- if (SStr_Code_Point_From(source_text, 1) == '"'
- && SStr_Code_Point_From(source_text, 2) != '\\'
- ) {
- SStr_Chop(source_text, 1);
+ StrIter_Advance(top, 1);
+ if (StrIter_Ends_With_UTF8(tail, "\"", 1)
+ && !StrIter_Ends_With_UTF8(tail, "\\\"", 2)
+ ) {
+ StrIter_Recede(tail, 1);
}
}
+ String *source_text = StrIter_substring(top, tail);
// Either use LeafQuery's field or default to Parser's list.
VArray *fields;
@@ -891,7 +897,7 @@ QParser_Expand_Leaf_IMP(QueryParser *self, Query *query) {
fields = (VArray*)INCREF(ivars->fields);
}
- CharBuf *unescape_buf = CB_new(SStr_Get_Size(source_text));
+ CharBuf *unescape_buf = CB_new(Str_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);
@@ -906,8 +912,7 @@ QParser_Expand_Leaf_IMP(QueryParser *self, Query *query) {
}
else {
// Extract token texts.
- String *split_source
- = S_unescape(self, (String*)source_text, unescape_buf);
+ String *split_source = S_unescape(self, 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);
@@ -959,6 +964,9 @@ QParser_Expand_Leaf_IMP(QueryParser *self, Query *query) {
DECREF(unescape_buf);
DECREF(queries);
DECREF(fields);
+ DECREF(source_text);
+ DECREF(tail);
+ DECREF(top);
return retval;
}
[lucy-commits] [08/20] git commit: refs/heads/cfish-string-prep1 - Eliminate
SStr_Nip in CompoundFileReader
Posted by nw...@apache.org.
Eliminate SStr_Nip in CompoundFileReader
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/fd388fc1
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/fd388fc1
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/fd388fc1
Branch: refs/heads/cfish-string-prep1
Commit: fd388fc1a7474f6f1af82d11cc0fe66e66d1c371
Parents: c7e1875
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Sep 7 15:24:00 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Sep 7 18:14:04 2013 +0200
----------------------------------------------------------------------
core/Lucy/Store/CompoundFileReader.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/fd388fc1/core/Lucy/Store/CompoundFileReader.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/CompoundFileReader.c b/core/Lucy/Store/CompoundFileReader.c
index 3955cfb..cc08f68 100644
--- a/core/Lucy/Store/CompoundFileReader.c
+++ b/core/Lucy/Store/CompoundFileReader.c
@@ -87,7 +87,6 @@ CFReader_do_open(CompoundFileReader *self, Folder *folder) {
// Strip directory name from filepaths for old format.
if (ivars->format == 1) {
VArray *files = Hash_Keys(ivars->records);
- StackString *filename = SStr_BLANK();
StackString *folder_name
= IxFileNames_local_part(Folder_Get_Path(folder), SStr_BLANK());
size_t folder_name_len = SStr_Length(folder_name);
@@ -96,9 +95,11 @@ CFReader_do_open(CompoundFileReader *self, Folder *folder) {
String *orig = (String*)VA_Fetch(files, i);
if (Str_Starts_With(orig, (String*)folder_name)) {
Obj *record = Hash_Delete(ivars->records, (Obj*)orig);
- SStr_Assign(filename, orig);
- SStr_Nip(filename, folder_name_len + sizeof(DIR_SEP) - 1);
+ size_t offset = folder_name_len + sizeof(DIR_SEP) - 1;
+ size_t len = Str_Length(orig) - offset;
+ String *filename = Str_SubString(orig, offset, len);
Hash_Store(ivars->records, (Obj*)filename, (Obj*)record);
+ DECREF(filename);
}
}
[lucy-commits] [03/20] git commit: refs/heads/cfish-string-prep1 - Highlighter fixes
Posted by nw...@apache.org.
Highlighter fixes
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/593dfe90
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/593dfe90
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/593dfe90
Branch: refs/heads/cfish-string-prep1
Commit: 593dfe907945fbf464d1a22e1ac5c2e7954d5973
Parents: 1f51cae
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Sep 7 16:57:44 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Sep 7 18:12:45 2013 +0200
----------------------------------------------------------------------
core/Lucy/Test/Highlight/TestHighlighter.c | 2 +-
perl/buildlib/Lucy/Build/Binding/Highlight.pm | 4 ----
2 files changed, 1 insertion(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/593dfe90/core/Lucy/Test/Highlight/TestHighlighter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Highlight/TestHighlighter.c b/core/Lucy/Test/Highlight/TestHighlighter.c
index f8fabc6..2539ad0 100644
--- a/core/Lucy/Test/Highlight/TestHighlighter.c
+++ b/core/Lucy/Test/Highlight/TestHighlighter.c
@@ -139,7 +139,7 @@ test_Raw_Excerpt(TestBatchRunner *runner, Searcher *searcher, Obj *query) {
heat_map);
TEST_TRUE(runner,
Str_Equals_Str(raw_excerpt, "abc/d" ELLIPSIS, 8),
- "Long word at top %s");
+ "Long word at top");
DECREF(heat_map);
DECREF(raw_excerpt);
http://git-wip-us.apache.org/repos/asf/lucy/blob/593dfe90/perl/buildlib/Lucy/Build/Binding/Highlight.pm
----------------------------------------------------------------------
diff --git a/perl/buildlib/Lucy/Build/Binding/Highlight.pm b/perl/buildlib/Lucy/Build/Binding/Highlight.pm
index 90f47a6..7b675fc 100644
--- a/perl/buildlib/Lucy/Build/Binding/Highlight.pm
+++ b/perl/buildlib/Lucy/Build/Binding/Highlight.pm
@@ -90,10 +90,6 @@ END_CONSTRUCTOR
class_name => "Lucy::Highlight::Highlighter",
);
$binding->bind_method(
- alias => '_find_best_fragment',
- method => 'Find_Best_Fragment'
- );
- $binding->bind_method(
alias => '_raw_excerpt',
method => 'Raw_Excerpt'
);
[lucy-commits] [16/20] git commit: refs/heads/cfish-string-prep1 - Eliminate
SStr_Nibble in Clownfish::Test::TestObj
Posted by nw...@apache.org.
Eliminate SStr_Nibble in Clownfish::Test::TestObj
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/d7ed0918
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/d7ed0918
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/d7ed0918
Branch: refs/heads/cfish-string-prep1
Commit: d7ed091804f0f5f657f04b56b3c7613625213a8f
Parents: ab80bcf
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Sep 7 18:04:59 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Sep 7 18:14:05 2013 +0200
----------------------------------------------------------------------
clownfish/runtime/core/Clownfish/Test/TestObj.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/d7ed0918/clownfish/runtime/core/Clownfish/Test/TestObj.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/Test/TestObj.c b/clownfish/runtime/core/Clownfish/Test/TestObj.c
index cdc0961..7e06955 100644
--- a/clownfish/runtime/core/Clownfish/Test/TestObj.c
+++ b/clownfish/runtime/core/Clownfish/Test/TestObj.c
@@ -67,12 +67,7 @@ static void
test_To_String(TestBatchRunner *runner) {
Obj *testobj = S_new_testobj();
String *string = Obj_To_String(testobj);
- StackString *temp = SSTR_WRAP(string);
- while (SStr_Get_Size(temp)) {
- if (SStr_Starts_With_Str(temp, "TestObj", 7)) { break; }
- SStr_Nibble(temp);
- }
- TEST_TRUE(runner, SStr_Starts_With_Str(temp, "TestObj", 7), "To_String");
+ TEST_TRUE(runner, Str_Find_Str(string, "TestObj", 7) >= 0, "To_String");
DECREF(string);
DECREF(testobj);
}
[lucy-commits] [02/20] git commit: refs/heads/cfish-string-prep1 - Return type of
StrIter_Clone
Posted by nw...@apache.org.
Return type of StrIter_Clone
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/0d0cb67a
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/0d0cb67a
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/0d0cb67a
Branch: refs/heads/cfish-string-prep1
Commit: 0d0cb67ab9d16da74eeb33218ae31b579377f2c2
Parents: 593dfe9
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Sep 7 12:09:36 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Sep 7 18:12:45 2013 +0200
----------------------------------------------------------------------
clownfish/runtime/core/Clownfish/String.c | 4 ++--
clownfish/runtime/core/Clownfish/String.cfh | 2 +-
clownfish/runtime/core/Clownfish/Test/TestString.c | 2 +-
core/Lucy/Highlight/Highlighter.c | 12 ++++++------
4 files changed, 10 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/0d0cb67a/clownfish/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.c b/clownfish/runtime/core/Clownfish/String.c
index f6f1a85..01a7939 100644
--- a/clownfish/runtime/core/Clownfish/String.c
+++ b/clownfish/runtime/core/Clownfish/String.c
@@ -806,9 +806,9 @@ StrIter_substring(StringIterator *top, StringIterator *tail) {
tail->byte_offset - top->byte_offset);
}
-Obj*
+StringIterator*
StrIter_Clone_IMP(StringIterator *self) {
- return (Obj*)StrIter_new(self->string, self->byte_offset);
+ return StrIter_new(self->string, self->byte_offset);
}
void
http://git-wip-us.apache.org/repos/asf/lucy/blob/0d0cb67a/clownfish/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.cfh b/clownfish/runtime/core/Clownfish/String.cfh
index d6d378a..bf9a4a9 100644
--- a/clownfish/runtime/core/Clownfish/String.cfh
+++ b/clownfish/runtime/core/Clownfish/String.cfh
@@ -392,7 +392,7 @@ class Clownfish::StringIterator cnick StrIter
inert incremented String*
substring(StringIterator *top, StringIterator *tail);
- public incremented Obj*
+ public incremented StringIterator*
Clone(StringIterator *self);
public void
http://git-wip-us.apache.org/repos/asf/lucy/blob/0d0cb67a/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 eced59f..4b937f8 100644
--- a/clownfish/runtime/core/Clownfish/Test/TestString.c
+++ b/clownfish/runtime/core/Clownfish/Test/TestString.c
@@ -329,7 +329,7 @@ test_iterator(TestBatchRunner *runner) {
TEST_INT_EQ(runner, StrIter_Compare_To(top, (Obj*)top), 0,
"Compare_To top == top");
- StringIterator *clone = (StringIterator*)StrIter_Clone(top);
+ StringIterator *clone = StrIter_Clone(top);
TEST_TRUE(runner, StrIter_Equals(clone, (Obj*)top), "Clone");
StrIter_Assign(clone, tail);
http://git-wip-us.apache.org/repos/asf/lucy/blob/0d0cb67a/core/Lucy/Highlight/Highlighter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Highlight/Highlighter.c b/core/Lucy/Highlight/Highlighter.c
index a4529e7..dc2f0a3 100644
--- a/core/Lucy/Highlight/Highlighter.c
+++ b/core/Lucy/Highlight/Highlighter.c
@@ -220,7 +220,7 @@ S_find_starting_boundary(StringIterator *top, uint32_t max_skip,
// Check if we're at a starting boundary already.
- StringIterator *iter = (StringIterator*)StrIter_Clone(top);
+ StringIterator *iter = StrIter_Clone(top);
while (true) {
uint32_t code_point = StrIter_Prev(iter);
@@ -233,7 +233,7 @@ S_find_starting_boundary(StringIterator *top, uint32_t max_skip,
}
if (StrHelp_is_whitespace(code_point)) {
- if (word == NULL) { word = (StringIterator*)StrIter_Clone(top); }
+ if (word == NULL) { word = StrIter_Clone(top); }
}
else {
break;
@@ -258,7 +258,7 @@ S_find_starting_boundary(StringIterator *top, uint32_t max_skip,
}
if (word == NULL && StrHelp_is_whitespace(code_point)) {
- word = (StringIterator*)StrIter_Clone(iter);
+ word = StrIter_Clone(iter);
word_offset = i + 1;
}
}
@@ -290,7 +290,7 @@ S_find_ending_boundary(StringIterator *tail, uint32_t max_skip,
// Check if we're at an ending boundary already. Don't check for a word
// boundary because we need space for a trailing ellipsis.
- StringIterator *iter = (StringIterator*)StrIter_Clone(tail);
+ StringIterator *iter = StrIter_Clone(tail);
do {
code_point = StrIter_Next(iter);
@@ -324,7 +324,7 @@ S_find_ending_boundary(StringIterator *tail, uint32_t max_skip,
if (StrHelp_is_whitespace(code_point)) {
if (word == NULL) {
- word = (StringIterator*)StrIter_Clone(iter);
+ word = StrIter_Clone(iter);
word_offset = i + 1;
}
}
@@ -401,7 +401,7 @@ Highlighter_Raw_Excerpt_IMP(Highlighter *self, const String *field_val,
// Find end of excerpt.
- StringIterator *tail = (StringIterator*)StrIter_Clone(top);
+ StringIterator *tail = StrIter_Clone(top);
uint32_t max_len = ivars->excerpt_length;
if (!found_starting_edge) {
[lucy-commits] [20/20] git commit: refs/heads/cfish-string-prep1 - Convert
Util::Json to StringIterator
Posted by nw...@apache.org.
Convert Util::Json to StringIterator
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/ab80bcf5
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/ab80bcf5
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/ab80bcf5
Branch: refs/heads/cfish-string-prep1
Commit: ab80bcf5383f4dc6f08e606f1ee69233abed551a
Parents: c053487
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Sep 7 17:59:45 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Sep 7 18:14:05 2013 +0200
----------------------------------------------------------------------
core/Lucy/Util/Json.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/ab80bcf5/core/Lucy/Util/Json.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/Json.c b/core/Lucy/Util/Json.c
index 33295a1..61018d6 100644
--- a/core/Lucy/Util/Json.c
+++ b/core/Lucy/Util/Json.c
@@ -175,14 +175,14 @@ Json_set_tolerant(bool tolerance) {
static const int32_t MAX_DEPTH = 200;
static void
-S_append_json_string(Obj *dump, CharBuf *buf) {
+S_append_json_string(String *dump, CharBuf *buf) {
// Append opening quote.
CB_Cat_Trusted_UTF8(buf, "\"", 1);
// Process string data.
- StackString *iterator = SSTR_WRAP((String*)dump);
- while (SStr_Get_Size(iterator)) {
- uint32_t code_point = SStr_Nibble(iterator);
+ StringIterator *iter = Str_Top(dump);
+ uint32_t code_point;
+ while (STRITER_DONE != (code_point = StrIter_Next(iter))) {
if (code_point > 127) {
// There is no need to escape any high characters, including those
// above the BMP, as we assume that the destination channel can
@@ -247,6 +247,8 @@ S_append_json_string(Obj *dump, CharBuf *buf) {
// Append closing quote.
CB_Cat_Trusted_UTF8(buf, "\"", 1);
+
+ DECREF(iter);
}
static void
@@ -275,7 +277,7 @@ S_to_json(Obj *dump, CharBuf *buf, int32_t depth) {
CB_Cat_Trusted_UTF8(buf, "false", 5);
}
else if (Obj_Is_A(dump, STRING)) {
- S_append_json_string(dump, buf);
+ S_append_json_string((String*)dump, buf);
}
else if (Obj_Is_A(dump, INTNUM)) {
CB_catf(buf, "%i64", Obj_To_I64(dump));
@@ -349,7 +351,7 @@ S_to_json(Obj *dump, CharBuf *buf, int32_t depth) {
Obj *key = VA_Fetch(keys, i);
CB_Cat_Trusted_UTF8(buf, "\n", 1);
S_cat_whitespace(buf, depth + 1);
- S_append_json_string(key, buf);
+ S_append_json_string((String*)key, buf);
CB_Cat_Trusted_UTF8(buf, ": ", 2);
if (!S_to_json(Hash_Fetch(hash, key), buf, depth + 1)) {
DECREF(keys);
@@ -684,7 +686,7 @@ S_set_error(CharBuf *buf, char *json, char *limit, int line,
len = end - json;
}
StackString *snippet = SSTR_WRAP_STR(json, len);
- S_append_json_string((Obj*)snippet, buf);
+ S_append_json_string((String*)snippet, buf);
String *mess = CB_Yield_String(buf);
DECREF(buf);
[lucy-commits] [04/20] git commit: refs/heads/cfish-string-prep1 - Convert
Index::Segment to StringIterator
Posted by nw...@apache.org.
Convert Index::Segment to StringIterator
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/c56353bd
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/c56353bd
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/c56353bd
Branch: refs/heads/cfish-string-prep1
Commit: c56353bdabe13a9285d6ee66d2215c4059f84ee4
Parents: f374f95
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Sep 7 14:44:44 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Sep 7 18:14:04 2013 +0200
----------------------------------------------------------------------
core/Lucy/Index/Segment.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/c56353bd/core/Lucy/Index/Segment.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/Segment.c b/core/Lucy/Index/Segment.c
index bd283d0..d375e98 100644
--- a/core/Lucy/Index/Segment.c
+++ b/core/Lucy/Index/Segment.c
@@ -66,13 +66,17 @@ Seg_num_to_name(int64_t number) {
bool
Seg_valid_seg_name(const String *name) {
if (Str_Starts_With_Str(name, "seg_", 4)) {
- StackString *scratch = SSTR_WRAP(name);
- SStr_Nip(scratch, 4);
+ StringIterator *iter = Str_Top(name);
+ StrIter_Advance(iter, 4);
uint32_t code_point;
- while (0 != (code_point = SStr_Nibble(scratch))) {
- if (!isalnum(code_point)) { return false; }
+ while (STRITER_DONE != (code_point = StrIter_Next(iter))) {
+ if (!isalnum(code_point)) {
+ DECREF(iter);
+ return false;
+ }
}
- if (SStr_Get_Size(scratch) == 0) { return true; } // Success!
+ DECREF(iter);
+ return true; // Success!
}
return false;
}
[lucy-commits] [14/20] git commit: refs/heads/cfish-string-prep1 - Convert
Util::IndexFileNames to StringIterator
Posted by nw...@apache.org.
Convert Util::IndexFileNames to StringIterator
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/c0534877
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/c0534877
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/c0534877
Branch: refs/heads/cfish-string-prep1
Commit: c0534877a17453b81eb52941968a78fd7d623c2f
Parents: 430ba96
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Sep 7 17:51:04 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Sep 7 18:14:05 2013 +0200
----------------------------------------------------------------------
core/Lucy/Store/CompoundFileReader.c | 8 ++---
core/Lucy/Store/Folder.c | 47 +++++++++++++++------------
core/Lucy/Store/RAMFolder.c | 38 ++++++++++++----------
core/Lucy/Test/Util/TestIndexFileNames.c | 43 ++++++++++--------------
core/Lucy/Util/IndexFileNames.c | 46 ++++++++++++++------------
core/Lucy/Util/IndexFileNames.cfh | 12 +++----
6 files changed, 98 insertions(+), 96 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/c0534877/core/Lucy/Store/CompoundFileReader.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/CompoundFileReader.c b/core/Lucy/Store/CompoundFileReader.c
index cc08f68..2ecf45c 100644
--- a/core/Lucy/Store/CompoundFileReader.c
+++ b/core/Lucy/Store/CompoundFileReader.c
@@ -87,13 +87,12 @@ CFReader_do_open(CompoundFileReader *self, Folder *folder) {
// Strip directory name from filepaths for old format.
if (ivars->format == 1) {
VArray *files = Hash_Keys(ivars->records);
- StackString *folder_name
- = IxFileNames_local_part(Folder_Get_Path(folder), SStr_BLANK());
- size_t folder_name_len = SStr_Length(folder_name);
+ String *folder_name = IxFileNames_local_part(Folder_Get_Path(folder));
+ size_t folder_name_len = Str_Length(folder_name);
for (uint32_t i = 0, max = VA_Get_Size(files); i < max; i++) {
String *orig = (String*)VA_Fetch(files, i);
- if (Str_Starts_With(orig, (String*)folder_name)) {
+ if (Str_Starts_With(orig, folder_name)) {
Obj *record = Hash_Delete(ivars->records, (Obj*)orig);
size_t offset = folder_name_len + sizeof(DIR_SEP) - 1;
size_t len = Str_Length(orig) - offset;
@@ -103,6 +102,7 @@ CFReader_do_open(CompoundFileReader *self, Folder *folder) {
}
}
+ DECREF(folder_name);
DECREF(files);
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/c0534877/core/Lucy/Store/Folder.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/Folder.c b/core/Lucy/Store/Folder.c
index 066d20e..371dcc6 100644
--- a/core/Lucy/Store/Folder.c
+++ b/core/Lucy/Store/Folder.c
@@ -67,11 +67,12 @@ Folder_Open_In_IMP(Folder *self, const String *path) {
InStream *instream = NULL;
if (enclosing_folder) {
- StackString *name = IxFileNames_local_part(path, SStr_BLANK());
- instream = Folder_Local_Open_In(enclosing_folder, (String*)name);
+ String *name = IxFileNames_local_part(path);
+ instream = Folder_Local_Open_In(enclosing_folder, name);
if (!instream) {
ERR_ADD_FRAME(Err_get_error());
}
+ DECREF(name);
}
else {
Err_set_error(Err_new(Str_newf("Invalid path: '%o'", path)));
@@ -125,12 +126,12 @@ Folder_Open_FileHandle_IMP(Folder *self, const String *path,
FileHandle *fh = NULL;
if (enclosing_folder) {
- StackString *name = IxFileNames_local_part(path, SStr_BLANK());
- fh = Folder_Local_Open_FileHandle(enclosing_folder,
- (String*)name, flags);
+ String *name = IxFileNames_local_part(path);
+ fh = Folder_Local_Open_FileHandle(enclosing_folder, name, flags);
if (!fh) {
ERR_ADD_FRAME(Err_get_error());
}
+ DECREF(name);
}
else {
Err_set_error(Err_new(Str_newf("Invalid path: '%o'", path)));
@@ -143,8 +144,9 @@ bool
Folder_Delete_IMP(Folder *self, const String *path) {
Folder *enclosing_folder = Folder_Enclosing_Folder(self, path);
if (enclosing_folder) {
- StackString *name = IxFileNames_local_part(path, SStr_BLANK());
- bool result = Folder_Local_Delete(enclosing_folder, (String*)name);
+ String *name = IxFileNames_local_part(path);
+ bool result = Folder_Local_Delete(enclosing_folder, name);
+ DECREF(name);
return result;
}
else {
@@ -160,10 +162,10 @@ Folder_Delete_Tree_IMP(Folder *self, const String *path) {
if (!path || !Str_Get_Size(path)) { return false; }
if (enclosing_folder) {
- StackString *local = IxFileNames_local_part(path, SStr_BLANK());
- if (Folder_Local_Is_Directory(enclosing_folder, (String*)local)) {
+ String *local = IxFileNames_local_part(path);
+ if (Folder_Local_Is_Directory(enclosing_folder, local)) {
Folder *inner_folder
- = Folder_Local_Find_Folder(enclosing_folder, (String*)local);
+ = Folder_Local_Find_Folder(enclosing_folder, local);
DirHandle *dh = Folder_Local_Open_Dir(inner_folder);
if (dh) {
VArray *files = VA_new(20);
@@ -195,7 +197,9 @@ Folder_Delete_Tree_IMP(Folder *self, const String *path) {
DECREF(dh);
}
}
- return Folder_Local_Delete(enclosing_folder, (String*)local);
+ bool retval = Folder_Local_Delete(enclosing_folder, local);
+ DECREF(local);
+ return retval;
}
else {
// Return failure if the entry wasn't there in the first place.
@@ -286,11 +290,12 @@ Folder_MkDir_IMP(Folder *self, const String *path) {
path)));
}
else {
- StackString *name = IxFileNames_local_part(path, SStr_BLANK());
- result = Folder_Local_MkDir(enclosing_folder, (String*)name);
+ String *name = IxFileNames_local_part(path);
+ result = Folder_Local_MkDir(enclosing_folder, name);
if (!result) {
ERR_ADD_FRAME(Err_get_error());
}
+ DECREF(name);
}
return result;
@@ -301,10 +306,11 @@ Folder_Exists_IMP(Folder *self, const String *path) {
Folder *enclosing_folder = Folder_Enclosing_Folder(self, path);
bool retval = false;
if (enclosing_folder) {
- StackString *name = IxFileNames_local_part(path, SStr_BLANK());
- if (Folder_Local_Exists(enclosing_folder, (String*)name)) {
+ String *name = IxFileNames_local_part(path);
+ if (Folder_Local_Exists(enclosing_folder, name)) {
retval = true;
}
+ DECREF(name);
}
return retval;
}
@@ -314,10 +320,11 @@ Folder_Is_Directory_IMP(Folder *self, const String *path) {
Folder *enclosing_folder = Folder_Enclosing_Folder(self, path);
bool retval = false;
if (enclosing_folder) {
- StackString *name = IxFileNames_local_part(path, SStr_BLANK());
- if (Folder_Local_Is_Directory(enclosing_folder, (String*)name)) {
+ String *name = IxFileNames_local_part(path);
+ if (Folder_Local_Is_Directory(enclosing_folder, name)) {
retval = true;
}
+ DECREF(name);
}
return retval;
}
@@ -412,12 +419,12 @@ Folder_Consolidate_IMP(Folder *self, const String *path) {
CFWriter_Consolidate(cf_writer);
DECREF(cf_writer);
if (Str_Get_Size(path)) {
- StackString *name = IxFileNames_local_part(path, SStr_BLANK());
CompoundFileReader *cf_reader = CFReader_open(folder);
if (!cf_reader) { RETHROW(INCREF(Err_get_error())); }
Hash *entries = Folder_IVARS(enclosing_folder)->entries;
- Hash_Store(entries, (Obj*)name,
- (Obj*)cf_reader);
+ String *name = IxFileNames_local_part(path);
+ Hash_Store(entries, (Obj*)name, (Obj*)cf_reader);
+ DECREF(name);
}
}
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/c0534877/core/Lucy/Store/RAMFolder.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/RAMFolder.c b/core/Lucy/Store/RAMFolder.c
index f2b2dd4..4a42484 100644
--- a/core/Lucy/Store/RAMFolder.c
+++ b/core/Lucy/Store/RAMFolder.c
@@ -141,7 +141,7 @@ RAMFolder_Local_Is_Directory_IMP(RAMFolder *self, const String *name) {
static bool
S_rename_or_hard_link(RAMFolder *self, const String* from, const String *to,
Folder *from_folder, Folder *to_folder,
- StackString *from_name, StackString *to_name,
+ String *from_name, String *to_name,
int op) {
Obj *elem = NULL;
RAMFolder *inner_from_folder = NULL;
@@ -190,7 +190,7 @@ S_rename_or_hard_link(RAMFolder *self, const String* from, const String *to,
(Obj*)from_name);
if (!elem) {
if (Folder_Is_A(from_folder, COMPOUNDFILEREADER)
- && Folder_Local_Exists(from_folder, (String*)from_name)
+ && Folder_Local_Exists(from_folder, from_name)
) {
Err_set_error(Err_new(Str_newf("Source file '%o' is virtual",
from)));
@@ -210,7 +210,7 @@ S_rename_or_hard_link(RAMFolder *self, const String* from, const String *to,
// Return success fast if file is copied on top of itself.
if (inner_from_folder == inner_to_folder
- && SStr_Equals(from_name, (Obj*)to_name)
+ && Str_Equals(from_name, (Obj*)to_name)
) {
return true;
}
@@ -241,7 +241,7 @@ S_rename_or_hard_link(RAMFolder *self, const String* from, const String *to,
DECREF(Hash_Delete(RAMFolder_IVARS(inner_from_folder)->entries,
(Obj*)from_name));
if (Obj_Is_A(elem, FOLDER)) {
- String *newpath = S_fullpath(inner_to_folder, (String*)to_name);
+ String *newpath = S_fullpath(inner_to_folder, to_name);
Folder_Set_Path((Folder*)elem, newpath);
DECREF(newpath);
}
@@ -276,28 +276,30 @@ S_rename_or_hard_link(RAMFolder *self, const String* from, const String *to,
bool
RAMFolder_Rename_IMP(RAMFolder *self, const String* from,
const String *to) {
- Folder *from_folder = RAMFolder_Enclosing_Folder(self, from);
- Folder *to_folder = RAMFolder_Enclosing_Folder(self, to);
- StackString *from_name = IxFileNames_local_part(from, SStr_BLANK());
- StackString *to_name = IxFileNames_local_part(to, SStr_BLANK());
- bool result = S_rename_or_hard_link(self, from, to, from_folder,
- to_folder, from_name, to_name,
- OP_RENAME);
+ Folder *from_folder = RAMFolder_Enclosing_Folder(self, from);
+ Folder *to_folder = RAMFolder_Enclosing_Folder(self, to);
+ String *from_name = IxFileNames_local_part(from);
+ String *to_name = IxFileNames_local_part(to);
+ bool result = S_rename_or_hard_link(self, from, to, from_folder, to_folder,
+ from_name, to_name, OP_RENAME);
if (!result) { ERR_ADD_FRAME(Err_get_error()); }
+ DECREF(to_name);
+ DECREF(from_name);
return result;
}
bool
RAMFolder_Hard_Link_IMP(RAMFolder *self, const String *from,
const String *to) {
- Folder *from_folder = RAMFolder_Enclosing_Folder(self, from);
- Folder *to_folder = RAMFolder_Enclosing_Folder(self, to);
- StackString *from_name = IxFileNames_local_part(from, SStr_BLANK());
- StackString *to_name = IxFileNames_local_part(to, SStr_BLANK());
- bool result = S_rename_or_hard_link(self, from, to, from_folder,
- to_folder, from_name, to_name,
- OP_HARD_LINK);
+ Folder *from_folder = RAMFolder_Enclosing_Folder(self, from);
+ Folder *to_folder = RAMFolder_Enclosing_Folder(self, to);
+ String *from_name = IxFileNames_local_part(from);
+ String *to_name = IxFileNames_local_part(to);
+ bool result = S_rename_or_hard_link(self, from, to, from_folder, to_folder,
+ from_name, to_name, OP_HARD_LINK);
if (!result) { ERR_ADD_FRAME(Err_get_error()); }
+ DECREF(to_name);
+ DECREF(from_name);
return result;
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/c0534877/core/Lucy/Test/Util/TestIndexFileNames.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Util/TestIndexFileNames.c b/core/Lucy/Test/Util/TestIndexFileNames.c
index 8dbbb7a..6ba675d 100644
--- a/core/Lucy/Test/Util/TestIndexFileNames.c
+++ b/core/Lucy/Test/Util/TestIndexFileNames.c
@@ -28,33 +28,24 @@ TestIxFileNames_new() {
}
static void
-test_local_part(TestBatchRunner *runner) {
- StackString *source = SStr_BLANK();
- StackString *got = SStr_BLANK();
-
- got = IxFileNames_local_part((String*)source, got);
- TEST_TRUE(runner, SStr_Equals(got, (Obj*)source), "simple name");
-
- SStr_Assign_Str(source, "foo.txt", 7);
- got = IxFileNames_local_part((String*)source, got);
- TEST_TRUE(runner, SStr_Equals(got, (Obj*)source), "name with extension");
-
- SStr_Assign_Str(source, "/foo", 4);
- got = IxFileNames_local_part((String*)source, got);
- TEST_TRUE(runner, SStr_Equals_Str(got, "foo", 3), "strip leading slash");
-
- SStr_Assign_Str(source, "/foo/", 5);
- got = IxFileNames_local_part((String*)source, got);
- TEST_TRUE(runner, SStr_Equals_Str(got, "foo", 3), "strip trailing slash");
-
- SStr_Assign_Str(source, "foo/bar\\ ", 9);
- got = IxFileNames_local_part((String*)source, got);
- TEST_TRUE(runner, SStr_Equals_Str(got, "bar\\ ", 5),
- "Include garbage like backslashes and spaces");
+S_test_local_part(TestBatchRunner *runner, const char *source,
+ const char *wanted, const char *test_name) {
+ StackString *source_str = SSTR_WRAP_STR(source, strlen(source));
+ String *got = IxFileNames_local_part((String*)source_str);
+ TEST_TRUE(runner, Str_Equals_Str(got, wanted, strlen(wanted)), test_name);
+ DECREF(got);
+}
- SStr_Assign_Str(source, "foo/bar/baz.txt", 15);
- got = IxFileNames_local_part((String*)source, got);
- TEST_TRUE(runner, SStr_Equals_Str(got, "baz.txt", 7), "find last component");
+static void
+test_local_part(TestBatchRunner *runner) {
+ S_test_local_part(runner, "", "", "simple name");
+ S_test_local_part(runner, "foo.txt", "foo.txt", "name with extension");
+ S_test_local_part(runner, "/foo", "foo", "strip leading slash");
+ S_test_local_part(runner, "/foo/", "foo", "strip trailing slash");
+ S_test_local_part(runner, "foo/bar\\ ", "bar\\ ",
+ "Include garbage like backslashes and spaces");
+ S_test_local_part(runner, "foo/bar/baz.txt", "baz.txt",
+ "find last component");
}
static void
http://git-wip-us.apache.org/repos/asf/lucy/blob/c0534877/core/Lucy/Util/IndexFileNames.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/IndexFileNames.c b/core/Lucy/Util/IndexFileNames.c
index 9a938db..e3b7bf7 100644
--- a/core/Lucy/Util/IndexFileNames.c
+++ b/core/Lucy/Util/IndexFileNames.c
@@ -51,45 +51,51 @@ IxFileNames_latest_snapshot(Folder *folder) {
uint64_t
IxFileNames_extract_gen(const String *name) {
- StackString *num_string = SSTR_WRAP(name);
+ StringIterator *iter = Str_Top(name);
// Advance past first underscore. Bail if we run out of string or if we
// encounter a NULL.
while (1) {
- uint32_t code_point = SStr_Nibble(num_string);
- if (code_point == 0) { return 0; }
+ uint32_t code_point = StrIter_Next(iter);
+ if (code_point == STRITER_DONE) { return 0; }
else if (code_point == '_') { break; }
}
- return (uint64_t)SStr_BaseX_To_I64(num_string, 36);
-}
+ String *num_string = StrIter_substring(iter, NULL);
+ uint64_t retval = (uint64_t)Str_BaseX_To_I64(num_string, 36);
-StackString*
-IxFileNames_local_part(const String *path, StackString *target) {
- StackString *scratch = SSTR_WRAP(path);
- size_t local_part_start = Str_Length(path);
- uint32_t code_point;
+ DECREF(num_string);
+ DECREF(iter);
+ return retval;
+}
- SStr_Assign(target, path);
+String*
+IxFileNames_local_part(const String *path) {
+ StringIterator *top = Str_Tail(path);
+ uint32_t code_point = StrIter_Prev(top);
// Trim trailing slash.
- while (SStr_Code_Point_From(target, 1) == '/') {
- SStr_Chop(target, 1);
- SStr_Chop(scratch, 1);
- local_part_start--;
+ while (code_point == '/') {
+ code_point = StrIter_Prev(top);
}
+ StringIterator *tail = StrIter_Clone(top);
+ StrIter_Advance(tail, 1);
+
// Substring should start after last slash.
- while (0 != (code_point = SStr_Code_Point_From(scratch, 1))) {
+ while (code_point != STRITER_DONE) {
if (code_point == '/') {
- SStr_Nip(target, local_part_start);
+ StrIter_Advance(top, 1);
break;
}
- SStr_Chop(scratch, 1);
- local_part_start--;
+ code_point = StrIter_Prev(top);
}
- return target;
+ String *retval = StrIter_substring(top, tail);
+
+ DECREF(tail);
+ DECREF(top);
+ return retval;
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/c0534877/core/Lucy/Util/IndexFileNames.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/IndexFileNames.cfh b/core/Lucy/Util/IndexFileNames.cfh
index 872efb2..b82f857 100644
--- a/core/Lucy/Util/IndexFileNames.cfh
+++ b/core/Lucy/Util/IndexFileNames.cfh
@@ -35,15 +35,11 @@ inert class Lucy::Util::IndexFileNames cnick IxFileNames {
inert incremented nullable String*
latest_snapshot(Folder *folder);
- /** Split the <code>path</code> on '/' and assign the last component to
- * <code>target</code>, which will remain valid only as long as
- * <code>path</code> is unmodified. Trailing slashes will be stripped.
- *
- * @param target The target string to assign to.
- * @return target, allowing an assignment idiom.
+ /** Split the <code>path</code> on '/' and return the last component.
+ * Trailing slashes will be stripped.
*/
- inert incremented StackString*
- local_part(const String *path, StackString *target);
+ inert incremented String*
+ local_part(const String *path);
}
[lucy-commits] [13/20] git commit: refs/heads/cfish-string-prep1 - Convert
Store::Lock to StringIterator
Posted by nw...@apache.org.
Convert Store::Lock to StringIterator
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/07945bd6
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/07945bd6
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/07945bd6
Branch: refs/heads/cfish-string-prep1
Commit: 07945bd60f1928bea75f275b0637e3ccf470cf74
Parents: a3d2e27
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Sep 7 16:17:00 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Sep 7 18:14:05 2013 +0200
----------------------------------------------------------------------
core/Lucy/Store/Lock.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/07945bd6/core/Lucy/Store/Lock.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/Lock.c b/core/Lucy/Store/Lock.c
index 18e965a..4d778d0 100644
--- a/core/Lucy/Store/Lock.c
+++ b/core/Lucy/Store/Lock.c
@@ -39,9 +39,9 @@ Lock_init(Lock *self, Folder *folder, const String *name,
DECREF(self);
THROW(ERR, "Invalid value for 'interval': %i32", interval);
}
- StackString *scratch = SSTR_WRAP(name);
+ StringIterator *iter = Str_Top(name);
uint32_t code_point;
- while (0 != (code_point = SStr_Nibble(scratch))) {
+ while (STRITER_DONE != (code_point = StrIter_Next(iter))) {
if (isalnum(code_point)
|| code_point == '.'
|| code_point == '-'
@@ -52,6 +52,7 @@ Lock_init(Lock *self, Folder *folder, const String *name,
DECREF(self);
THROW(ERR, "Lock name contains disallowed characters: '%o'", name);
}
+ DECREF(iter);
// Assign.
ivars->folder = (Folder*)INCREF(folder);
@@ -230,17 +231,18 @@ LFLock_Maybe_Delete_File_IMP(LockFileLock *self, const String *path,
LockFileLockIVARS *const ivars = LFLock_IVARS(self);
Folder *folder = ivars->folder;
bool success = false;
- StackString *scratch = SSTR_WRAP(path);
// Only delete locks that start with our lock name.
- String *lock_dir_name = (String*)SSTR_WRAP_STR("locks", 5);
- if (!SStr_Starts_With(scratch, lock_dir_name)) {
+ if (!Str_Starts_With_Str(path, "locks", 5)) {
return false;
}
- SStr_Nip(scratch, Str_Get_Size(lock_dir_name) + 1);
- if (!SStr_Starts_With(scratch, ivars->name)) {
+ StringIterator *iter = Str_Top(path);
+ StrIter_Advance(iter, 5 + 1);
+ if (!StrIter_Starts_With(iter, ivars->name)) {
+ DECREF(iter);
return false;
}
+ DECREF(iter);
// Attempt to delete dead lock file.
if (Folder_Exists(folder, path)) {
[lucy-commits] [11/20] git commit: refs/heads/cfish-string-prep1 - Introduce
StrIter_Starts_With_UTF8
Posted by nw...@apache.org.
Introduce StrIter_Starts_With_UTF8
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/e1d95d20
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/e1d95d20
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/e1d95d20
Branch: refs/heads/cfish-string-prep1
Commit: e1d95d20cc7772bf66c201ea9740d5d723f58c1a
Parents: e3a2f92
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Sep 7 14:29:32 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Sep 7 18:14:04 2013 +0200
----------------------------------------------------------------------
clownfish/runtime/core/Clownfish/String.c | 11 ++++++++---
clownfish/runtime/core/Clownfish/String.cfh | 6 ++++++
2 files changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/e1d95d20/clownfish/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.c b/clownfish/runtime/core/Clownfish/String.c
index ce10b7f..6bfcea7 100644
--- a/clownfish/runtime/core/Clownfish/String.c
+++ b/clownfish/runtime/core/Clownfish/String.c
@@ -1048,6 +1048,12 @@ StrIter_Skip_Prev_Whitespace_IMP(StringIterator *self) {
bool
StrIter_Starts_With_IMP(StringIterator *self, String *prefix) {
+ return StrIter_Starts_With_UTF8_IMP(self, prefix->ptr, prefix->size);
+}
+
+bool
+StrIter_Starts_With_UTF8_IMP(StringIterator *self, const char *prefix,
+ size_t size) {
String *string = self->string;
size_t byte_offset = self->byte_offset;
@@ -1055,10 +1061,9 @@ StrIter_Starts_With_IMP(StringIterator *self, String *prefix) {
THROW(ERR, "Invalid StringIterator offset");
}
- if (string->size - byte_offset < prefix->size) { return false; }
+ if (string->size - byte_offset < size) { return false; }
- const char *ptr = string->ptr + byte_offset;
- return memcmp(ptr, prefix->ptr, prefix->size) == 0;
+ return memcmp(string->ptr + byte_offset, prefix, size) == 0;
}
void
http://git-wip-us.apache.org/repos/asf/lucy/blob/e1d95d20/clownfish/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.cfh b/clownfish/runtime/core/Clownfish/String.cfh
index b49d957..82a51c9 100644
--- a/clownfish/runtime/core/Clownfish/String.cfh
+++ b/clownfish/runtime/core/Clownfish/String.cfh
@@ -460,6 +460,12 @@ class Clownfish::StringIterator cnick StrIter
bool
Starts_With(StringIterator *self, String *prefix);
+ /** Test whether the content after the iterator starts with the passed-in
+ * string.
+ */
+ bool
+ Starts_With_UTF8(StringIterator *self, const char *prefix, size_t size);
+
public void
Destroy(StringIterator *self);
}
[lucy-commits] [10/20] git commit: refs/heads/cfish-string-prep1 - Introduce
StrIter_Ends_With
Posted by nw...@apache.org.
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 <we...@aevum.de>
Authored: Sat Sep 7 15:17:08 2013 +0200
Committer: Nick Wellnhofer <we...@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);