Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Examples  

strings_utils.h File Reference

Go to the source code of this file.

Data Structures

struct  fields
 When a string is cut into fields, the fields are saved into a 'fields' structure. More...


Defines

#define INITIAL_NUMBER_OF_FIELD   10
 This defines the minimum number of fields to allocate. 10 should ne enough.

#define STRINGS_UTILS_HPP

Functions

char * make_one_line (char *st)
 Replace all series of '
' by one ';' and all series of spaces by one space.


int s_split (char *st, char *delimitor, struct fields *f)
 Split a string into fields.

int s_split_exact (char *st, char *delimitor, struct fields *f)
 Split a string into fields.

void free_fields (struct fields *fd)
 Free allocated memory used to put fields extracted from a string of characters.

char * get_end_of_string (char *src, char *dst, int nbcar)
 Extract everything between the string " = " and the end of the string.

char * IP2hex (char *src, char *dst, int nbcar)
 Transform a IP address "XXX.XXX.XXX.XXX" into a hexadecimal representation "HHHHHHHH".

char * post_chop (char *src)
 Delete spaces (or tabulations) at the end of a string.

char * pre_chop (char *src)
 Delete spaces (or tabulations) at the begining of a string.

char * chop (char *src)
 Delete spaces (or tabulations) at the begining and at the end of a string.

