Salad  1.0.15
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Functions
Sld_string

Functions

char * sld_string_allocate (char *string)
 Allocates enough memory to store the specified string. You can then call strcpy() using the returned heap space as a destination. More...
 
char * sld_string_chomp (char *string)
 Removes trailing "\r\n" characters on a passed string. More...
 
char * sld_string_chop (char *string)
 Removes trailing "\r\n" characters on a passed string or the last character if "\r\n" does not exist. More...
 
char * sld_string_trim_leading (char *string)
 Removes leading whitespace from the passed string. More...
 
char * sld_string_trim_trailing (char *string)
 Removes trailing whitespace from the passed string. More...
 
char * sld_string_trim (char *string)
 Removes leading and trailing whitespace from the passed string. More...
 
SLD_BOOL sld_string_contains_character (char *string, char character)
 Checks whether or not a string contains a specified character. More...
 
char * sld_string_capitalize (char *string)
 Capitalizes the specified string. More...
 
char * sld_string_uncapitalize (char *string)
 Uncapitalizes the specified string. More...
 
SLD_BOOL sld_string_casecmp (char *string1, char *string2)
 Compares two strings for equality regardless of capitalization. More...
 
char * sld_string_multiply (char *string, int factor, char separator)
 Multiplies a passed string by the specified factor and separated by the specified character. More...
 
char * sld_string_reverse (char *string)
 Reverses the passed string. More...
 

Detailed Description

This module contains functions related to string management.

Function Documentation

char* sld_string_allocate ( char *  string)

Allocates enough memory to store the specified string. You can then call strcpy() using the returned heap space as a destination.

Parameters
stringa string
Returns
A pointer to a block of uninitialized memory large enough to contain the passed string
Warning
This function makes use of the sld_memory_pool. Be sure to periodically check memory pool usage by calling sld_memory_pool_objects() and sld_memory_pool_size(). If necessary, call sld_memory_pool_free() or sld_memory_pool_nuke() to prevent memory leaks.
char* sld_string_capitalize ( char *  string)

Capitalizes the specified string.

Parameters
stringa string to be capitalized
Returns
A new capitalized string
Warning
This function makes use of the sld_memory_pool. Be sure to periodically check memory pool usage by calling sld_memory_pool_objects() and sld_memory_pool_size(). If necessary, call sld_memory_pool_free() or sld_memory_pool_nuke() to prevent memory leaks.
char *new_string = sld_string_capitalize("foo"); // returns "FOO"
Examples:
daemon.c.
SLD_BOOL sld_string_casecmp ( char *  string1,
char *  string2 
)

Compares two strings for equality regardless of capitalization.

Parameters
string1a string
string2a string
Returns
True or false
Warning
This function makes use of the sld_memory_pool. Be sure to periodically check memory pool usage by calling sld_memory_pool_objects() and sld_memory_pool_size(). If necessary, call sld_memory_pool_free() or sld_memory_pool_nuke() to prevent memory leaks.
if(sld_string_casecmp("foo", "FOO")) // returns true
...
char* sld_string_chomp ( char *  string)

Removes trailing "\r\n" characters on a passed string.

Parameters
stringa string potentially containing a trailing "\r\n"
Returns
A new string free of trailing "\r\n" characters
Warning
This function makes use of the sld_memory_pool. Be sure to periodically check memory pool usage by calling sld_memory_pool_objects() and sld_memory_pool_size(). If necessary, call sld_memory_pool_free() or sld_memory_pool_nuke() to prevent memory leaks.
char *new_string = sld_string_chomp("Hello!\r\n"); // returns "Hello!"
char* sld_string_chop ( char *  string)

Removes trailing "\r\n" characters on a passed string or the last character if "\r\n" does not exist.

