GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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.

Macros

#define NULL   0
 

Functions

char * G_strcpy (char *T, const char *F)
 Copies characters from the string F into the string T. More...
 
char * G_chrcpy (char *T, const char *F, int n)
 Copies characters from the string F into the string T. More...
 
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. More...
 
char * G_strmov (char *T, const char *F)
 Copies characters from the string F (not including the terminating null character) into the string T. More...
 
char * G_chrmov (char *T, const char *F, int n)
 This copies characters from the string F (exactly n characters) into the string T. More...
 
char * G_strcat (char *T, const char *F)
 This copies characters from the string F into the string T. More...
 
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. More...
 
int G_strcasecmp (const char *x, const char *y)
 String compare ignoring case (upper or lower) More...
 
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. More...
 
char * G_strdup (const char *string)
 Copies the null-terminated string into a newly allocated string. The string is allocated using G_malloc(). More...
 
char * G_strchg (char *bug, char character, char new)
 Replace all occurencies of character in string bug with new. More...
 
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. More...
 
int G_strip (char *buf)
 Removes all leading and trailing white space from string. More...
 
char * G_chop (char *line)
 Chop leading and trailing white spaces: More...
 
void G_str_to_upper (char *str)
 Convert string to upper case. More...
 
void G_str_to_lower (char *str)
 Convert string to lower case. More...
 
int G_str_to_sql (char *str)
 Make string SQL compliant. More...
 

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.

Macro Definition Documentation

#define NULL   0

Definition at line 26 of file strings.c.

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.nosp@m..Bla.nosp@m.zek@d.nosp@m.hv.c.nosp@m.z

Parameters
linebuffer to be worked on
Returns
pointer to string

Definition at line 418 of file strings.c.

Referenced by dig_read_frmt_ascii(), G_parse_color_rule(), G_str_to_color(), get_key_data(), read_coor(), read_file(), S_read(), Vect_get_column_names(), Vect_get_column_names_types(), Vect_get_column_types(), and Vect_read_dblinks().

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]Ttarget string
[in]Fsource string
[in]nnumber 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]Ttarget string
[in]Fsource string
[in]nnumber 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]Ttarget string
[in]Fsource string
[in]nnumber 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]buffermain string
[in]old_strstring to replace
[in]new_strnew string
Returns
the newly allocated string, input buffer is unchanged

Definition at line 316 of file strings.c.

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

Referenced by db_read_dbmscap(), escape_tcl_string(), and Vect_subst_var().

void G_str_to_lower ( char *  str)

Convert string to lower case.

Parameters
[in,out]strpointer to string

Definition at line 466 of file strings.c.

int G_str_to_sql ( char *  str)

Make string SQL compliant.

Parameters
[in,out]strpointer to string
Returns
number of changed characters

Definition at line 486 of file strings.c.

References count.

void G_str_to_upper ( char *  str)

Convert string to upper case.

Parameters
[in,out]strpointer 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]xfirst string to compare
[in]ysecond string to compare
Returns
0 the two strings are equal
-1, 1

Definition at line 192 of file strings.c.

Referenced by class_apply_algorithm(), clean_dir(), D_translate_color(), db__copy_table(), db_get_column(), db_table_exists(), dig_file_load(), dig_read_frmt_ascii(), F_generate(), 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(), G_str_to_color(), GPJ_ask_datum_params(), GPJ_get_datum_by_name(), GPJ_get_datum_transform_by_name(), GPJ_get_ellipsoid_by_name(), GPJ_grass_to_osr(), GPJ_osr_to_grass(), LOC_open_driver(), PNG_Graph_set(), PS_Graph_set(), read_image(), S_read(), submit(), Vect_legal_filename(), and write_image().

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]Ttarget string
[in]Fsource string
Returns
T value

Definition at line 153 of file strings.c.

References G_strcpy().

Referenced by G_site_format(), and read_ellipsoid_table().

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

Replace all occurencies of character in string bug with new.

Parameters
[in,out]bugbase string
[in]charactercharacter to replace
[in]newnew 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]Ttarget string
[in]Fsource string
Returns
pointer to T

Definition at line 46 of file strings.c.

Referenced by G_site_format(), G_str_to_color(), G_strcat(), GVL_get_volname(), and GVL_isosurf_get_att().

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]stringthe 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 F_generate(), and G_str_replace().

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]Ttarget string
[in]Fsource 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]Ttarget string
[in]Fsource string
[in]nnumber of characters to copy
Returns
T value

Definition at line 90 of file strings.c.

Referenced by G__oldsite_get(), and G_site_get().

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]mainStringstring where to find sub-string
[in]subStringsub-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.

References NULL, and forms::q.

Referenced by db_read_dbmscap(), G_oldsite_describe(), G_str_replace(), and GPJ_grass_to_osr().