gmerlin
Functions
String utilities

String utilities. More...

Functions

char * bg_strdup (char *old_string, const char *new_string)
 Duplicate a string. More...
 
char * bg_strndup (char *old_string, const char *new_start, const char *new_end)
 Duplicate a string from a part of a source string. More...
 
char * bg_strcat (char *old_string, const char *tail)
 Concatenate two strings. More...
 
char * bg_strncat (char *old_string, const char *start, const char *end)
 Append a part of a string to another string. More...
 
char * bg_toupper (const char *str)
 Convert an UTF-8 string to uppercase. More...
 
int bg_string_is_url (const char *str)
 Check if a string looks like an URL. More...
 
int bg_url_split (const char *url, char **protocol, char **user, char **password, char **hostname, int *port, char **path)
 Split an URL into their parts. More...
 
void bg_get_filename_hash (const char *gml, char ret[33])
 Get MD5 hash of a filename. More...
 
char * bg_sprintf (const char *format,...) __attribute__((format(printf
 Print into a string. More...
 
char char ** bg_strbreak (const char *str, char delim)
 Break a string into substrings. More...
 
void bg_strbreak_free (char **retval)
 Free a substrings array. More...
 
char * bg_scramble_string (const char *str)
 Scramble a string. More...
 
char * bg_descramble_string (const char *str)
 Descramble a string. More...
 
char * bg_string_to_uri (const char *pos1, int len)
 Convert a binary string (in system charset) to an URI. More...
 
char * bg_uri_to_string (const char *pos1, int len)
 Convert an URI to a a binary string (in system charset) More...
 
char ** bg_urilist_decode (const char *str, int len)
 Decode an URI list. More...
 
void bg_urilist_free (char **uri_list)
 Free an URI list. More...
 
char * bg_system_to_utf8 (const char *str, int len)
 Convert a string from the system character set to UTF-8. More...
 
char * bg_utf8_to_system (const char *str, int len)
 Convert a string from UTF-8 to the system character set. More...
 
const char * bg_get_language_name (const char *iso)
 Get a language name. More...
 
int bg_string_match (const char *str, const char *key_list)
 Check if a string occurs in a space-separated list of strings. More...
 

Detailed Description

String utilities.

Function Documentation

char* bg_strdup ( char *  old_string,
const char *  new_string 
)

Duplicate a string.

Parameters
old_string(will eventually be freed)
new_stringNew string

Both old_string and new_string can be NULL. If new string is the empty string (""), if will be treated like NULL.

char* bg_strndup ( char *  old_string,
const char *  new_start,
const char *  new_end 
)

Duplicate a string from a part of a source string.

Parameters
old_string(will eventually be freed)
new_startStart of the new string
new_endPoints to the first character after the end of the new string

Any combination of old_string, new_start and new_end can be NULL. If new_start is the empty string (""), if will be treated like NULL. If new_end is NULL, it will be obtained with strlen().

char* bg_strcat ( char *  old_string,
const char *  tail 
)

Concatenate two strings.

Parameters
old_stringOld string (will be freed)
tailWill be appended to old_string
Returns
A newly allocated string.
char* bg_strncat ( char *  old_string,
const char *  start,
const char *  end 
)

Append a part of a string to another string.

Parameters
old_stringOld string (will be freed)
startStart of the string to be appended
endPoints to the first character after the end of the string to be appended
Returns
A newly allocated string.
char* bg_toupper ( const char *  str)

Convert an UTF-8 string to uppercase.

Parameters
strString
Returns
A newly allocated string.
int bg_string_is_url ( const char *  str)

Check if a string looks like an URL.

Parameters
strA string
Returns
1 if the string looks like an URL, 0 else

This checks mostly for the occurrence of "://" at a location, where it makes sense.

int bg_url_split ( const char *  url,
char **  protocol,
char **  user,
char **  password,
char **  hostname,
int *  port,
char **  path 
)

Split an URL into their parts.

Parameters
urlAn URL
protocolProtocol (returned)
userUsername (returned)
passwordPassword (returned)
hostnameHostname (returned)
portPort (returned)
pathPath (returned)

This parses an url in the form <protocol>://<user@password><host><:port><path>. All arguments for returning the path can be NULL. port will be set to -1 if if doesn't occur in the URL. All strings must be freed when non-NULL after the call.

void bg_get_filename_hash ( const char *  gml,
char  ret[33] 
)

Get MD5 hash of a filename.

Parameters
gml
retReturns the MD5 sum

This creates an MD5 hash of a gml. For regular files this is compatible with the thumbnailing specification

char* bg_sprintf ( const char *  format,
  ... 
)

Print into a string.

Parameters
formatprintf like format

All other arguments must match the format like in printf. This function allocates the returned string, thus it must be freed by the caller.

char char** bg_strbreak ( const char *  str,
char  delim 
)

Break a string into substrings.

Parameters
strString
delimDelimiter for the substrings
Returns
A NULL terminated array of substrings

Free the result with bg_strbreak_free.

void bg_strbreak_free ( char **  retval)

Free a substrings array.

Parameters
retvalArray

Use this for substring arrays returned by bg_strbreak.

char* bg_scramble_string ( const char *  str)

Scramble a string.

Parameters
strString to be scrambled
Returns
A newly allocated scrambled string

Note: Don't even think about using this for security sensitive stuff. It's for saving passwords in files, which should be readable by the the owner only.

char* bg_descramble_string ( const char *  str)

Descramble a string.

Parameters
strString to be descrambled
Returns
A newly allocated descrambled string

Note: Don't even think about using this for security sensitive stuff. It's for saving passwords in files, which should be readable by the the owner only.

char* bg_string_to_uri ( const char *  pos1,
int  len 
)

Convert a binary string (in system charset) to an URI.

Parameters
pos1The string
lenor -1

This e.g. replaces " " by "%20".

char* bg_uri_to_string ( const char *  pos1,
int  len 
)

Convert an URI to a a binary string (in system charset)

Parameters
pos1The string
lenor -1

This e.g. replaces "%20" by " ".

char** bg_urilist_decode ( const char *  str,
int  len 
)

Decode an URI list.

Parameters
strString
lenLength of the string or -1

This one decodes a string of MIME type text/urilist into a gmerlin usable array of location strings. The returned array is NULL terminated, it must be freed by the caller with bg_urilist_free.

void bg_urilist_free ( char **  uri_list)

Free an URI list.

Parameters
uri_listDecoded URI list returned by bg_uri_to_string
char* bg_system_to_utf8 ( const char *  str,
int  len 
)

Convert a string from the system character set to UTF-8.

Parameters
strString
lenLength or -1
Returns
A newly allocated string

The "system charset" is obtained with nl_langinfo().

char* bg_utf8_to_system ( const char *  str,
int  len 
)

Convert a string from UTF-8 to the system character set.

Parameters
strString
lenLength or -1
Returns
A newly allocated string

The "system charset" is obtained with nl_langinfo().

const char* bg_get_language_name ( const char *  iso)

Get a language name.

Parameters
isoAn iso-639 3 character code
Returns
The name of the language or NULL
int bg_string_match ( const char *  str,
const char *  key_list 
)

Check if a string occurs in a space-separated list of strings.

Parameters
strString
key_listSpace separated list of keys
Returns
1 of str occurs in key_list, 0 else