char * add_comment (char *src, char **dst)
 Replace all charater 'new line' (that is '
'), by the sequence '
#'.


char * get_config_value (char *buffer, char *delim)
 Extract a field's value from a configuration file.

char * replace_tag_by_integer (char *src, char *tag, int value)
 Replace a tag by an integer in a string.

unsigned int string2unsigned_int (char *st, int *error)
 Convert a string of characters into an 'unsigned int'.

int string2int (char *st, int *error)
 Convert a string of characters into an 'int'.

time_t string2time_t (char *st, int *error)
 Convert a string of characters into a 'time_t'.

int is_integer (char *st)
 Test if a string of characters represents an interger.

int is_hexa (char *st)
 Test if a string of characters represents a hexadecimal.

int is_ip_address (char *st)
 Test if a string of characters represents an IP address.

int ip_address_to_num (char *st, unsigned char *num)
 Convert an IPV4 address to its numerical equivalent.


Detailed Description

Header file for strings_utils.c

Definition in file strings_utils.h.


Function Documentation

char* add_comment char *    src,
char **    dst
 

Replace all charater 'new line' (that is '
'), by the sequence '
#'.

Parameters:
src Pointer to the string to convert into comment.
dst Pointer to a pointer that will be used to store the resulting string.
Returns:
The function returns a pointer to the resulting string, or NULL if an error occured.
Warning:
The returned pointer has been allocated using 'malloc()'. So you must free the allocated memory yourself (using 'free()').

Definition at line 488 of file strings_utils.c.

char* chop char *    src
 

Delete spaces (or tabulations) at the begining and at the end of a string.

Parameters:
src Pointer to the string to parse.
Returns:
The function returns a pointer to 'src', or NULL if an error occured.
Warning:
The string 'src' is modified.

Definition at line 473 of file strings_utils.c.

References post_chop(), and pre_chop().

Referenced by get_config_value().

void free_fields struct fields   fd
 

Free allocated memory used to put fields extracted from a string of characters.

Parameters:
fd Pointer to a structure 'fields'.
Warning:
You should call this function after a call to s_split(). Please note that if s_split() failes, then you don't have to free the resulting structure 'fields'. But you can do it, it won't harm.

Definition at line 317 of file strings_utils.c.

References fields::number_of_fields, fields::size, and fields::tabs.

Referenced by date2timestamp(), IP2hex(), ip_address_to_num(), and is_ip_address().

char* get_config_value char *    buffer,
char *    delim
 

Extract a field's value from a configuration file.

Parameters:
buffer Pointer to a NULL terminated string of characters that contains the line extracted from the configuration file.
delim Pointer to a NULL terminated string of characters that defines the delimitor between the field' label and the field's value.
Returns:
The function returns a pointer to the field's value. If an error occured, the function returns NULL.

Definition at line 532 of file strings_utils.c.

References chop().

char* get_end_of_string char *    src,
char *    dst,
int    nbcar
 

Extract everything between the string " = " and the end of the string.

Parameters:
src Pointer to the string to parse.
dst Pointer to a memory location used to put the extracted string.
nbcar Maximum number of characters the function can put into 'dst'.
Returns:
The function return a pointer to 'dst', or NULL if an error occured.

Definition at line 335 of file strings_utils.c.

char* IP2hex char *    src,
char *    dst,
int    nbcar
 

Transform a IP address "XXX.XXX.XXX.XXX" into a hexadecimal representation "HHHHHHHH".

Parameters:
src Pointer to a string of characters that contains an IP address written as "XXX.XXX.XXX.XXX".
dst Pointer to a memory location used to put the resulting IP address in hexadecimal notation.
nbcar Maximum number of characters the function can put into 'dst'.
Returns:
The function returns a pointer to 'dst', or NULL if an error occured.

Definition at line 365 of file strings_utils.c.

References bin2hex_hexa, free_fields(), s_split(), and fields::tabs.

int ip_address_to_num char *    st,
unsigned char *    num
 

Convert an IPV4 address to its numerical equivalent.

Parameters:
st Pointer to a zero terminated string of characters that represents the IP address (X.X.X.X).
num Pointer to a array of - at least - 4 unsigned char.
Returns:
The function returns 0 if the operation was successfull, 1 otherwise.

Definition at line 825 of file strings_utils.c.

References free_fields(), is_ip_address(), fields::number_of_fields, s_split(), and fields::tabs.

int is_hexa char *    st
 

Test if a string of characters represents a hexadecimal.

Parameters:
st Pointer to a NULL terminated string of characters that should represent a hexadecimal.
Returns:
The function returns 0 if the string 'st' represents an interger. Otherwise, it returns 1.

Definition at line 737 of file strings_utils.c.

References char2hex.

int is_integer char *    st
 

Test if a string of characters represents an interger.

Parameters:
st Pointer to a NULL terminated string of characters that should represent an integer.
Returns:
The function returns 0 if the string 'st' represents an interger. Otherwise, it returns 1.

Definition at line 710 of file strings_utils.c.

References char2int.

int is_ip_address char *    st
 

Test if a string of characters represents an IP address.

Parameters:
st Pointer to a zero terminated string of characters that might represents an IP address.
Returns:
The function return 0 is 'st' represents an IP address. Otherwise, the function returns 1.
Warning:
An error code 1 could also mean "Out of memory". But it should not happen.

Definition at line 765 of file strings_utils.c.

References free_fields(), fields::number_of_fields, s_split(), string2int(), and fields::tabs.

Referenced by ip_address_to_num().

char* make_one_line char *    st
 

Replace all series of '
' by one ';' and all series of spaces by one space.

Parameters:
st Pointer to a zero terminated string of characters that represents the original string.
Returns:
Upon successful completion the function returns a pointer to a zero terminated string of charaters that represents the resulting string. If an error occured (no memory), then the function returns NULL.
Warning:
The returned pointer points to a memory location allocated within the function. Therefore you MUST free it (using free()). Before you free it, make sure that the pointer is not NULL.

Definition at line 19 of file strings_utils.c.

char* post_chop char *    src
 

Delete spaces (or tabulations) at the end of a string.

Parameters:
src pointer to the string to parser.
Returns:
The function returns a pointer to 'src'.
Warning:
The string 'src' is modified.

Definition at line 414 of file strings_utils.c.

Referenced by chop().

char* pre_chop char *    src
 

Delete spaces (or tabulations) at the begining of a string.

Parameters:
src Pointer to a string of of characters that contains the string to parser.
Returns:
value the function returns a pointer to 'src', or NULL if an error occured.
Warning:
the string 'src' is modified.

Definition at line 437 of file strings_utils.c.

Referenced by chop().

char* replace_tag_by_integer char *    src,
char *    tag,
int    value
 

Replace a tag by an integer in a string.

Parameters:
src Pointer to NULL terminated string of characters that contains the tag to replace.
tag Tag to replace.
value Integer value that will replace the tag.
Returns:
The function returns a pointer to the resulting string of characters. If an error occured, then the function returns a NULL pointer (this means that the program is running out of memory).

Definition at line 564 of file strings_utils.c.

References INTEGER_STR_MAX_SIZE.

int s_split char *    st,
char *    delimitor,
struct fields   f
 

Split a string into fields.

Parameters:
st Pointer to a string of characters to split.
delimitor Pointer to a string of characters that defines the delimitor used to separate fieds.
f Pointer to a structure 'fields' that contains the fields extracted from the string 'st'.
Returns:
The function returns the number of fields extracted. If an error occurs, the the function returns -1.
Warning:
  • The structure 'f' contains elements that have been allocated within the function. So you must free these elements when you don't need them any more. To do this, you should use the function 'free_fields()'.
  • For this function, 2 (or more) delimitors in a row are seen as one and oly one delimitor. Example: the string "A;;;B" has 2 fields ("A" and "B"), not 4 (assuming that the delimitor is the character ";").

Definition at line 94 of file strings_utils.c.

References INITIAL_NUMBER_OF_FIELD, fields::number_of_fields, fields::size, and fields::tabs.

Referenced by date2timestamp(), IP2hex(), ip_address_to_num(), and is_ip_address().

int s_split_exact char *    st,
char *    delimitor,
struct fields   f
 

Split a string into fields.

Parameters:
st Pointer to a string of characters to split.
delimitor Pointer to a string of characters that defines the delimitor used to separate fieds.
f Pointer to a structure 'fields' that contains the fields extracted from the string 'st'.
Returns:
The function returns the number of fields extracted. If an error occurs, the the function returns -1.
Warning:
  • The structure 'f' contains elements that have been allocated within the function. So you must free these elements when you don't need them any more. To do this, you should use the function 'free_fields()'.
  • This function does NOT behave like the function s_split(). Example: the string "A;;;B" has 4 fields ("A", "", "" and "B"), not 2 (assuming that the delimitor is the character ";").

Definition at line 180 of file strings_utils.c.

References INITIAL_NUMBER_OF_FIELD, fields::number_of_fields, fields::size, and fields::tabs.

int string2int char *    st,
int *    error
 

Convert a string of characters into an 'int'.

Parameters:
st Pointer to a NULL terminated string of characters that will be converted into "int'.
error Pointer to an interger used to signal an error.
Returns:
The function returns the value represented bu the string 'st' (if sucess, then 'error' is equal to 0). Please note that if an error occures, then the returned value is equal to -1 (in this case 'error' is equal to 1).

Definition at line 678 of file strings_utils.c.

References char2int.

Referenced by is_ip_address().

time_t string2time_t char *    st,
int *    error
 

Convert a string of characters into a 'time_t'.

Parameters:
st Pointer to a NULL terminated string of characters that will be converted into "time_t".
error Pointer to an interger used to signal an error.
Returns:
The function returns the value represented bu the string 'st' (if sucess, then 'error' is equal to 0). Please note that if an error occures, then the returned value is equal to -1 (all in binary - in this case 'error' is equal to 1).

Definition at line 649 of file strings_utils.c.

References char2int.

Referenced by test_tz_conf().

unsigned int string2unsigned_int char *    st,
int *    error
 

Convert a string of characters into an 'unsigned int'.

Parameters:
st Pointer to a NULL terminated string of characters that will be converted into "u_int'.
error Pointer to an interger used to signal an error.
Returns:
The function returns the value represented bu the string 'st' (if sucess, then 'error' is equal to 0). Please note that if an error occures, then the returned value is equal to -1 (all in binary - in this case 'error' is equal to 1).

Definition at line 618 of file strings_utils.c.

References char2int.


Generated on Thu Apr 3 16:23:47 2003 for Common_C_libraries by doxygen1.3-rc1