Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 37893 invoked from network); 1 Jul 2009 08:49:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 1 Jul 2009 08:49:13 -0000 Received: (qmail 79113 invoked by uid 500); 1 Jul 2009 08:49:24 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 79027 invoked by uid 500); 1 Jul 2009 08:49:23 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 79018 invoked by uid 99); 1 Jul 2009 08:49:23 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Jul 2009 08:49:23 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Jul 2009 08:49:21 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id ABED423888E3; Wed, 1 Jul 2009 08:49:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r790073 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr_string.h shared/string.c test/testcase.c Date: Wed, 01 Jul 2009 08:49:01 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090701084901.ABED423888E3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mturk Date: Wed Jul 1 08:49:01 2009 New Revision: 790073 URL: http://svn.apache.org/viewvc?rev=790073&view=rev Log: Add API for geting the number of tokens without modifying the string in advance Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h 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/include/acr_string.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h?rev=790073&r1=790072&r2=790073&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h Wed Jul 1 08:49:01 2009 @@ -187,6 +187,24 @@ ACR_DECLARE(wchar_t *) ACR_wcstok_c(wchar_t *str, int sep, wchar_t **last); /** + * Determine the number of tokens in string without + * modifying it. + * @param str string to tokenize. + * @param sep Token delimiting character. + * @return Number of tokens. + */ +ACR_DECLARE(int) ACR_StrTokensA(const char *str, int sep); + +/** + * Determine the number of tokens in string without + * modifying it. Unicode version of the function. + * @param str string to tokenize. + * @param sep Token delimiting character. + * @return Number of tokens. + */ +ACR_DECLARE(int) ACR_StrTokensW(const wchar_t *str, int sep); + +/** * Count the number of string parts in multi string. Ansi version. *

Multi strings are zero separated double zero * terminated strings 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=790073&r1=790072&r2=790073&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:49:01 2009 @@ -885,6 +885,44 @@ } } +ACR_DECLARE(int) ACR_StrTokensA(const char *str, int sep) +{ + int cnt = 1; + + while (*str && *str == sep) /* skip leading delimiters */ + str++; + while (*str) { + if (*str == sep) { + while (*str == sep) + str++; + if (*str) + cnt++; + } + else + str++; + } + return cnt; +} + +ACR_DECLARE(int) ACR_StrTokensW(const wchar_t *str, int sep) +{ + int cnt = 1; + + while (*str && *str == (wchar_t)sep) /* skip leading delimiters */ + str++; + while (*str) { + if (*str == sep) { + while (*str == sep) + str++; + if (*str) + cnt++; + } + else + str++; + } + return cnt; +} + ACR_DECLARE(wchar_t *) ACR_wcstok_c(wchar_t *str, int sep, wchar_t **last) { wchar_t *tok; 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=790073&r1=790072&r2=790073&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:49:01 2009 @@ -350,12 +350,14 @@ ACR_JNI_EXPORT_DECLARE(int, TestPrivate, test033)(ACR_JNISTDARGS, jint d) { + int e; int n = 0; char buf[64]; char *token; char *state; sprintf(buf, " 1 22 3333 4"); + e = ACR_StrTokensA(buf, ' '); token = ACR_strtok_c(buf, ' ', &state); if (token) { n++; @@ -365,7 +367,7 @@ break; } } - return n; + return n == e ? n : 0; }