commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r790062 - in /commons/sandbox/runtime/trunk/src/main/native: shared/string.c test/testcase.c
Date Wed, 01 Jul 2009 08:24:48 GMT
Author: mturk
Date: Wed Jul  1 08:24:48 2009
New Revision: 790062

URL: http://svn.apache.org/viewvc?rev=790062&view=rev
Log:
Fix strtok_c implmentation and add test-case

Modified:
    commons/sandbox/runtime/trunk/src/main/native/shared/string.c
    commons/sandbox/runtime/trunk/src/main/native/test/testcase.c

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/string.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/string.c?rev=790062&r1=790061&r2=790062&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Wed Jul  1 08:24:48 2009
@@ -865,17 +865,21 @@
 
 ACR_DECLARE(char *) ACR_strtok_c(char *str, int sep, char **last)
 {
-    char *sp;
-    if (!str)           /* subsequent call */
-        str = *last;    /* start where we left off */
-    if (!str)           /* no more tokens */
+    char *tok;
+
+    if (!str)                       /* subsequent call */
+        str = *last;                /* start where we left off */
+    if (!str)                       /* no more tokens */
         return NULL;
-    if ((sp = strchr(str, sep))) {
-        *sp++ = '\0';
-        *last = sp;
+    while (*str == sep)             /* skip leading delimiters */
+         str++;
+    if ((tok = strchr(str, sep))) {
+        *tok++ = '\0';
+        *last  = tok;
         return str;
     }
     else {
+        *last = NULL;
         /* Check for last empty token */
         return *str ? str : NULL;
     }
@@ -883,17 +887,21 @@
 
 ACR_DECLARE(wchar_t *) ACR_wcstok_c(wchar_t *str, int sep, wchar_t **last)
 {
-    wchar_t *sp;
-    if (!str)           /* subsequent call */
-        str = *last;    /* start where we left off */
-    if (!str)           /* no more tokens */
+    wchar_t *tok;
+
+    if (!str)                       /* subsequent call */
+        str = *last;                /* start where we left off */
+    if (!str)                       /* no more tokens */
         return NULL;
-    if ((sp = wcschr(str, (wchar_t)sep))) {
-        *sp++ = L'\0';
-        *last = sp;
+    while (*str == (wchar_t)sep)    /* skip leading delimiters */
+         str++;
+    if ((tok = wcschr(str, (wchar_t)sep))) {
+        *tok++ = L'\0';
+        *last  = tok;
         return str;
     }
     else {
+        *last = NULL;
         /* Check for last empty token */
         return *str ? str : NULL;
     }

Modified: commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testcase.c?rev=790062&r1=790061&r2=790062&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Wed Jul  1 08:24:48 2009
@@ -334,7 +334,7 @@
         a = ACR_MszStrToStringArrayA(_E, J2S(s));
     } END_WITH_CSTR(s);
 
-	return a;
+    return a;
 }
 
 ACR_JNI_EXPORT_DECLARE(jobjectArray, TestPrivate, test032)(ACR_JNISTDARGS, jstring s)
@@ -345,7 +345,26 @@
         a = ACR_MszStrToStringArrayW(_E, J2W(s));
     } END_WITH_WSTR(s);
 
-	return a;
+    return a;
+}
+
+ACR_JNI_EXPORT_DECLARE(int, TestPrivate, test033)(ACR_JNISTDARGS, jint d)
+{
+    int n = 0;
+    char buf[64];
+    char *token;
+    char *state;
+
+    token = ACR_strtok_c(buf, ' ', &state);
+    if (token) {
+        n++;
+        while ((token = ACR_strtok_c(NULL, ' ', &state))) {
+            n++;
+            if (n > 20)
+                break;
+        }
+    }
+    return n;
 }
 
 



Mime
View raw message