TaPAS  0.2
Macros | Typedefs | Functions
ccl-string.h File Reference

Module gathering routines frequently used for the manipulation of string. More...

#include <ccl/ccl-common.h>
#include <ccl/ccl-memory.h>

Go to the source code of this file.

Macros

#define ccl_string_compare   ((ccl_compare_func *) strcmp)
 String comparison. More...
 
#define ccl_string_cmp   strcmp
 String comparison. More...
 

Typedefs

typedef char * ccl_ustring
 Alias type for strings that are stored in an internal dictionary and then can be used as identifiers and can be compared by pointers.
 

Functions

unsigned int ccl_string_hash (const void *ptr)
 Hashes the string pointed by ptr. More...
 
void ccl_string_delete (void *ptr)
 Deletion function for a string.
 
int ccl_string_equals (const void *str1, const void *str2)
 Equality checking for strings. More...
 
char * ccl_string_dup (const char *s)
 Duplicates the string s. More...
 
char * ccl_string_format_new (const char *fmt,...)
 Allocates a formatted string. More...
 
char * ccl_string_format_new_va (const char *fmt, va_list pa)
 Allocates a formatted string. More...
 
void ccl_string_format (char **dst, size_t *size, const char *fmt,...)
 Allocates a formatted string. More...
 
void ccl_string_format_va (char **dst, size_t *size, const char *fmt, va_list pa)
 Allocates a formatted string. More...
 
void ccl_string_format_append (char **dst, const char *fmt,...)
 Appends a formatted string to *dst. More...
 
void ccl_string_format_append_va (char **dst, const char *fmt, va_list pa)
 Appends a formatted string to *dst. More...
 
int ccl_string_parse_int (const char *s)
 Interprets s as an integer value. More...
 
int ccl_string_parse_boolean (const char *s)
 Interprets s as a Boolean value. More...
 
ccl_ustring ccl_string_make_unique (const char *s)
 Creates a unique string from the string s. More...
 
ccl_ustring ccl_string_make_unique_from_int (int i)
 Creates a unique string from an integer i. More...
 

Detailed Description

Module gathering routines frequently used for the manipulation of string.

Definition in file ccl-string.h.

Macro Definition Documentation

#define ccl_string_cmp   strcmp

String comparison.

Alias for strcmp

Definition at line 92 of file ccl-string.h.

#define ccl_string_compare   ((ccl_compare_func *) strcmp)

String comparison.

This function compares str1 and str2. This function returns a value less than, equal to or greater than zero if str1 is, respectively, less than, equal to or greater than str2. This function can be used where a pointer to a ccl_compare_func is required.

Parameters
str1first string arg
str2second string arg
Precondition
str1 != NULL &&
str2 != NULL
Return values
<0 if str1 < str2
==0 if str1 == str2
>0 if str1 > str2

Definition at line 85 of file ccl-string.h.

Function Documentation

char* ccl_string_dup ( const char *  s)

Duplicates the string s.

Parameters
sthe string to duplicate
Precondition
s != NULL
Returns
a copy of s
int ccl_string_equals ( const void *  str1,
const void *  str2 
)

Equality checking for strings.

This function checks if str1 and str2 are equal. This function can be used where a pointer to a ccl_equals_func is required.

Parameters
str1first string arg
str2second string arg
Precondition
str1 != NULL
str2 != NULL
Returns
a non-null value if str1 and str2 are equal.
void ccl_string_format ( char **  dst,
size_t *  size,
const char *  fmt,
  ... 
)

Allocates a formatted string.

This function creates a formatted string using fmt specifications in the same way than ccl_string_format_new. The resulting string is stored in the buffer pointed by dst. The function assumes that *size bytes can be stored into *dst; if size is NULL the buffer size is assumed to be 0. If *dst has a size inferior to the number of bytes required to store the formatted string then the buffer is resized and *size is changed according to the new size. *dst can be NULL.

Parameters
dsta pointer to the string that should receive the result.
sizea pointer to an integer that should receive the new size of the buffer pointed by *dst. This parameter can be NULL.
fmtthe formatting string
Precondition
dst != NULL
fmt != NULL
void ccl_string_format_append ( char **  dst,
const char *  fmt,
  ... 
)

Appends a formatted string to *dst.

This function creates a formatted string using fmt specifications in the same way than ccl_string_format_new. The resulting string is appended to the string pointed by dst. *dst can be NULL in which case it is considered as an empty string.

Parameters
dsta pointer to the string that should receive the result.
fmtthe formatting string
Precondition
fmt != NULL
void ccl_string_format_append_va ( char **  dst,
const char *  fmt,
va_list  pa 
)

Appends a formatted string to *dst.

This function behaves like ccl_string_format_append but variable arguments are replaced by a va_list.

Parameters
dsta pointer to the string that should receive the result.
fmtthe formatting string
pathe list of arguments
Precondition
fmt != NULL
char* ccl_string_format_new ( const char *  fmt,
  ... 
)

Allocates a formatted string.

This function allocates a new string and fills it using formatting informations contained in fmt. The syntax of fmt is the one of printf-like functions.

Parameters
fmtthe formatting string
Precondition
fmt != NULL

return a formatted string.

char* ccl_string_format_new_va ( const char *  fmt,
va_list  pa 
)

Allocates a formatted string.

This function makes the same work than ccl_string_format_new but variable arguments are replaced by a va_list; thus it can be called by funtions that use variable arguments (i.e. ...).

Parameters
fmtthe formatting string
pathe list of arguments
Precondition
fmt != NULL return a formatted string.
void ccl_string_format_va ( char **  dst,
size_t *  size,
const char *  fmt,
va_list  pa 
)

Allocates a formatted string.

This function behaves like ccl_string_format but variable arguments are replaced by a va_list.

Parameters
dsta pointer to the string that should receive the result.
sizea pointer to an integer that should receive the new size of the buffer pointed by *dst. This parameter can be NULL.
fmtthe formatting string
pathe list of arguments
Precondition
dst != NULL
fmt != NULL
unsigned int ccl_string_hash ( const void *  ptr)

Hashes the string pointed by ptr.

Parameters
ptrthe string to hash ccl_pre ptr != NULL
Returns
a hashed value of ptr.
ccl_ustring ccl_string_make_unique ( const char *  s)

Creates a unique string from the string s.

A unique string is just a string stored in an internal dictionary. All unique string can then be compared by addresses instead of the lexicographical order (e.g. using strcmp).

The function manages an internal dictionary. If the string s exists in that dictionary the function returns the pointer to the stored string; else, a copy of s is stored in the dictionary and returned.

Parameters
sthe string made unique
Precondition
s!= NULL
Returns
a unique string from the string s
ccl_ustring ccl_string_make_unique_from_int ( int  i)

Creates a unique string from an integer i.

Parameters
ithe integer transformed into a unique string
Returns
a unique string from the integer i
int ccl_string_parse_boolean ( const char *  s)

Interprets s as a Boolean value.

If s is equal to one of the following strings true, enabled, TRUE, ENABLED or 1, the function returns a non-null value. If s is NULL then the function returns 0.

Parameters
sthe string to parse
Returns
a non-null value if s describe a Boolean value equivalent to true.
int ccl_string_parse_int ( const char *  s)

Interprets s as an integer value.

The function parses the longest prefix of s that matches the regexp of a signed integer: 0|-([0-9]+).

If s is NULL then the function returns 0.

Parameters
sthe string to parse
Returns
the integer encoded by s