group General Utils

Description

Every now and then we cant have nice data structures, so here are some handy functions to help with dealing with data with existing apis. All the functions require that they return a string that it is free'd using ffree().

group contents
Functions
function ferite_copy_string(char,int,int) - Copy a subsection of a string
function ferite_delete_string(int,int) - Cuts out a substring starting at "start" up to but not including "end"
function ferite_find_string(char,char) - Find a substring within a string and return the first occurance
function ferite_insert_string(char,char,int) - Insert a string within another string at a specified position
function ferite_int_to_ptr(int) - Allocate an int and set the value to that of the given parameter
function ferite_lowercase(char) - Convert a string to lowercase
function ferite_replace_string(char,char,char) - Replace all occurances of a pattern in a string with another
function ferite_strcasecmp(char,char) - Do a case insensitive strcmp on the two strings.
function ferite_strip_whitespace(char) - Create a new string based upon the data with the whitespace removed
function ferite_stroflen(char,int) - Provide a string of a given length l filled with the character c
function ferite_variable_from_array(FeriteVariable,char) - For a given array and a given name, locate a variable of that name
function fstrdup(char) - Allocate the memory and copy the string

Functions

function ferite_copy_string Click to go up to the list
Copy a subsection of a string
Warning!
It is the responsibility of the calling function to free the returned string.
Declaration:
    char *ferite_copy_string( char *str, int start, int end )
Parameters:
    Parameter #1: char *str - The string to copy from
    Parameter #2: int start - The start of the subsection
    Parameter #3: int end - The end of the subsection
Returns:
    A string containing the data between the two bounds

function ferite_delete_string Click to go up to the list
Cuts out a substring starting at "start" up to but not including "end"
Warning!
It is the responsibility of the calling function to free the returned string.
Declaration:
    char *ferite_delete_string( char *str, int start, int end )
Parameters:
    Parameter #1: int start - The start of the substring
    Parameter #2: int end - The end of the substring
Returns:
    The string without the substring

function ferite_find_string Click to go up to the list
Find a substring within a string and return the first occurance
Declaration:
    int ferite_find_string( char *haystack, char *needle )
Parameters:
    Parameter #1: char *haystack - The string to scan
    Parameter #2: char *needle - The string to look for
Returns:
    The index of the start of the substring or -1 if no string is found

function ferite_insert_string Click to go up to the list
Insert a string within another string at a specified position
Warning!
It is the responsibility of the calling function to free the returned string.
Declaration:
    char *ferite_insert_string( char *str, char *istr, int pos )
Parameters:
    Parameter #1: char *str - The string to insert into
    Parameter #2: char *istr - The string to insert
    Parameter #3: int pos - The position to insert at
Returns:
    A new string

function ferite_int_to_ptr Click to go up to the list
Allocate an int and set the value to that of the given parameter
Warning!
It is the responsibility of the calling function to free the returned string.
Declaration:
    int *ferite_int_to_ptr( int i )
Parameters:
    Parameter #1: int i - The value
Returns:
    A pointer to an int

function ferite_lowercase Click to go up to the list
Convert a string to lowercase
Warning!
This function modifies the calling string.
Declaration:
    char *ferite_lowercase( char *str )
Parameters:
    Parameter #1: char *str - The string to convert
Returns:
    A string that is a lowercase version of the passed string

function ferite_replace_string Click to go up to the list
Replace all occurances of a pattern in a string with another
Warning!
It is the responsibility of the calling function to free the returned string.
Declaration:
    char *ferite_replace_string( char *str, char *pattern, char *data )
Parameters:
    Parameter #1: char *str - The string to scan
    Parameter #2: char *pattern - The pattern to look for
    Parameter #3: char *datat - The data to replace with
Returns:
    A string that has had the replacements

function ferite_strcasecmp Click to go up to the list
Do a case insensitive strcmp on the two strings.
Declaration:
    int ferite_strcasecmp( char *left, char *right )
Parameters:
    Parameter #1: char *left
    Parameter #2: char *right

function ferite_strip_whitespace Click to go up to the list
Create a new string based upon the data with the whitespace removed
Warning!
This function modifies the calling string.
Declaration:
    char *ferite_strip_whitespace( char *str )
Description:
This function will remove whitespace but not from within double quotes.
Parameters:
    Parameter #1: char *str - The string to remove the whitespace from
Returns:
    A new string without whitespace

function ferite_stroflen Click to go up to the list
Provide a string of a given length l filled with the character c
Warning!
You must not try to free the returned pointer.
Declaration:
    char *ferite_stroflen(char c, int l)
Description:
The length of the string must not exceed 1024. If l is greater than or equal to 1024, a zero length string will be returned.
Parameters:
    Parameter #1: char c - The character to use
    Parameter #2: int l - The length of the string required.

function ferite_variable_from_array Click to go up to the list
For a given array and a given name, locate a variable of that name
Warning!
This is not a ferite array but a C array
Declaration:
    FeriteVariable *ferite_variable_from_array( FeriteVariable **arr, char *name )
Parameters:
    Parameter #1: FeriteVariable **arr - The array to search
    Parameter #2: char *name
Returns:
    A pointer to the variable on success, NULL otherwise.

function fstrdup Click to go up to the list
Allocate the memory and copy the string
Warning!
It is the responsibility of the calling function to free the returned string.
Declaration:
    char *fstrdup( char *str )
Parameters:
    Parameter #1: char *str - The string to copy
Returns:
    The copied string

Automatically generated at 12:07PM, Wednesday 25 May 2005 by feritedoc.