gmerlin
Topics | Functions
String utilities

String utilities. More...

Topics

 Misc stuff
 

Functions

char * bg_toupper (const char *str)
 Convert an UTF-8 string to uppercase.
 
int bg_string_is_url (const char *str)
 Check if a string looks like an URL.
 
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.
 
void bg_url_get_vars (char *path, gavl_metadata_t *vars)
 
void bg_get_filename_hash (const char *gml, char ret[33])
 Get MD5 hash of a filename.
 
char * bg_sprintf (const char *format,...) __attribute__((format(printf
 Print into a string.
 
char char ** bg_strbreak (const char *str, char delim)
 Break a string into substrings.
 
void bg_strbreak_free (char **retval)
 Free a substrings array.
 
char * bg_scramble_string (const char *str)
 Scramble a string.
 
char * bg_descramble_string (const char *str)
 Descramble a string.
 
char * bg_string_to_uri (const char *pos1, int len)
 Convert a binary string (in system charset) to an URI.
 
char * bg_uri_to_string (const char *pos1, int len)
 Convert an URI to a a binary string (in system charset)
 
char ** bg_urilist_decode (const char *str, int len)
 Decode an URI list.
 
void bg_urilist_free (char **uri_list)
 Free an URI list.
 
char * bg_system_to_utf8 (const char *str, int len)
 Convert a string from the system character set to UTF-8.
 
char * bg_utf8_to_system (const char *str, int len)
 Convert a string from UTF-8 to the system character set.
 
const char * bg_get_language_name (const char *iso)
 Get a language name.
 
int bg_string_match (const char *str, const char *key_list)
 Check if a string occurs in a space-separated list of strings.
 
wchar_t * bg_str_to_wchar (const char *str)
 Convert a multibyte string to a wide character string.
 
char * bg_wchar_to_str (const wchar_t *wstr)
 Convert a wide character string to a byte string.
 
char * bg_capitalize (const char *str)
 Capitalize the first character of each word in a string.
 
char * bg_strip_space (char *str)
 Strip leading and trailing whitespace from a string.
 

Detailed Description

String utilities.

Function Documentation

◆ bg_toupper()

char * bg_toupper ( const char * str)

Convert an UTF-8 string to uppercase.

Parameters
strString
Returns
A newly allocated string.

◆ bg_string_is_url()

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.

◆ bg_url_split()

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.

◆ bg_get_filename_hash()

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

◆ bg_sprintf()

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.

◆ bg_strbreak()

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.

◆ bg_strbreak_free()

void bg_strbreak_free ( char ** retval)

Free a substrings array.

Parameters
retvalArray

Use this for substring arrays returned by bg_strbreak.

◆ bg_scramble_string()

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.

◆ bg_descramble_string()

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.

◆ bg_string_to_uri()

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".

◆ bg_uri_to_string()

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 " ".

◆ bg_urilist_decode()

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.

◆ 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

◆ bg_system_to_utf8()

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().

◆ bg_utf8_to_system()

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().

◆ bg_get_language_name()

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

◆ bg_string_match()

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

◆ bg_str_to_wchar()

wchar_t * bg_str_to_wchar ( const char * str)

Convert a multibyte string to a wide character string.

Parameters
strString
Returns
A newly allocated wide character string

◆ bg_wchar_to_str()

char * bg_wchar_to_str ( const wchar_t * wstr)

Convert a wide character string to a byte string.

Parameters
wstrString
Returns
A newly allocated multibyte string

◆ bg_capitalize()

char * bg_capitalize ( const char * str)

Capitalize the first character of each word in a string.

Parameters
strString
Returns
A newly allocated capitalized string

◆ bg_strip_space()

char * bg_strip_space ( char * str)

Strip leading and trailing whitespace from a string.

Parameters
strString
Returns
The same string without whitespaces or NULL