Defines | Functions

strings.c File Reference

GIS Library - string/chring movement functions. More...

#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <sys/types.h>
#include <grass/gis.h>
Include dependency graph for strings.c:

Go to the source code of this file.

Defines

#define NULL   0

Functions

char * G_strcpy (char *T, const char *F)
 Copies characters from the string F into the string T.
char * G_chrcpy (char *T, const char *F, int n)
 Copies characters from the string F into the string T.
char * G_strncpy (char *T, const char *F, int n)
 This function is similar to G_chrcpy() but always copies at least n characters into the string T.
char * G_strmov (char *T, const char *F)
 Copies characters from the string F (not including the terminating null character) into the string T.
char * G_chrmov (char *T, const char *F, int n)
 This copies characters from the string F (exactly n characters) into the string T.
char * G_strcat (char *T, const char *F)
 This copies characters from the string F into the string T.
char * G_chrcat (char *T, const char *F, int n)
 This function is like G_strcat() except that not more than n characters from F are appended to the end of T.
int G_strcasecmp (const char *x, const char *y)
 String compare ignoring case (upper or lower).
char * G_strstr (const char *mainString, const char *subString)
 Finds the first occurrence of the character C in the null-terminated string beginning at mainString.
char * G_strdup (const char *string)
 Copies the null-terminated string into a newly allocated string. The string is allocated using G_malloc().
char * G_strchg (char *bug, char character, char new)
 Replace all occurencies of character in string bug with new.
char * G_str_replace (char *buffer, const char *old_str, const char *new_str)
 Replace all occurencies of old_str in buffer with new_str.
int G_strip (char *buf)
 Removes all leading and trailing white space from string.
char * G_chop (char *line)
 Chop leading and trailing white spaces:
void G_str_to_upper (char *str)
 Convert string to upper case.
void G_str_to_lower (char *str)
 Convert string to lower case.
int G_str_to_sql (char *str)
 Make string SQL compliant.

Detailed Description

GIS Library - string/chring movement functions.

Todo:
merge interesting functions from ../datetime/scan.c here

(C) 1999-2008 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:
Dave Gerdes (USACERL), Michael Shapiro (USACERL), Amit Parghi (USACERL), Bernhard Reiter (Intevation GmbH, Germany) and many others

Definition in file strings.c.


Define Documentation

#define NULL   0

Function Documentation

char* G_chop ( char *  line  ) 

Chop leading and trailing white spaces:

space, \f, \n, \r, \t, \v 

modified copy of G_squeeze(); RB March 2000 <Radim.Blazek@dhv.cz>

Parameters:
line buffer to be worked on
Returns:
pointer to string

Definition at line 418 of file strings.c.

Referenced by G_parse_color_rule(), and G_str_to_color().

char* G_chrcat ( char *  T,
const char *  F,
int  n 
)

This function is like G_strcat() except that not more than n characters from F are appended to the end of T.

This function is similar to G_strcpy(), except that the characters from F are concatenated or appended to the end of T, instead of overwriting it. That is, the first character from F overwrites the null character marking the end of T.

Parameters:
[out] T target string
[in] F source string
[in] n number of character to copy
Returns:
T value

Definition at line 174 of file strings.c.

References G_chrcpy().

char* G_chrcpy ( char *  T,
const char *  F,
int  n 
)

Copies characters from the string F into the string T.

Copies just the first n characters from the string F. At the end the null terminator is written into the string T.

Parameters:
[out] T target string
[in] F source string
[in] n number of characters to copy
Returns:
T value

Definition at line 66 of file strings.c.

Referenced by G_chrcat().

char* G_chrmov ( char *  T,
const char *  F,
int  n 
)

This copies characters from the string F (exactly n characters) into the string T.

The terminating null character is not explicitly written into the string T.

Parameters:
[out] T target string
[in] F source string
[in] n number of characters to copy
Returns:
T value

Definition at line 131 of file strings.c.

char* G_str_replace ( char *  buffer,
const char *  old_str,
const char *  new_str 
)

Replace all occurencies of old_str in buffer with new_str.

Code example:

 char *name;
 name = G_str_replace ( inbuf, ".exe", "" );
 ... 
 G_free (name);
