str_functions.h File Reference

String processing functions. More...

#include <string.h>
#include <glib.h>

Go to the source code of this file.

Data Structures

struct  StringList
 StringList is a structure that stores a list of constant strings. More...

Functions

StringListstringList_new ()
 Allocate space for a StringList instance.
void stringList_clear (StringList *sList)
 Clear all content of Stringlist.
int stringList_find_string (StringList *sList, const char *str)
 Find a string in StringList.
char ** stringList_to_charPointerPointer (StringList *sList)
 Return a char pointer pointer (char **) which points to the list of strings.
const char * stringList_index (StringList *sList, guint index)
 Return the string at the given index.
guint stringList_insert (StringList *sList, const char *str)
 Insert a string to StringList.
guint stringList_insert_const (StringList *sList, const char *str)
 Insert a constant string to StringList.
void stringList_free (StringList *sList)
 Free the StringList instance.
char * initString (char *str)
 Initialize the string by setting the first char to 0x0.
gboolean isEmptyString (const char *str)
 Check whether the string is NULL or have 0 length.
void string_trim (char *str)
 Trim the leading and trailing whitespace of the string.
char * subString (char *buf, const char *str, int beginIndex, int length)
 Returns a substring of the given string.
char * ucs4_to_utf8 (gunichar ucs4_code)
 Convert UCS-4 to UTF-8 string.
gunichar * utf8_to_ucs4 (const char *utf8_str)
 Convert UTF-8 string to UCS-4 (gunichar).
char * utf8_concat_ucs4 (char *utf8_str, gunichar ucs4_code)
 Concatenate a UCS-4 (gunichar) to an UTF-8 string.
int strcmp_unsigned_signed (const unsigned char *str1, const char *str2)
 Compare between signed and unsigned char arrays.
unsigned char * signedStr_to_unsignedStr (const char *str)
 Convert the signed char string to a new allocated unsigned char string.
unsigned char * signedStr_to_unsignedStr_buffer (unsigned char *resultBuf, const char *str)
 Convert the signed char string to the unsigned char string buffer.
char * unsignedStr_to_signedStr (const unsigned char *str)
 Convert the unsigned char string to a new allocated signed char string.
char * unsignedStr_to_signedStr_buffer (char *resultBuf, const unsigned char *str)
 Convert the unsigned char string to the signed char string buffer.


Detailed Description

String processing functions.

This header file list the some string processing functions. Such as subString, and StringList, which provides a memory efficient methods to store a list of constrant strings.


Function Documentation

char* initString ( char *  str  ) 

Initialize the string by setting the first char to 0x0.

If str is NULL, then an char array with MAX_STRING_BUFFER_SIZE will be assined.

Parameters:
str String to be initialize, NULL for allocate a new string..
Returns:
The initialized string.

gboolean isEmptyString ( const char *  str  ) 

Check whether the string is NULL or have 0 length.

Parameters:
str String to be check.
Returns:
False if the string is not empty, true otherwise.

unsigned char* signedStr_to_unsignedStr ( const char *  str  ) 

Convert the signed char string to a new allocated unsigned char string.

Parameters:
str Signed char string.
Returns:
A new allocated unsigned char string.
See also:
signedStr_to_unsignedStr_buffer()

unsignedStr_to_signedStr()

unsignedStr_to_signedStr_buffer()

unsigned char* signedStr_to_unsignedStr_buffer ( unsigned char *  resultBuf,
const char *  str 
)

Convert the signed char string to the unsigned char string buffer.

Parameters:
resultBuf The buffer that stored the conversion result.
str Signed char string.
See also:
signedStr_to_unsignedStr()

unsignedStr_to_signedStr()

unsignedStr_to_signedStr_buffer()

int strcmp_unsigned_signed ( const unsigned char *  str1,
const char *  str2 
)

Compare between signed and unsigned char arrays.

It behaves like strcmp() except the comparison is between a unsigned string (char array) and signed string. Mainly for GCC 4.3

Parameters:
str1 Unsigned string to be compared.
str2 Signed string to be compared.
Returns:
An integer less than, equal to, or greater than zero if str1 is found, respectively, to be less than, to match, or be greater than str2.

void string_trim ( char *  str  ) 

Trim the leading and trailing whitespace of the string.

Note the content of str might be changed. Use strdup() or g_strdup() to backup.

