GLib Reference Manual | |||
---|---|---|---|
<<< Previous Page | Home | Up | Next Page >>> |
#include <glib.h> gchar* g_strdup (const gchar *str); gchar* g_strndup (const gchar *str, guint n); gchar* g_strnfill (guint length, gchar fill_char); gchar* g_strdup_printf (const gchar *format, ...); gchar* g_strdup_vprintf (const gchar *format, va_list args); gint g_snprintf (gchar *string, gulong n, gchar const *format, ...); gint g_vsnprintf (gchar *string, gulong n, gchar const *format, va_list args); guint g_printf_string_upper_bound (const gchar *format, va_list args); void g_strup (gchar *string); void g_strdown (gchar *string); gint g_strcasecmp (const gchar *s1, const gchar *s2); gint g_strncasecmp (const gchar *s1, const gchar *s2, guint n); void g_strreverse (gchar *string); gdouble g_strtod (const gchar *nptr, gchar **endptr); gchar* g_strchug (gchar *string); gchar* g_strchomp (gchar *string); #define g_strstrip ( string ) gchar* g_strdelimit (gchar *string, const gchar *delimiters, gchar new_delimiter); #define G_STR_DELIMITERS gchar* g_strescape (gchar *string); gchar** g_strsplit (const gchar *string, const gchar *delimiter, gint max_tokens); void g_strfreev (gchar **str_array); gchar* g_strconcat (const gchar *string1, ...); gchar* g_strjoin (const gchar *separator, ...); gchar* g_strjoinv (const gchar *separator, gchar **str_array); gchar* g_strerror (gint errnum); gchar* g_strsignal (gint signum); |
This section describes a number of utility functions for creating, duplicating, and manipulating strings.
gchar* g_strdup (const gchar *str); |
Duplicates a string. The returned string should be freed when no longer needed.
gchar* g_strndup (const gchar *str, guint n); |
Duplicates the first n characters of a string, returning a newly-allocated buffer n + 1 characters long which will always be null-terminated. If str is less than n characters long the buffer is padded with nulls. The returned value should be freed when no longer needed.
gchar* g_strnfill (guint length, gchar fill_char); |
Creates a new string length characters long filled with fill_char. The returned string should be freed when no longer needed.
gchar* g_strdup_printf (const gchar *format, ...); |
Similar to the standard C sprintf() function but safer, since it calculates the maximum space required and allocates memory to hold the result. The returned string should be freed when no longer needed.
gchar* g_strdup_vprintf (const gchar *format, va_list args); |
Similar to the standard C vsprintf() function but safer, since it calculates the maximum space required and allocates memory to hold the result. The returned string should be freed when no longer needed.
gint g_snprintf (gchar *string, gulong n, gchar const *format, ...); |
A safer form of the standard sprintf() function. The output is guaranteed to not exceed n characters (including the terminating NULL character), so it is easy to ensure that a buffer overflow cannot occur.
See also g_strdup_printf().
Note: In versions of GLib prior to 1.2.3, this function may return -1 if the output was truncated, and the truncated string may not be NULL-terminated.
gint g_vsnprintf (gchar *string, gulong n, gchar const *format, va_list args); |
A safer form of the standard vsprintf() function. The output is guaranteed to not exceed n characters (including the terminating NULL character), so it is easy to ensure that a buffer overflow cannot occur.
See also g_strdup_vprintf().
Note: In versions of GLib prior to 1.2.3, this function may return -1 if the output was truncated, and the truncated string may not be NULL-terminated.
guint g_printf_string_upper_bound (const gchar *format, va_list args); |
Calculates the maximum space needed to store the output of the sprintf() function.
gint g_strcasecmp (const gchar *s1, const gchar *s2); |
A case-insensitive string comparison, corresponding to the standard strcasecmp() function on platforms which support it.
gint g_strncasecmp (const gchar *s1, const gchar *s2, guint n); |
A case-insensitive string comparison, corresponding to the standard strncasecmp() function on platforms which support it. It is similar to g_strcasecmp() except it only compares the first n characters of the strings.
void g_strreverse (gchar *string); |
Reverses all of the characters in a string. For example, g_strreverse ("abcdef") would be "fedcba".
gdouble g_strtod (const gchar *nptr, gchar **endptr); |
Converts a string to a gdouble value. It calls the standard strtod() function to handle the conversion, but if the string is not completely converted it attempts the conversion again in the "C" locale, and returns the best match.
gchar* g_strchug (gchar *string); |
Removes leading whitespace from a string, by moving the rest of the characters forward.
gchar* g_strdelimit (gchar *string, const gchar *delimiters, gchar new_delimiter); |
Converts any delimiter characters in string to new_delimiter. Any characters in string which are found in delimiters are changed to the new_delimiter character.
string : | the string to convert. |
delimiters : | a string containing the current delimiters, or NULL to use the standard delimiters defined in G_STR_DELIMITERS. |
new_delimiter : | the new delimiter character. |
Returns : |
gchar* g_strescape (gchar *string); |
Escapes all backslash characters, '\' in a string, by inserting a second '\'.
gchar** g_strsplit (const gchar *string, const gchar *delimiter, gint max_tokens); |
Splits a string into a maximum of max_tokens pieces, using the given delimiter. If max_tokens is reached, the final string in the returned string array contains the remainder of string.
string : | a string to split. |
delimiter : | a string which specifies the places at which to split the string. The delimiter is not included in any of the resulting strings, unless max_tokens is reached. |
max_tokens : | the maximum number of strings to split string into. If this is less than 1, the string is split completely. |
Returns : | a newly-allocated array of strings. Use g_strfreev() to free it. |
void g_strfreev (gchar **str_array); |
Frees a NULL-terminated array of strings, and the array itself.
gchar* g_strconcat (const gchar *string1, ...); |
Concatenates all of the given strings into one long string. The returned string should be freed when no longer needed.
gchar* g_strjoin (const gchar *separator, ...); |
Joins a number of strings together to form one long string, with the optional separator inserted between each of them.
gchar* g_strjoinv (const gchar *separator, gchar **str_array); |
Joins a number of strings together to form one long string, with the optional separator inserted between each of them.
gchar* g_strerror (gint errnum); |
Returns a string corresponding to the given error code, e.g. "no such process". This function is included since not all platforms support the strerror() function.