Parameters:
[in,out] buffer main string
[in] old_str string to replace
[in] new_str new string
Returns:
the newly allocated string, input buffer is unchanged

Definition at line 316 of file strings.c.

References G_strdup(), G_strstr(), and NULL.

void G_str_to_lower ( char *  str  ) 

Convert string to lower case.

Parameters:
[in,out] str pointer to string

Definition at line 466 of file strings.c.

int G_str_to_sql ( char *  str  ) 

Make string SQL compliant.

Parameters:
[in,out] str pointer to string
Returns:
number of changed characters

Definition at line 486 of file strings.c.

void G_str_to_upper ( char *  str  ) 

Convert string to upper case.

Parameters:
[in,out] str pointer to string

Definition at line 448 of file strings.c.

int G_strcasecmp ( const char *  x,
const char *  y 
)

String compare ignoring case (upper or lower).

Returning a value that has the same sign as the difference between the first differing pair of characters

Parameters:
[in] x first string to compare
[in] y second string to compare
Returns:
0 the two strings are equal
-1, 1

Definition at line 192 of file strings.c.

Referenced by G_ask_datum_name(), G_basename(), G_get_datum_by_name(), G_get_ellipsoid_by_name(), G_get_spheroid_by_name(), G_info_format(), G_parse_color_rule(), and G_str_to_color().

char* G_strcat ( char *  T,
const char *  F 
)

This copies characters from the string F into the string T.

This function is similar to G_strcpy(), except that the characters from F are concatenated or appended to the end of T, instead of overwriting it. That is, the first character from F overwrites the null character marking the end of T.

Parameters:
[out] T target string
[in] F source string
Returns:
T value

Definition at line 153 of file strings.c.

References G_strcpy().

char* G_strchg ( char *  bug,
char  character,
char  new 
)

Replace all occurencies of character in string bug with new.

Parameters:
[in,out] bug base string
[in] character character to replace
[in] new new character
Returns:
bug string

Definition at line 287 of file strings.c.

char* G_strcpy ( char *  T,
const char *  F 
)

Copies characters from the string F into the string T.

This function has undefined results if the strings overlap.

Parameters:
[out] T target string
[in] F source string
Returns:
pointer to T

Definition at line 46 of file strings.c.

Referenced by G_str_to_color(), and G_strcat().

char* G_strdup ( const char *  string  ) 

Copies the null-terminated string into a newly allocated string. The string is allocated using G_malloc().

Parameters:
[in] string the string to duplicate
Returns:
pointer to a string that is a duplicate of the string given to G_strdup().
NULL if unable to allocate the required space

Definition at line 265 of file strings.c.

References NULL.

Referenced by G_str_replace().

int G_strip ( char *  buf  ) 

Removes all leading and trailing white space from string.

Parameters:
[in,out] buf buffer to be worked on
Returns:
0

Definition at line 389 of file strings.c.

References b.

Referenced by G__check_fp_type(), G__read_cats(), G_ask_colors(), G_ask_datum_name(), G_ask_ellipse_name(), G_ask_proj_name(), G_fread_key_value(), G_get_cell_title(), G_get_dig_title(), G_put_cell_title(), G_read_color_rule(), G_set_d_raster_cat(), G_set_raster_cats_fmt(), G_set_raster_cats_title(), and G_yes().

char* G_strmov ( char *  T,
const char *  F 
)

Copies characters from the string F (not including the terminating null character) into the string T.

Parameters:
[out] T target string
[in] F source string
Returns:
T value

Definition at line 109 of file strings.c.

char* G_strncpy ( char *  T,
const char *  F,
int  n 
)

This function is similar to G_chrcpy() but always copies at least n characters into the string T.

If the length of F is more than n, then copies just the first n characters. At the end the null terminator is written into the string T.

Parameters:
[out] T target string
[in] F source string
[in] n number of characters to copy
Returns:
T value

Definition at line 90 of file strings.c.

char* G_strstr ( const char *  mainString,
const char *  subString 
)

Finds the first occurrence of the character C in the null-terminated string beginning at mainString.

Parameters:
[in] mainString string where to find sub-string
[in] subString sub-string
Returns:
a pointer to the first occurrence of subString in mainString
NULL if no occurrences are found

Definition at line 230 of file strings.c.

Referenced by G_str_replace().