s = *pStart;
/* start to find the next token */
- while ((s < EndBuffer) && !IsEmptyStr(s))
+ while ((s < EndBuffer) &&
+ (!IsEmptyStr(s)) &&
+ (current_token == 0) )
{
if (*s == separator)
{
++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 */
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);
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);
/*