[GRASS-SVN] r58417 - grass/trunk/lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Dec 8 15:05:56 PST 2013
Author: martinl
Date: 2013-12-08 15:05:56 -0800 (Sun, 08 Dec 2013)
New Revision: 58417
Modified:
grass/trunk/lib/gis/token.c
Log:
libgis: tokenize string using strtok()
Modified: grass/trunk/lib/gis/token.c
===================================================================
--- grass/trunk/lib/gis/token.c 2013-12-08 21:58:21 UTC (rev 58416)
+++ grass/trunk/lib/gis/token.c 2013-12-08 23:05:56 UTC (rev 58417)
@@ -4,7 +4,7 @@
\brief GIS Library - Tokenize strings
- (C) 2001-2008, 2011 by the GRASS Development Team
+ (C) 2001-2008, 2011-2013 by the GRASS Development Team
This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.
@@ -17,6 +17,7 @@
#include <grass/gis.h>
static char **tokenize(const char *, const char *, const char *);
+static char **tokenize_strtok(const char *, const char *);
/*!
\brief Tokenize string
@@ -46,7 +47,7 @@
*/
char **G_tokenize(const char *buf, const char *delim)
{
- return tokenize(buf, delim, NULL);
+ return tokenize_strtok(buf, delim);
}
/*!
@@ -85,6 +86,31 @@
return tokenize(buf, delim, valchar);
}
+/* strtok-based version of tokenize subroutine */
+char **tokenize_strtok(const char *buf, const char *delim)
+{
+ int i;
+ char **tokens;
+ char *p, *ptr;
+
+ p = G_store(buf);
+
+ i = 0;
+ tokens = (char **) G_malloc (sizeof (char *));
+ ptr = strtok(p, delim);
+ tokens[i] = ptr;
+ i++;
+ while(ptr != NULL) {
+ tokens = (char **) G_realloc(tokens, sizeof(char*) * (i + 1));
+ ptr = strtok(NULL, delim);
+ tokens[i] = ptr;
+ i++;
+ }
+
+ return tokens;
+}
+
+/* own version of tokenize subroutine */
char **tokenize(const char *buf, const char *delim, const char *inchar)
{
int i, invalue;
More information about the grass-commit
mailing list