add PL_strtok_r

This commit is contained in:
Michael Jerris 2012-12-17 22:50:34 -05:00
parent 86487ed459
commit a4923bbe54
8 changed files with 104 additions and 6 deletions

View File

@ -125,7 +125,7 @@ core/src-common/util_ios_queue.c \
core/src-common/util_parse.c \
core/src-common/util_string.c
CPR_COMMON_SRC = cpr/common/cpr_string.c
CPR_COMMON_SRC = cpr/common/cpr_string.c cpr/common/strtok.c
CPR_DARWIN_SRC = \
cpr/darwin/cpr_darwin_errno.c \
@ -342,6 +342,7 @@ cpr/darwin/cpr_darwin_timers.h \
cpr/darwin/cpr_darwin_tst.h \
cpr/darwin/cpr_darwin_types.h \
cpr/include/cpr.h \
cpr/include/plstr.h \
cpr/include/cpr_assert.h \
cpr/include/cpr_debug.h \
cpr/include/cpr_errno.h \

View File

@ -22,7 +22,7 @@
#include "platform_api.h"
#include "vcm.h"
//#include "prlog.h"
//#include "plstr.h"
#include "plstr.h"
#include "sdp_private.h"
//TODO Need to place this in a portable location

View File

@ -5,7 +5,7 @@
#include <errno.h>
#include <limits.h>
//#include "plstr.h"
#include "plstr.h"
#include "sdp_os_defs.h"
#include "sdp.h"
#include "sdp_private.h"

View File

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//#include "plstr.h"
#include "plstr.h"
#include "cpr_types.h"
#include "cpr_time.h"
#include "cpr_stdio.h"

View File

@ -15,7 +15,7 @@
#include <errno.h>
#include <limits.h>
//#include "plstr.h"
#include "plstr.h"
#include "cpr_types.h"
#include "cpr_stdio.h"
#include "cpr_stdlib.h"

View File

@ -9,7 +9,7 @@
* CCAPI callids, conversion from CCAPI to SIP cause codes and the
* like.
*/
//#include "plstr.h"
#include "plstr.h"
#include "cpr_types.h"
#include "cpr_stdlib.h"
#include "cpr_string.h"

View File

@ -0,0 +1,55 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "plstr.h"
char * PL_strtok_r(char *s1, const char *s2, char **lasts)
{
const char *sepp;
int c, sc;
char *tok;
if( s1 == NULL )
{
if( *lasts == NULL )
return NULL;
s1 = *lasts;
}
for( ; (c = *s1) != 0; s1++ )
{
for( sepp = s2 ; (sc = *sepp) != 0 ; sepp++ )
{
if( c == sc )
break;
}
if( sc == 0 )
break;
}
if( c == 0 )
{
*lasts = NULL;
return NULL;
}
tok = s1++;
for( ; (c = *s1) != 0; s1++ )
{
for( sepp = s2; (sc = *sepp) != 0; sepp++ )
{
if( c == sc )
{
*s1++ = '\0';
*lasts = s1;
return tok;
}
}
}
*lasts = NULL;
return tok;
}

View File

@ -0,0 +1,42 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef _plstr_h
#define _plstr_h
#include "cpr_types.h"
__BEGIN_DECLS
/*
* PL_strtok_r
*
* Splits the string s1 into tokens, separated by one or more characters
* from the separator string s2. The argument lasts points to a
* user-supplied char * pointer in which PL_strtok_r stores information
* for it to continue scanning the same string.
*
* In the first call to PL_strtok_r, s1 points to a string and the value
* of *lasts is ignored. PL_strtok_r returns a pointer to the first
* token, writes '\0' into the character following the first token, and
* updates *lasts.
*
* In subsequent calls, s1 is null and lasts must stay unchanged from the
* previous call. The separator string s2 may be different from call to
* call. PL_strtok_r returns a pointer to the next token in s1. When no
* token remains in s1, PL_strtok_r returns null.
*/
char * PL_strtok_r(char *s1, const char *s2, char **lasts);
/*
* Things not (yet?) included: strspn/strcspn, strsep.
* memchr, memcmp, memcpy, memccpy, index, rindex, bcmp, bcopy, bzero.
* Any and all i18n/l10n stuff.
*/
__END_DECLS
#endif /* _plstr_h */