* fix it some, but not all.
authorWilfried Göesgens <willi@citadel.org>
Sun, 6 Sep 2009 07:16:30 +0000 (07:16 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sun, 6 Sep 2009 07:16:30 +0000 (07:16 +0000)
libcitadel/lib/stringbuf.c
libcitadel/tests/Makefile.in
libcitadel/tests/stringbuf_test.c

index a405e77a1415331726e25d3d2f1676c3038bbbab..141c9bfed817f3a9d8ed81d66fb9ea13f9c89d33 100644 (file)
@@ -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 */
index 7081a29ff84301f33da79283dc357665de7a03ee..e222bd0b358ea9151d044d45e0e6d57771fca794 100644 (file)
@@ -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=../
index 48143b8ade57ac4bf0c03c2332b31c894360cde5..24d4ee0820df92e3854a1d4a74c0ca349197b371 100644 (file)
@@ -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);
 
 
 /*