Loading...
Searching...
No Matches
token.c File Reference

GIS Library - Tokenize strings. More...

`#include <stdlib.h>`
`#include <string.h>`
`#include <grass/gis.h>`
`#include <grass/glocale.h>`
Include dependency graph for token.c:

Go to the source code of this file.

## Functions

char ** | G_tokenize (const char *buf, const char *delim)
| Tokenize string.
char ** | G_tokenize2 (const char *buf, const char *delim, const char *valchar)
| Tokenize string.
int | G_number_of_tokens (char **tokens)
| Return number of tokens.
void | G_free_tokens (char **tokens)
| Free memory allocated to tokens.

## Detailed Description

GIS Library - Tokenize strings.

(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.

Author
  USA CERL and others

Definition in file token.c.

## Function Documentation

## G_free_tokens()

void G_free_tokens | ( | char ** | tokens | ) |

Free memory allocated to tokens.

Note: G_free_tokens() must be called when finished with tokens to release memory.

Parameters

  [out] | tokens |

Definition at line 197 of file token.c.

References G_free(), and NULL.

Referenced by check_create_export_opts(), check_create_import_opts(), G_get_window(), G_parser(), and GPJ_grass_to_osr2().

## G_number_of_tokens()

int G_number_of_tokens | ( | char ** | tokens | ) |

Return number of tokens.

Parameters

  tokens |

Returns
  number of tokens

Definition at line 178 of file token.c.

References NULL.

Referenced by G_set_keywords(), and GPJ_grass_to_osr2().

## G_tokenize()

char ** G_tokenize | ( | const char * | buf,
|  | const char * | delim )

Tokenize string.

Given a string, buf, turn delimiter, delim, into '\0' (NULL) and place pointers to tokens in tokens. buf must not contain a new line (
). delim may consist of more than one character. G_free_tokens() must be called when finished with tokens to release memory.

Example:

char **tokens;
int ntok, i;
tokens = G_tokenize(buf, " |:,");
ntok = G_number_of_tokens(tokens);
for (i=0; i < ntok; i++) {
G_debug(1, "%d=[%s]", i, tokens[i]);
}
G_free_tokens(tokens);
G_debug
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition debug.c:66
G_free_tokens
void G_free_tokens(char **tokens)
Free memory allocated to tokens.
Definition token.c:197
G_tokenize
char ** G_tokenize(const char *buf, const char *delim)
Tokenize string.
Definition token.c:47
G_number_of_tokens
int G_number_of_tokens(char **tokens)
Return number of tokens.
Definition token.c:178

Parameters

  buf | input string
  delim | string delimiter

Returns
  pointer to string token

Definition at line 47 of file token.c.

References NULL.

Referenced by check_create_export_opts(), check_create_import_opts(), check_mapset_in_layer_name(), G_get_window(), G_parser(), G_set_keywords(), and GPJ_grass_to_osr2().

## G_tokenize2()

char ** G_tokenize2 | ( | const char * | buf,
|  | const char * | delim,
|  | const char * | valchar )

Tokenize string.

This function behaves similarly to G_tokenize().

It introduces valchar which defines borders of token. Within token delim is ignored.

Example:

char *str = "a,'b,c',d";
char **tokens1, **tokens2;
int ntok1, ntok2;
tokens1 = G_tokenize(str, ",");
ntok1 = G_number_of_tokens(tokens1);
tokens1 = G_tokenize2(str, ",", "'");
ntok2 = G_number_of_tokens(tokens2);
G_tokenize2
char ** G_tokenize2(const char *buf, const char *delim, const char *valchar)
Tokenize string.
Definition token.c:83

In this example ntok1 will be 4, ntok2 only 3, i.e. { "a", "'b, c'", "d"}

Parameters

  buf | input string
  delim | string delimiter
  valchar | character defining border of token

Returns
  pointer to string token

Definition at line 83 of file token.c.