Parameters
stringa string potentially containing a trailing "\r\n" or containing a trailing character to be removed
Returns
A new string free of trailing "\r\n" characters or the last character removed
Warning
This function makes use of the sld_memory_pool. Be sure to periodically check memory pool usage by calling sld_memory_pool_objects() and sld_memory_pool_size(). If necessary, call sld_memory_pool_free() or sld_memory_pool_nuke() to prevent memory leaks.
char *new_string1 = sld_string_chop("Hello!\r\n"); // returns "Hello!"
char *new_string2 = sld_string_chop("Hello!"); // returns "Hello"
SLD_BOOL sld_string_contains_character ( char *  string,
char  character 
)

Checks whether or not a string contains a specified character.

Parameters
stringa string potentially containing a specified character
charactera character which possibly exists in the passed string
Returns
True or false
if(sld_string_contains_character("foo", 'f')) // returns true
...
char* sld_string_multiply ( char *  string,
int  factor,
char  separator 
)

Multiplies a passed string by the specified factor and separated by the specified character.

Parameters
stringa string to repeat
factoran amount to repeat
separatorcharacter used to separate each string instance
Returns
A new string containing the original string repeated by the passed factor and separated by separator
Warning
This function makes use of the sld_memory_pool. Be sure to periodically check memory pool usage by calling sld_memory_pool_objects() and sld_memory_pool_size(). If necessary, call sld_memory_pool_free() or sld_memory_pool_nuke() to prevent memory leaks.
char *new_string = sld_string_multiply("foo", 2, ' '); // returns "foo foo"
Examples:
daemon.c.
char* sld_string_reverse ( char *  string)

Reverses the passed string.

Parameters
stringa string to reverse
Returns
A new string which is the reverse of the original string
Warning
This function makes use of the sld_memory_pool. Be sure to periodically check memory pool usage by calling sld_memory_pool_objects() and sld_memory_pool_size(). If necessary, call sld_memory_pool_free() or sld_memory_pool_nuke() to prevent memory leaks.
char *new_string = sld_string_reverse("foo"); // returns "oof"
char* sld_string_trim ( char *  string)

Removes leading and trailing whitespace from the passed string.

Parameters
stringa string potentially containing leading and trailing whitespace
Returns
A new string free of leading and trailing whitespace
Warning
This function makes use of the sld_memory_pool. Be sure to periodically check memory pool usage by calling sld_memory_pool_objects() and sld_memory_pool_size(). If necessary, call sld_memory_pool_free() or sld_memory_pool_nuke() to prevent memory leaks.
char *new_string = sld_string_trim(" Hello! "); // returns "Hello!"
char* sld_string_trim_leading ( char *  string)

Removes leading whitespace from the passed string.

Parameters
stringa string potentially containing leading whitespace
Returns
A new string free of leading whitespace
Warning
This function makes use of the sld_memory_pool. Be sure to periodically check memory pool usage by calling sld_memory_pool_objects() and sld_memory_pool_size(). If necessary, call sld_memory_pool_free() or sld_memory_pool_nuke() to prevent memory leaks.
char *new_string = sld_string_trim_leading(" Hello! "); // returns "Hello! "
char* sld_string_trim_trailing ( char *  string)

Removes trailing whitespace from the passed string.

Parameters
stringa string potentially containing trailing whitespace
Returns
A new string free of trailing whitespace
Warning
This function makes use of the sld_memory_pool. Be sure to periodically check memory pool usage by calling sld_memory_pool_objects() and sld_memory_pool_size(). If necessary, call sld_memory_pool_free() or sld_memory_pool_nuke() to prevent memory leaks.
char *new_string = sld_string_trim_trailing(" Hello! "); // returns " Hello!"
char* sld_string_uncapitalize ( char *  string)

Uncapitalizes the specified string.

Parameters
stringa string to be uncapitalized
Returns
A new uncapitalized string
Warning
This function makes use of the sld_memory_pool. Be sure to periodically check memory pool usage by calling sld_memory_pool_objects() and sld_memory_pool_size(). If necessary, call sld_memory_pool_free() or sld_memory_pool_nuke() to prevent memory leaks.
char *new_string = sld_string_uncapitalize("FOO"); // returns "foo"