Parameters:
str String to be trim.

void stringList_clear ( StringList sList  ) 

Clear all content of Stringlist.

Parameters:
sList The StringList to be processed.

int stringList_find_string ( StringList sList,
const char *  str 
)

Find a string in StringList.

If found, this function returns the index of the string from 0, otherwise returns -1.

Parameters:
sList The StringList to be processed.
str The character to be found.
Returns:
The index of the string from 0 if found; -1 otherwise.

void stringList_free ( StringList sList  ) 

Free the StringList instance.

Note that this function assumes the sList is not NULL. Use if (sList) stringList_free(sList); to tolerate the NULL parameter.

Parameters:
sList The StringList to be processed.

const char* stringList_index ( StringList sList,
guint  index 
)

Return the string at the given index.

Parameters:
sList The StringList to be processed.
index The given index.
Returns:
The string at the given index.

guint stringList_insert ( StringList sList,
const char *  str 
)

Insert a string to StringList.

This functions copies the str to the string list. It behaves like g_string_chunk_insert(), that is, it does not check for the duplicates. However, it returns the index instead of char pointer of inserted string.

The difference between this function and stringList_insert_const() is that each inserted identical string will have it own spaces.

Parameters:
sList The StringList to be processed.
str String to be inserted.
See also:
stringList_insert_const()

guint stringList_insert_const ( StringList sList,
const char *  str 
)

Insert a constant string to StringList.

This functions copies the str to the string list. It behaves like g_string_chunk_insert_const(), that is, it checks for the duplicates. However, it returns the index instead of char pointer of inserted string.

The difference between this function and stringList_insert() is that each inserted identical string will share the same space.

Parameters:
sList The StringList to be processed.
str String to be inserted.
See also:
stringList_insert()

StringList* stringList_new (  ) 

Allocate space for a StringList instance.

Returns:
the pointer to the allocated space.

char** stringList_to_charPointerPointer ( StringList sList  ) 

Return a char pointer pointer (char **) which points to the list of strings.

This function returns a char** which points to the places that strings are stored. The pointer directly points to content in StringList instance, so the returned pointer should not be free.

Use the stringList_free to free instead.

Parameters:
sList The StringList to be processed.
Returns:
The index of the string from 0 if found; -1 otherwise.

char* subString ( char *  buf,
const char *  str,
int  beginIndex,
int  length 
)

Returns a substring of the given string.

The substring begins at the specified beginIndex and end after length bytes. The index starts from zero.

Parameters:
buf buffer that stores the result.
str String to be process
beginIndex the beginning index, inclusive.
length total bytes to copy.
Returns:
The specified substring.

char* ucs4_to_utf8 ( gunichar  ucs4_code  ) 

Convert UCS-4 to UTF-8 string.

Parameters:
ucs4_code the UCS-4 to be converted.
Returns:
UTF-8 string that converted from the UCS-4 Code. Use g_free() after use.

char* unsignedStr_to_signedStr ( const unsigned char *  str  ) 

Convert the unsigned char string to a new allocated signed char string.

Parameters:
str Unsigned char string.
Returns:
A new allocated signed char string.
See also:
signedStr_to_unsignedStr()

signedStr_to_unsignedStr_buffer()

unsignedStr_to_signedStr_buffer()

char* unsignedStr_to_signedStr_buffer ( char *  resultBuf,
const unsigned char *  str 
)

Convert the unsigned char string to the signed char string buffer.

Parameters:
resultBuf The buffer that stored the conversion result.
str Unsigned char string.
See also:
signedStr_to_unsignedStr()

signedStr_to_unsignedStr_buffer()

unsignedStr_to_signedStr()

char* utf8_concat_ucs4 ( char *  utf8_str,
gunichar  ucs4_code 
)

Concatenate a UCS-4 (gunichar) to an UTF-8 string.

Parameters:
utf8_str the UTF-8 string.
ucs4_code the UCS-4 to be appended.
Returns:
a pointer to utf8_str;

gunichar* utf8_to_ucs4 ( const char *  utf8_str  ) 

Convert UTF-8 string to UCS-4 (gunichar).

Parameters:
utf8_str the UTF-8 string to be converted.
Returns:
UCS-4 representation of the UTF-8 string.


Generated on Tue Sep 23 01:24:26 2008 for libUnihan by  doxygen 1.5.6