From: Wilfried Göesgens Date: Sun, 6 Sep 2009 07:16:30 +0000 (+0000) Subject: * fix it some, but not all. X-Git-Tag: v7.86~878 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=95411856f885000fcb226c6aeb8ac44cba434594 * fix it some, but not all. --- diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index a405e77a1..141c9bfed 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -1375,7 +1375,9 @@ int StrBufExtract_NextToken(StrBuf *dest, const StrBuf *Source, const char **pSt s = *pStart; /* start to find the next token */ - while ((s < EndBuffer) && !IsEmptyStr(s)) + while ((s < EndBuffer) && + (!IsEmptyStr(s)) && + (current_token == 0) ) { if (*s == separator) { @@ -1406,14 +1408,12 @@ int StrBufExtract_NextToken(StrBuf *dest, const StrBuf *Source, const char **pSt ++s; } - /* did we reach a \0 ? */ - if ((s >= EndBuffer) || IsEmptyStr(s)) { + /* did we reach the end? */ + if ((s > EndBuffer)) { *pStart = EndBuffer + 1; } else { *pStart = s; /* remember the position for the next run */ - (*pStart) ++; /* move behind the next token separator so - * we don't see it next time */ } /* sanitize our extracted token */ diff --git a/libcitadel/tests/Makefile.in b/libcitadel/tests/Makefile.in index 7081a29ff..e222bd0b3 100644 --- a/libcitadel/tests/Makefile.in +++ b/libcitadel/tests/Makefile.in @@ -7,7 +7,7 @@ DEFS=@DEFS@ INSTALL=@INSTALL@ LIBOBJS=@LIBOBJS@ -lcunit -lcitadel LIBS=@LIBS@ -LDFLAGS=@LDFLAGS@ -L ../lib/.libs +LDFLAGS=@LDFLAGS@ -L ../.libs SED=@SED@ LCUNIT_DEFS= srcdir=../ diff --git a/libcitadel/tests/stringbuf_test.c b/libcitadel/tests/stringbuf_test.c index 48143b8ad..24d4ee082 100644 --- a/libcitadel/tests/stringbuf_test.c +++ b/libcitadel/tests/stringbuf_test.c @@ -114,9 +114,37 @@ static void TestCreateBuf(void) CU_ASSERT(StrBufIsNumber(Buf) == 1); - } + +static void TestNextTokenizer(void) +{ + const char *pCh = NULL; + StrBuf *Buf; + StrBuf *Buf2; + long CountTokens = 0; + long HaveNextToken; + long HaveNextTokenF; + + Buf = NewStrBufPlain(HKEY("abc,abc, 1, ,,")); + printf("\nTemplate: >%s<\n", ChrPtr(Buf)); + + Buf2 = NewStrBuf(); + do + { + HaveNextTokenF = StrBufExtract_NextToken(Buf2, Buf, &pCh, ','); + printf("Token: >%s< >%s<\n", ChrPtr(Buf2), pCh); + CountTokens++; + HaveNextToken = StrBufHaveNextToken(Buf2, &pCh); + CU_ASSERT(HaveNextToken == 1); + + CU_ASSERT(CountTokens < 7); + } + while (HaveNextTokenF); +} + + + static void testSuccessAssertTrue(void) { CU_ASSERT_TRUE(CU_TRUE); @@ -245,6 +273,8 @@ static void AddStrBufSimlpeTests(void) pGroup = CU_add_suite("TestStringBufSimpleAppenders", NULL, NULL); pTest = CU_add_test(pGroup, "testCreateBuf", TestCreateBuf); + pGroup = CU_add_suite("TestStringTokenizer", NULL, NULL); + pTest = CU_add_test(pGroup, "testNextTokenizer", TestNextTokenizer); /*