libcgi_string(3)
| Strings(3) | Library Functions Manual | Strings(3) |
NAME
Strings -
Detailed Description
General string manipulation and utilities functions.
Functions
char * str_base64_encode (char *str)
Encodes a given tring to its base64 form. char *
str_base64_decode (char *str)
Decode a base64 encoded string. char * addnslashes (char *s, int
n)
Same to addslashes(), except that this one only do the action
while 'n' is great than 0. char * addslashes (char *s)
Add slashes to a string when necessary. char * stripnslashes
(char *s, int n)
Strip no more than 'n' slashes from a string. char *
stripslashes (char *str)
Strip slashes from a string. void ltrim (char *str)
Strip left white spaces from a string. void rtrim (char *str)
Strip right white spaces from a string. void trim (char *str)
Strip both left and right white spaces from a string. char *
substr (char *src, const int start, const int count)
Copy part of a string. char ** explode (char *src, const char
*token, int *total)
Create an array from a string separated by some special char. char *
str_nreplace (char *src, const char *delim, const char *with, int n)
Replace characteres in a string, but not more than 'n'. char *
str_replace (char *str, const char *delim, const char *with)
Replace characteres in a string. int strnpos (char *s, char *ch,
unsigned int count)
Returns the position of a character in a string, but parses no more that
'n' chars. int strpos (char *s, char *ch)
Returns the position of a character in a string. char * strdel
(char *s, int start, int count)
Delete characters from a string. char * recvline (FILE *s)
Reads an entire line. char * make_string (char *s,...)
Makes a string.
Function Documentation
char* addnslashes (char * s, int n)
Same to addslashes(), except that this one only do the action while 'n' is great than 0.Parameters:
n Number of characters to work with.
See also:
char *name = 'My test string is called ´foobar´';
puts(name); // will display My test string is called 'foobar'
name = addnslashes(name, 31);
puts(name); // will display My test string is called ´foobar'
char* addslashes (char * s)
Add slashes to a string when necessary.Adds a '\' in every quote ( ' ), apostrophe ( ' ) or backslash ( \ ) It's useful when working with databases, for example, because someone can try insert this caracters to try hack the application...
Parameters:
Returns:
See also:
char *name = 'My test string is called ´foobar´';
puts(name); // will display My test string is called 'foobar'
name = addslashes(name);
puts(name); // will display My test string is called ´foobar´
char** explode (char * src, const char * token, int * total)
Create an array from a string separated by some special char.Divides the src string in pieces, each delimited by token and storing the total of pieces in total
Parameters:
token Character delimiter to search.
total An integer variable passed as reference, which stores the total of itens of the array
Returns:
char **pieces;
char *name = 'This,is,a,string,of,test';
int total, i;
pieces = explode(name, ',', &total);
for (i = 0; i < total; i++)
printf('Piece %d: %s0, i, *(pieces+i));
void ltrim (char * str)
Strip left white spaces from a string.Parameters:
Returns:
Author:
See also:
char *s = ' String with spaces ';
printf('_%s_0, s);
s = ltrim(s);
printf('_%s_0, s);
char* make_string (char * s, ...)
Makes a string.Works like printf(), with the difference that it returns a string that is the concatenation of the values passed as parameter.
Parameters:
Returns:
char *sql = make_string('INSERT INTO myTable VALUES ('%s', '%s', '%s')', varValue1, varValue2, varValue3);
Todo
String limits/error checking
char* recvline (FILE * s)
Reads an entire line.Reads a line from the file specified by the file pointer passed as parameter. This function is intead to replace the non-portable GNU getline() function.
Parameters:
Returns:
Author:
void rtrim (char * str)
Strip right white spaces from a string.Parameters:
Returns:
Author:
See also:
char *s = ' String with spaces ';
printf('_%s_0, s);
s = rtrim(s);
printf('_%s_0, s);
char* str_base64_decode (char * str)
Decode a base64 encoded string.Parameters:
Returns:
See also:
char* str_base64_encode (char * str)
Encodes a given tring to its base64 form.Parameters:
Returns:
See also:
char* str_nreplace (char * src, const char * delim, const char * with, int n)
Replace characteres in a string, but not more than 'n'.Replace all occourences of *delim on *src with characteres pointed by *with, stopping after 'n' char.
Parameters:
*delim Character to search that will be replaced
with String to replace with
n Maximum number of chars to parse
Returns:
See also:
char *linux = 'Linux C';
linux = str_nreplace(linux, 'C', 'Cool', strlen(linux));
puts(linux);
// -- OR --
char *name = 'rAfAel steil';
name = str_nreplace(name, 'A', 'a', 3);
puts(name);
char* str_replace (char * str, const char * delim, const char * with)
Replace characteres in a string.Replace all occourences of *delim on *src with characteres pointed by *with. The problem with the folowing code is that the function only searches for the first caracter of *delim, ingoring the rest. Other problem is speed relacioned: note that the function ever compare the length of *with to do the correct action.
Parameters:
delim Character to search that will be replaced
with String to replace with
Returns:
See also:
char *linux = 'Linux C';
linux = str_replace(linux, 'C', 'Cool');
puts(linux);
// -- OR --
char *name = 'rAfAel steil';
name = str_replace(name, 'A', 'a');
puts(name);
char* strdel (char * s, int start, int count)
Delete characters from a string.Delete count characters of s, starting in start
Parameters:
start Initial offset to begin search
count Number of characteres to delete
Returns:
See also:
*txt = 'Some text to test anything';
puts(txt);
txt = strdel(txt, 2, 8);
puts(txt);
char* stripnslashes (char * s, int n)
Strip no more than 'n' slashes from a string.Strip the backslash character ( \ ) from a string, stopping after 'n' char
Parameters:
n Maximum number of chars to parse
Returns:
See also:
char *name = 'My another string is called \´blablabla\´';
puts(name); // will display My another string is called ´blablabla´
name = stripslashes(name, 33);
puts(name); // will display My another string is called 'blablabla´
char* stripslashes (char * str)
Strip slashes from a string.Strip the backslash character ( \ ) from a string
Parameters:
Returns:
See also:
char *name = 'My another string is called \´blablabla\´';
puts(name); // will display My another string is called ´blablabla´
name = stripslashes(name);
puts(name); // will display My another string is called 'blablabla'
int strnpos (char * s, char * ch, unsigned int count)
Returns the position of a character in a string, but parses no more that 'n' chars.Parameters:
ch Character to search
count Maximum number of chars to parse before exiting the function
See also:
int strpos (char * s, char * ch)
Returns the position of a character in a string.Parameters:
ch Character to search
count Maximum number of ch to search
See also:
char* substr (char * src, const int start, const int count)
Copy part of a string.Copy count characters from src, starting from start
Parameters:
start Initial offset
count Number of chars to copy
Returns:
char *part, *str = 'Test one, test two';
part = substr(str, 1, 5);
puts(part); // -> est o
void trim (char * str)
Strip both left and right white spaces from a string.Parameters:
Returns:
Author:
See also:
char *s = ' String with spaces ';
printf('_%s_0, s);
s = trim(s);
printf('_%s_0, s);
| 13 Mar 2003 | LibCGI |
