mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-27 07:56:14 +01:00
API cleanups of the new g_str* functions for consistency with the existing
Wed Oct 21 17:03:05 1998 Tim Janik <timj@gtk.org> * glib.h: * gstrfuncs.c: API cleanups of the new g_str* functions for consistency with the existing naming scheme for g_str* functions. grouped the g_str* functions that will return a newly allocated string seperatedly. all of the in_place arguments were skipped, the caller is supposed to pass a g_strdup()ed string if he wants to retrive a new copy. indentation and coding style fixups. added some g_return_if_fail() statements. string array functions are prefixed with g_str_array_. (g_strdelimit): return the modified string like all other g_str* functions, that operate in place. (g_strchug): renamed from g_str_chug(), removed in_place argument. (g_strchomp): renamed from g_str_chomp(), removed in_place argument. (g_strstrip): renamed from g_str_strip(), removed in_place argument. (g_str_array_join): renamed from g_strconcatv(), since it actually operates on a string array and has totaly different semantics from g_strconcat(). check for separator != NULL, don't segfault if the first string is NULL. removed the `const' from the string array that's passed, so users can operate on gchar** string arrays. (g_str_array_split): renamed from g_str_split() because we actually produce a string array. reimplemented this function for efficiency. removed macro aliases g_str_joinv and g_str_join.
This commit is contained in:
parent
88a22179ac
commit
2009313501
24
ChangeLog
24
ChangeLog
@ -1,3 +1,27 @@
|
|||||||
|
Wed Oct 21 17:03:05 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
|
* glib.h:
|
||||||
|
* gstrfuncs.c: API cleanups of the new g_str* functions for consistency
|
||||||
|
with the existing naming scheme for g_str* functions. grouped the g_str*
|
||||||
|
functions that will return a newly allocated string seperatedly. all of
|
||||||
|
the in_place arguments were skipped, the caller is supposed to pass a
|
||||||
|
g_strdup()ed string if he wants to retrive a new copy. indentation and
|
||||||
|
coding style fixups. added some g_return_if_fail() statements.
|
||||||
|
string array functions are prefixed with g_str_array_.
|
||||||
|
(g_strdelimit): return the modified string like all other g_str*
|
||||||
|
functions, that operate in place.
|
||||||
|
(g_strchug): renamed from g_str_chug(), removed in_place argument.
|
||||||
|
(g_strchomp): renamed from g_str_chomp(), removed in_place argument.
|
||||||
|
(g_strstrip): renamed from g_str_strip(), removed in_place argument.
|
||||||
|
(g_str_array_join): renamed from g_strconcatv(), since it actually
|
||||||
|
operates on a string array and has totaly different semantics from
|
||||||
|
g_strconcat(). check for separator != NULL, don't segfault if the first
|
||||||
|
string is NULL. removed the `const' from the string array that's passed,
|
||||||
|
so users can operate on gchar** string arrays.
|
||||||
|
(g_str_array_split): renamed from g_str_split() because we actually
|
||||||
|
produce a string array. reimplemented this function for efficiency.
|
||||||
|
removed macro aliases g_str_joinv and g_str_join.
|
||||||
|
|
||||||
1998-10-20 Elliot Lee <sopwith@redhat.com>
|
1998-10-20 Elliot Lee <sopwith@redhat.com>
|
||||||
|
|
||||||
* glib.h, gstrfuncs.c: Move string join/split/free routines from
|
* glib.h, gstrfuncs.c: Move string join/split/free routines from
|
||||||
|
@ -1,3 +1,27 @@
|
|||||||
|
Wed Oct 21 17:03:05 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
|
* glib.h:
|
||||||
|
* gstrfuncs.c: API cleanups of the new g_str* functions for consistency
|
||||||
|
with the existing naming scheme for g_str* functions. grouped the g_str*
|
||||||
|
functions that will return a newly allocated string seperatedly. all of
|
||||||
|
the in_place arguments were skipped, the caller is supposed to pass a
|
||||||
|
g_strdup()ed string if he wants to retrive a new copy. indentation and
|
||||||
|
coding style fixups. added some g_return_if_fail() statements.
|
||||||
|
string array functions are prefixed with g_str_array_.
|
||||||
|
(g_strdelimit): return the modified string like all other g_str*
|
||||||
|
functions, that operate in place.
|
||||||
|
(g_strchug): renamed from g_str_chug(), removed in_place argument.
|
||||||
|
(g_strchomp): renamed from g_str_chomp(), removed in_place argument.
|
||||||
|
(g_strstrip): renamed from g_str_strip(), removed in_place argument.
|
||||||
|
(g_str_array_join): renamed from g_strconcatv(), since it actually
|
||||||
|
operates on a string array and has totaly different semantics from
|
||||||
|
g_strconcat(). check for separator != NULL, don't segfault if the first
|
||||||
|
string is NULL. removed the `const' from the string array that's passed,
|
||||||
|
so users can operate on gchar** string arrays.
|
||||||
|
(g_str_array_split): renamed from g_str_split() because we actually
|
||||||
|
produce a string array. reimplemented this function for efficiency.
|
||||||
|
removed macro aliases g_str_joinv and g_str_join.
|
||||||
|
|
||||||
1998-10-20 Elliot Lee <sopwith@redhat.com>
|
1998-10-20 Elliot Lee <sopwith@redhat.com>
|
||||||
|
|
||||||
* glib.h, gstrfuncs.c: Move string join/split/free routines from
|
* glib.h, gstrfuncs.c: Move string join/split/free routines from
|
||||||
|
@ -1,3 +1,27 @@
|
|||||||
|
Wed Oct 21 17:03:05 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
|
* glib.h:
|
||||||
|
* gstrfuncs.c: API cleanups of the new g_str* functions for consistency
|
||||||
|
with the existing naming scheme for g_str* functions. grouped the g_str*
|
||||||
|
functions that will return a newly allocated string seperatedly. all of
|
||||||
|
the in_place arguments were skipped, the caller is supposed to pass a
|
||||||
|
g_strdup()ed string if he wants to retrive a new copy. indentation and
|
||||||
|
coding style fixups. added some g_return_if_fail() statements.
|
||||||
|
string array functions are prefixed with g_str_array_.
|
||||||
|
(g_strdelimit): return the modified string like all other g_str*
|
||||||
|
functions, that operate in place.
|
||||||
|
(g_strchug): renamed from g_str_chug(), removed in_place argument.
|
||||||
|
(g_strchomp): renamed from g_str_chomp(), removed in_place argument.
|
||||||
|
(g_strstrip): renamed from g_str_strip(), removed in_place argument.
|
||||||
|
(g_str_array_join): renamed from g_strconcatv(), since it actually
|
||||||
|
operates on a string array and has totaly different semantics from
|
||||||
|
g_strconcat(). check for separator != NULL, don't segfault if the first
|
||||||
|
string is NULL. removed the `const' from the string array that's passed,
|
||||||
|
so users can operate on gchar** string arrays.
|
||||||
|
(g_str_array_split): renamed from g_str_split() because we actually
|
||||||
|
produce a string array. reimplemented this function for efficiency.
|
||||||
|
removed macro aliases g_str_joinv and g_str_join.
|
||||||
|
|
||||||
1998-10-20 Elliot Lee <sopwith@redhat.com>
|
1998-10-20 Elliot Lee <sopwith@redhat.com>
|
||||||
|
|
||||||
* glib.h, gstrfuncs.c: Move string join/split/free routines from
|
* glib.h, gstrfuncs.c: Move string join/split/free routines from
|
||||||
|
@ -1,3 +1,27 @@
|
|||||||
|
Wed Oct 21 17:03:05 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
|
* glib.h:
|
||||||
|
* gstrfuncs.c: API cleanups of the new g_str* functions for consistency
|
||||||
|
with the existing naming scheme for g_str* functions. grouped the g_str*
|
||||||
|
functions that will return a newly allocated string seperatedly. all of
|
||||||
|
the in_place arguments were skipped, the caller is supposed to pass a
|
||||||
|
g_strdup()ed string if he wants to retrive a new copy. indentation and
|
||||||
|
coding style fixups. added some g_return_if_fail() statements.
|
||||||
|
string array functions are prefixed with g_str_array_.
|
||||||
|
(g_strdelimit): return the modified string like all other g_str*
|
||||||
|
functions, that operate in place.
|
||||||
|
(g_strchug): renamed from g_str_chug(), removed in_place argument.
|
||||||
|
(g_strchomp): renamed from g_str_chomp(), removed in_place argument.
|
||||||
|
(g_strstrip): renamed from g_str_strip(), removed in_place argument.
|
||||||
|
(g_str_array_join): renamed from g_strconcatv(), since it actually
|
||||||
|
operates on a string array and has totaly different semantics from
|
||||||
|
g_strconcat(). check for separator != NULL, don't segfault if the first
|
||||||
|
string is NULL. removed the `const' from the string array that's passed,
|
||||||
|
so users can operate on gchar** string arrays.
|
||||||
|
(g_str_array_split): renamed from g_str_split() because we actually
|
||||||
|
produce a string array. reimplemented this function for efficiency.
|
||||||
|
removed macro aliases g_str_joinv and g_str_join.
|
||||||
|
|
||||||
1998-10-20 Elliot Lee <sopwith@redhat.com>
|
1998-10-20 Elliot Lee <sopwith@redhat.com>
|
||||||
|
|
||||||
* glib.h, gstrfuncs.c: Move string join/split/free routines from
|
* glib.h, gstrfuncs.c: Move string join/split/free routines from
|
||||||
|
@ -1,3 +1,27 @@
|
|||||||
|
Wed Oct 21 17:03:05 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
|
* glib.h:
|
||||||
|
* gstrfuncs.c: API cleanups of the new g_str* functions for consistency
|
||||||
|
with the existing naming scheme for g_str* functions. grouped the g_str*
|
||||||
|
functions that will return a newly allocated string seperatedly. all of
|
||||||
|
the in_place arguments were skipped, the caller is supposed to pass a
|
||||||
|
g_strdup()ed string if he wants to retrive a new copy. indentation and
|
||||||
|
coding style fixups. added some g_return_if_fail() statements.
|
||||||
|
string array functions are prefixed with g_str_array_.
|
||||||
|
(g_strdelimit): return the modified string like all other g_str*
|
||||||
|
functions, that operate in place.
|
||||||
|
(g_strchug): renamed from g_str_chug(), removed in_place argument.
|
||||||
|
(g_strchomp): renamed from g_str_chomp(), removed in_place argument.
|
||||||
|
(g_strstrip): renamed from g_str_strip(), removed in_place argument.
|
||||||
|
(g_str_array_join): renamed from g_strconcatv(), since it actually
|
||||||
|
operates on a string array and has totaly different semantics from
|
||||||
|
g_strconcat(). check for separator != NULL, don't segfault if the first
|
||||||
|
string is NULL. removed the `const' from the string array that's passed,
|
||||||
|
so users can operate on gchar** string arrays.
|
||||||
|
(g_str_array_split): renamed from g_str_split() because we actually
|
||||||
|
produce a string array. reimplemented this function for efficiency.
|
||||||
|
removed macro aliases g_str_joinv and g_str_join.
|
||||||
|
|
||||||
1998-10-20 Elliot Lee <sopwith@redhat.com>
|
1998-10-20 Elliot Lee <sopwith@redhat.com>
|
||||||
|
|
||||||
* glib.h, gstrfuncs.c: Move string join/split/free routines from
|
* glib.h, gstrfuncs.c: Move string join/split/free routines from
|
||||||
|
@ -1,3 +1,27 @@
|
|||||||
|
Wed Oct 21 17:03:05 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
|
* glib.h:
|
||||||
|
* gstrfuncs.c: API cleanups of the new g_str* functions for consistency
|
||||||
|
with the existing naming scheme for g_str* functions. grouped the g_str*
|
||||||
|
functions that will return a newly allocated string seperatedly. all of
|
||||||
|
the in_place arguments were skipped, the caller is supposed to pass a
|
||||||
|
g_strdup()ed string if he wants to retrive a new copy. indentation and
|
||||||
|
coding style fixups. added some g_return_if_fail() statements.
|
||||||
|
string array functions are prefixed with g_str_array_.
|
||||||
|
(g_strdelimit): return the modified string like all other g_str*
|
||||||
|
functions, that operate in place.
|
||||||
|
(g_strchug): renamed from g_str_chug(), removed in_place argument.
|
||||||
|
(g_strchomp): renamed from g_str_chomp(), removed in_place argument.
|
||||||
|
(g_strstrip): renamed from g_str_strip(), removed in_place argument.
|
||||||
|
(g_str_array_join): renamed from g_strconcatv(), since it actually
|
||||||
|
operates on a string array and has totaly different semantics from
|
||||||
|
g_strconcat(). check for separator != NULL, don't segfault if the first
|
||||||
|
string is NULL. removed the `const' from the string array that's passed,
|
||||||
|
so users can operate on gchar** string arrays.
|
||||||
|
(g_str_array_split): renamed from g_str_split() because we actually
|
||||||
|
produce a string array. reimplemented this function for efficiency.
|
||||||
|
removed macro aliases g_str_joinv and g_str_join.
|
||||||
|
|
||||||
1998-10-20 Elliot Lee <sopwith@redhat.com>
|
1998-10-20 Elliot Lee <sopwith@redhat.com>
|
||||||
|
|
||||||
* glib.h, gstrfuncs.c: Move string join/split/free routines from
|
* glib.h, gstrfuncs.c: Move string join/split/free routines from
|
||||||
|
@ -1,3 +1,27 @@
|
|||||||
|
Wed Oct 21 17:03:05 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
|
* glib.h:
|
||||||
|
* gstrfuncs.c: API cleanups of the new g_str* functions for consistency
|
||||||
|
with the existing naming scheme for g_str* functions. grouped the g_str*
|
||||||
|
functions that will return a newly allocated string seperatedly. all of
|
||||||
|
the in_place arguments were skipped, the caller is supposed to pass a
|
||||||
|
g_strdup()ed string if he wants to retrive a new copy. indentation and
|
||||||
|
coding style fixups. added some g_return_if_fail() statements.
|
||||||
|
string array functions are prefixed with g_str_array_.
|
||||||
|
(g_strdelimit): return the modified string like all other g_str*
|
||||||
|
functions, that operate in place.
|
||||||
|
(g_strchug): renamed from g_str_chug(), removed in_place argument.
|
||||||
|
(g_strchomp): renamed from g_str_chomp(), removed in_place argument.
|
||||||
|
(g_strstrip): renamed from g_str_strip(), removed in_place argument.
|
||||||
|
(g_str_array_join): renamed from g_strconcatv(), since it actually
|
||||||
|
operates on a string array and has totaly different semantics from
|
||||||
|
g_strconcat(). check for separator != NULL, don't segfault if the first
|
||||||
|
string is NULL. removed the `const' from the string array that's passed,
|
||||||
|
so users can operate on gchar** string arrays.
|
||||||
|
(g_str_array_split): renamed from g_str_split() because we actually
|
||||||
|
produce a string array. reimplemented this function for efficiency.
|
||||||
|
removed macro aliases g_str_joinv and g_str_join.
|
||||||
|
|
||||||
1998-10-20 Elliot Lee <sopwith@redhat.com>
|
1998-10-20 Elliot Lee <sopwith@redhat.com>
|
||||||
|
|
||||||
* glib.h, gstrfuncs.c: Move string join/split/free routines from
|
* glib.h, gstrfuncs.c: Move string join/split/free routines from
|
||||||
|
@ -1,3 +1,27 @@
|
|||||||
|
Wed Oct 21 17:03:05 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
|
* glib.h:
|
||||||
|
* gstrfuncs.c: API cleanups of the new g_str* functions for consistency
|
||||||
|
with the existing naming scheme for g_str* functions. grouped the g_str*
|
||||||
|
functions that will return a newly allocated string seperatedly. all of
|
||||||
|
the in_place arguments were skipped, the caller is supposed to pass a
|
||||||
|
g_strdup()ed string if he wants to retrive a new copy. indentation and
|
||||||
|
coding style fixups. added some g_return_if_fail() statements.
|
||||||
|
string array functions are prefixed with g_str_array_.
|
||||||
|
(g_strdelimit): return the modified string like all other g_str*
|
||||||
|
functions, that operate in place.
|
||||||
|
(g_strchug): renamed from g_str_chug(), removed in_place argument.
|
||||||
|
(g_strchomp): renamed from g_str_chomp(), removed in_place argument.
|
||||||
|
(g_strstrip): renamed from g_str_strip(), removed in_place argument.
|
||||||
|
(g_str_array_join): renamed from g_strconcatv(), since it actually
|
||||||
|
operates on a string array and has totaly different semantics from
|
||||||
|
g_strconcat(). check for separator != NULL, don't segfault if the first
|
||||||
|
string is NULL. removed the `const' from the string array that's passed,
|
||||||
|
so users can operate on gchar** string arrays.
|
||||||
|
(g_str_array_split): renamed from g_str_split() because we actually
|
||||||
|
produce a string array. reimplemented this function for efficiency.
|
||||||
|
removed macro aliases g_str_joinv and g_str_join.
|
||||||
|
|
||||||
1998-10-20 Elliot Lee <sopwith@redhat.com>
|
1998-10-20 Elliot Lee <sopwith@redhat.com>
|
||||||
|
|
||||||
* glib.h, gstrfuncs.c: Move string join/split/free routines from
|
* glib.h, gstrfuncs.c: Move string join/split/free routines from
|
||||||
|
63
glib.h
63
glib.h
@ -1334,24 +1334,13 @@ gdouble g_timer_elapsed (GTimer *timer,
|
|||||||
gulong *microseconds);
|
gulong *microseconds);
|
||||||
|
|
||||||
|
|
||||||
/* String utility functions
|
/* String utility functions that modify a string argument or
|
||||||
|
* return a constant string that must not be freed.
|
||||||
*/
|
*/
|
||||||
#define G_STR_DELIMITERS "_-|> <."
|
#define G_STR_DELIMITERS "_-|> <."
|
||||||
void g_strdelimit (gchar *string,
|
gchar* g_strdelimit (gchar *string,
|
||||||
const gchar *delimiters,
|
const gchar *delimiters,
|
||||||
gchar new_delimiter);
|
gchar new_delimiter);
|
||||||
gchar* g_strdup (const gchar *str);
|
|
||||||
gchar* g_strdup_printf (const gchar *format,
|
|
||||||
...) G_GNUC_PRINTF (1, 2);
|
|
||||||
gchar* g_strdup_vprintf (const gchar *format,
|
|
||||||
va_list args);
|
|
||||||
gchar* g_strndup (const gchar *str,
|
|
||||||
guint n);
|
|
||||||
gchar* g_strnfill (guint length,
|
|
||||||
gchar fill_char);
|
|
||||||
gchar* g_strconcat (const gchar *string1,
|
|
||||||
...); /* NULL terminated */
|
|
||||||
#define g_str_join g_strconcat
|
|
||||||
gdouble g_strtod (const gchar *nptr,
|
gdouble g_strtod (const gchar *nptr,
|
||||||
gchar **endptr);
|
gchar **endptr);
|
||||||
gchar* g_strerror (gint errnum);
|
gchar* g_strerror (gint errnum);
|
||||||
@ -1363,26 +1352,42 @@ void g_strup (gchar *string);
|
|||||||
void g_strreverse (gchar *string);
|
void g_strreverse (gchar *string);
|
||||||
gpointer g_memdup (gconstpointer mem,
|
gpointer g_memdup (gconstpointer mem,
|
||||||
guint byte_size);
|
guint byte_size);
|
||||||
|
|
||||||
/* removes leading spaces */
|
/* removes leading spaces */
|
||||||
gchar * g_str_chug (gchar *astring,
|
gchar* g_strchug (gchar *string);
|
||||||
gboolean in_place);
|
|
||||||
/* removes trailing spaces */
|
/* removes trailing spaces */
|
||||||
gchar * g_str_chomp (gchar *astring,
|
gchar* g_strchomp (gchar *string);
|
||||||
gboolean in_place);
|
|
||||||
/* removes leading & trailing spaces */
|
/* removes leading & trailing spaces */
|
||||||
#define g_str_strip(astring, in_place) \
|
#define g_strstrip( string ) g_strchomp (g_strchug (string))
|
||||||
g_str_chomp(g_str_chug(astring, in_place), FALSE)
|
|
||||||
|
|
||||||
/* these routines that work with string arrays in which the last
|
/* String utility functions that return a newly allocated string which
|
||||||
element is NULL */
|
* ought to be freed from the caller at some point.
|
||||||
gchar ** g_str_split (const gchar *string,
|
*/
|
||||||
const gchar *delim,
|
gchar* g_strdup (const gchar *str);
|
||||||
|
gchar* g_strdup_printf (const gchar *format,
|
||||||
|
...) G_GNUC_PRINTF (1, 2);
|
||||||
|
gchar* g_strdup_vprintf (const gchar *format,
|
||||||
|
va_list args);
|
||||||
|
gchar* g_strndup (const gchar *str,
|
||||||
|
guint n);
|
||||||
|
gchar* g_strnfill (guint length,
|
||||||
|
gchar fill_char);
|
||||||
|
gchar* g_strconcat (const gchar *string1,
|
||||||
|
...); /* NULL terminated */
|
||||||
|
|
||||||
|
/* NULL terminated string arrays.
|
||||||
|
* g_str_array_split() splits up string into max_tokens tokens at delim and
|
||||||
|
* returns a newly allocated string array.
|
||||||
|
* g_str_array_join() concatenates all of str_array's strings, sliding in an
|
||||||
|
* optional separator, the returned string is newly allocated.
|
||||||
|
* g_str_array_free() frees the array itself and all of its strings.
|
||||||
|
*/
|
||||||
|
gchar** g_str_array_split (const gchar *string,
|
||||||
|
const gchar *delimiter,
|
||||||
gint max_tokens);
|
gint max_tokens);
|
||||||
gchar* g_strconcatv (const gchar *separator,
|
gchar* g_str_array_join (gchar **str_array,
|
||||||
const gchar **strarray);
|
const gchar *separator);
|
||||||
#define g_str_joinv g_strconcatv
|
void g_str_array_free (gchar **str_array);
|
||||||
void g_str_array_free (gchar **strarray);
|
|
||||||
|
|
||||||
|
|
||||||
/* calculate a string size, guarranteed to fit format + args.
|
/* calculate a string size, guarranteed to fit format + args.
|
||||||
|
63
glib/glib.h
63
glib/glib.h
@ -1334,24 +1334,13 @@ gdouble g_timer_elapsed (GTimer *timer,
|
|||||||
gulong *microseconds);
|
gulong *microseconds);
|
||||||
|
|
||||||
|
|
||||||
/* String utility functions
|
/* String utility functions that modify a string argument or
|
||||||
|
* return a constant string that must not be freed.
|
||||||
*/
|
*/
|
||||||
#define G_STR_DELIMITERS "_-|> <."
|
#define G_STR_DELIMITERS "_-|> <."
|
||||||
void g_strdelimit (gchar *string,
|
gchar* g_strdelimit (gchar *string,
|
||||||
const gchar *delimiters,
|
const gchar *delimiters,
|
||||||
gchar new_delimiter);
|
gchar new_delimiter);
|
||||||
gchar* g_strdup (const gchar *str);
|
|
||||||
gchar* g_strdup_printf (const gchar *format,
|
|
||||||
...) G_GNUC_PRINTF (1, 2);
|
|
||||||
gchar* g_strdup_vprintf (const gchar *format,
|
|
||||||
va_list args);
|
|
||||||
gchar* g_strndup (const gchar *str,
|
|
||||||
guint n);
|
|
||||||
gchar* g_strnfill (guint length,
|
|
||||||
gchar fill_char);
|
|
||||||
gchar* g_strconcat (const gchar *string1,
|
|
||||||
...); /* NULL terminated */
|
|
||||||
#define g_str_join g_strconcat
|
|
||||||
gdouble g_strtod (const gchar *nptr,
|
gdouble g_strtod (const gchar *nptr,
|
||||||
gchar **endptr);
|
gchar **endptr);
|
||||||
gchar* g_strerror (gint errnum);
|
gchar* g_strerror (gint errnum);
|
||||||
@ -1363,26 +1352,42 @@ void g_strup (gchar *string);
|
|||||||
void g_strreverse (gchar *string);
|
void g_strreverse (gchar *string);
|
||||||
gpointer g_memdup (gconstpointer mem,
|
gpointer g_memdup (gconstpointer mem,
|
||||||
guint byte_size);
|
guint byte_size);
|
||||||
|
|
||||||
/* removes leading spaces */
|
/* removes leading spaces */
|
||||||
gchar * g_str_chug (gchar *astring,
|
gchar* g_strchug (gchar *string);
|
||||||
gboolean in_place);
|
|
||||||
/* removes trailing spaces */
|
/* removes trailing spaces */
|
||||||
gchar * g_str_chomp (gchar *astring,
|
gchar* g_strchomp (gchar *string);
|
||||||
gboolean in_place);
|
|
||||||
/* removes leading & trailing spaces */
|
/* removes leading & trailing spaces */
|
||||||
#define g_str_strip(astring, in_place) \
|
#define g_strstrip( string ) g_strchomp (g_strchug (string))
|
||||||
g_str_chomp(g_str_chug(astring, in_place), FALSE)
|
|
||||||
|
|
||||||
/* these routines that work with string arrays in which the last
|
/* String utility functions that return a newly allocated string which
|
||||||
element is NULL */
|
* ought to be freed from the caller at some point.
|
||||||
gchar ** g_str_split (const gchar *string,
|
*/
|
||||||
const gchar *delim,
|
gchar* g_strdup (const gchar *str);
|
||||||
|
gchar* g_strdup_printf (const gchar *format,
|
||||||
|
...) G_GNUC_PRINTF (1, 2);
|
||||||
|
gchar* g_strdup_vprintf (const gchar *format,
|
||||||
|
va_list args);
|
||||||
|
gchar* g_strndup (const gchar *str,
|
||||||
|
guint n);
|
||||||
|
gchar* g_strnfill (guint length,
|
||||||
|
gchar fill_char);
|
||||||
|
gchar* g_strconcat (const gchar *string1,
|
||||||
|
...); /* NULL terminated */
|
||||||
|
|
||||||
|
/* NULL terminated string arrays.
|
||||||
|
* g_str_array_split() splits up string into max_tokens tokens at delim and
|
||||||
|
* returns a newly allocated string array.
|
||||||
|
* g_str_array_join() concatenates all of str_array's strings, sliding in an
|
||||||
|
* optional separator, the returned string is newly allocated.
|
||||||
|
* g_str_array_free() frees the array itself and all of its strings.
|
||||||
|
*/
|
||||||
|
gchar** g_str_array_split (const gchar *string,
|
||||||
|
const gchar *delimiter,
|
||||||
gint max_tokens);
|
gint max_tokens);
|
||||||
gchar* g_strconcatv (const gchar *separator,
|
gchar* g_str_array_join (gchar **str_array,
|
||||||
const gchar **strarray);
|
const gchar *separator);
|
||||||
#define g_str_joinv g_strconcatv
|
void g_str_array_free (gchar **str_array);
|
||||||
void g_str_array_free (gchar **strarray);
|
|
||||||
|
|
||||||
|
|
||||||
/* calculate a string size, guarranteed to fit format + args.
|
/* calculate a string size, guarranteed to fit format + args.
|
||||||
|
201
glib/gstrfuncs.c
201
glib/gstrfuncs.c
@ -967,14 +967,14 @@ g_strcasecmp (const gchar *s1,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
gchar*
|
||||||
g_strdelimit (gchar *string,
|
g_strdelimit (gchar *string,
|
||||||
const gchar *delimiters,
|
const gchar *delimiters,
|
||||||
gchar new_delim)
|
gchar new_delim)
|
||||||
{
|
{
|
||||||
register gchar *c;
|
register gchar *c;
|
||||||
|
|
||||||
g_return_if_fail (string != NULL);
|
g_return_val_if_fail (string != NULL, NULL);
|
||||||
|
|
||||||
if (!delimiters)
|
if (!delimiters)
|
||||||
delimiters = G_STR_DELIMITERS;
|
delimiters = G_STR_DELIMITERS;
|
||||||
@ -984,139 +984,138 @@ g_strdelimit (gchar *string,
|
|||||||
if (strchr (delimiters, *c))
|
if (strchr (delimiters, *c))
|
||||||
*c = new_delim;
|
*c = new_delim;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* blame Elliot for these next five routines */
|
/* blame Elliot for these next five routines */
|
||||||
char **
|
gchar*
|
||||||
g_str_split(const gchar *string, const gchar *delim, gint max_tokens)
|
g_strchug (gchar *string)
|
||||||
{
|
{
|
||||||
/* this could more easily be implemented using a GPtrArray */
|
gchar *start;
|
||||||
gchar **retval = NULL;
|
|
||||||
GList *items = NULL, *anode = NULL;
|
|
||||||
gint numitems = 0, dlen, i;
|
|
||||||
gchar *src, *cur, *nxt;
|
|
||||||
|
|
||||||
g_return_val_if_fail(string != NULL, NULL);
|
g_return_val_if_fail (string != NULL, NULL);
|
||||||
g_return_val_if_fail(delim != NULL, NULL);
|
|
||||||
|
|
||||||
if(max_tokens < 0)
|
for (start = string; *start && isspace (*start); start++)
|
||||||
max_tokens = INT_MAX;
|
;
|
||||||
|
|
||||||
dlen = strlen(delim);
|
strcpy (string, start);
|
||||||
nxt = strstr(string, delim);
|
|
||||||
if(!nxt) {
|
|
||||||
retval = g_malloc(sizeof(gchar *) * 2);
|
|
||||||
retval[0] = g_strdup(string);
|
|
||||||
retval[1] = NULL;
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
src = cur = g_strdup(string);
|
|
||||||
nxt = strstr(src, delim);
|
|
||||||
|
|
||||||
while(nxt && numitems < (max_tokens - 1)) {
|
return string;
|
||||||
*nxt = '\0';
|
|
||||||
items = g_list_append(items, g_strdup(cur));
|
|
||||||
cur = nxt + dlen;
|
|
||||||
nxt = strstr(cur, delim);
|
|
||||||
numitems++;
|
|
||||||
}
|
|
||||||
/* We have to take the rest of the string and put it as last token */
|
|
||||||
if(*cur) {
|
|
||||||
items = g_list_append(items, g_strdup(cur));
|
|
||||||
numitems++;
|
|
||||||
}
|
|
||||||
g_free(src);
|
|
||||||
|
|
||||||
retval = g_malloc(sizeof(gchar *) * (numitems + 1));
|
|
||||||
for(anode = items, i = 0; anode; anode = anode->next, i++)
|
|
||||||
retval[i] = anode->data;
|
|
||||||
retval[i] = NULL;
|
|
||||||
g_list_free(items);
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar *
|
gchar*
|
||||||
g_str_chug(gchar *astring, gboolean in_place)
|
g_strchomp (gchar *string)
|
||||||
{
|
{
|
||||||
gchar *retval, *start;
|
gchar *s;
|
||||||
|
|
||||||
g_return_val_if_fail(astring != NULL, NULL);
|
g_return_val_if_fail (string != NULL, NULL);
|
||||||
|
|
||||||
for(start = astring; *start && isspace(*start); start++)
|
if (!*string)
|
||||||
/* */;
|
return string;
|
||||||
|
|
||||||
if(in_place) {
|
for (s = string + strlen (string) - 1; s >= string && isspace (*s); s--)
|
||||||
retval = astring;
|
*s = '\0';
|
||||||
g_memmove(retval, start, strlen(start) + 1);
|
|
||||||
} else
|
|
||||||
retval = g_strdup(start);
|
|
||||||
|
|
||||||
return retval;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar *
|
gchar**
|
||||||
g_str_chomp(gchar *astring, gboolean in_place)
|
g_str_array_split (const gchar *string,
|
||||||
|
const gchar *delimiter,
|
||||||
|
gint max_tokens)
|
||||||
{
|
{
|
||||||
int i;
|
GSList *string_list = NULL, *slist;
|
||||||
gchar *retval, *end;
|
gchar **str_array, **as, *s;
|
||||||
|
guint n = 1;
|
||||||
|
|
||||||
g_return_val_if_fail(astring != NULL, NULL);
|
g_return_val_if_fail (string != NULL, NULL);
|
||||||
|
g_return_val_if_fail (delimiter != NULL, NULL);
|
||||||
|
|
||||||
if(in_place)
|
if (max_tokens < 1)
|
||||||
retval = astring;
|
max_tokens = G_MAXINT;
|
||||||
else
|
|
||||||
retval = g_strdup(astring);
|
|
||||||
|
|
||||||
i = strlen (retval);
|
s = strstr (string, delimiter);
|
||||||
if (!i)
|
if (s)
|
||||||
return retval;
|
{
|
||||||
|
guint delimiter_len = strlen (delimiter);
|
||||||
|
|
||||||
end = retval + i - 1;
|
do
|
||||||
for (; end >= retval && isspace (*end); end--)
|
{
|
||||||
*end = '\0';
|
guint len;
|
||||||
|
gchar *new_string;
|
||||||
|
|
||||||
return retval;
|
len = s - string;
|
||||||
|
new_string = g_new (gchar, len + 1);
|
||||||
|
strncpy (new_string, string, len);
|
||||||
|
new_string[len] = 0;
|
||||||
|
string_list = g_slist_prepend (string_list, new_string);
|
||||||
|
n++;
|
||||||
|
string = s + delimiter_len;
|
||||||
|
s = strstr (string, delimiter);
|
||||||
|
}
|
||||||
|
while (--max_tokens && s);
|
||||||
|
}
|
||||||
|
if (*string)
|
||||||
|
{
|
||||||
|
n++;
|
||||||
|
string_list = g_slist_prepend (string_list, g_strdup (string));
|
||||||
|
}
|
||||||
|
|
||||||
|
str_array = g_new (gchar*, n);
|
||||||
|
as = str_array + n - 1;
|
||||||
|
*(as--) = NULL;
|
||||||
|
for (slist = string_list; slist; slist = slist->next)
|
||||||
|
*(as--) = slist->data;
|
||||||
|
g_slist_free (string_list);
|
||||||
|
|
||||||
|
return str_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_str_array_free(gchar **strarray)
|
g_str_array_free (gchar **str_array)
|
||||||
{
|
{
|
||||||
int i;
|
if (str_array)
|
||||||
|
{
|
||||||
|
gchar **as;
|
||||||
|
|
||||||
if(strarray == NULL) return; /* Don't use g_return_if_fail,
|
for (as = str_array; *as; as++)
|
||||||
because this is legal */
|
g_free (*as);
|
||||||
|
g_free (str_array);
|
||||||
for(i = 0; strarray[i]; i++)
|
}
|
||||||
g_free(strarray[i]);
|
|
||||||
|
|
||||||
g_free(strarray);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar* g_strconcatv (const gchar *separator,
|
gchar*
|
||||||
const gchar **strarray)
|
g_str_array_join (gchar **str_array,
|
||||||
|
const gchar *separator)
|
||||||
{
|
{
|
||||||
guint l, sepl;
|
gchar *string;
|
||||||
gchar *concat;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
g_return_val_if_fail (strarray != NULL, NULL);
|
g_return_val_if_fail (str_array != NULL, NULL);
|
||||||
|
g_return_val_if_fail (separator != NULL, NULL);
|
||||||
|
|
||||||
l = strlen(strarray[0]) + 1;
|
if (*str_array)
|
||||||
sepl = strlen(separator);
|
{
|
||||||
for(i = 1; strarray[i]; i++) {
|
guint len;
|
||||||
l += sepl;
|
guint seperator_len;
|
||||||
l += strlen(strarray[i]);
|
gchar **as;
|
||||||
|
|
||||||
|
seperator_len = strlen (separator);
|
||||||
|
len = 1 + strlen (*str_array);
|
||||||
|
for (as = str_array + 1; *as; as++)
|
||||||
|
len += seperator_len + strlen (*as);
|
||||||
|
|
||||||
|
string = g_new (gchar, len);
|
||||||
|
*string = 0;
|
||||||
|
strcat (string, *str_array);
|
||||||
|
for (as = str_array + 1; *as; as++)
|
||||||
|
{
|
||||||
|
strcat (string, separator);
|
||||||
|
strcat (string, *as);
|
||||||
}
|
}
|
||||||
|
|
||||||
concat = g_new (gchar, l);
|
|
||||||
*concat = '\0';
|
|
||||||
|
|
||||||
strcat (concat, strarray[0]);
|
|
||||||
for(i = 1; strarray[i]; i++) {
|
|
||||||
strcat (concat, separator);
|
|
||||||
strcat (concat, strarray[i]);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
string = g_strdup ("");
|
||||||
|
|
||||||
return concat;
|
return string;
|
||||||
}
|
}
|
||||||
|
201
gstrfuncs.c
201
gstrfuncs.c
@ -967,14 +967,14 @@ g_strcasecmp (const gchar *s1,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
gchar*
|
||||||
g_strdelimit (gchar *string,
|
g_strdelimit (gchar *string,
|
||||||
const gchar *delimiters,
|
const gchar *delimiters,
|
||||||
gchar new_delim)
|
gchar new_delim)
|
||||||
{
|
{
|
||||||
register gchar *c;
|
register gchar *c;
|
||||||
|
|
||||||
g_return_if_fail (string != NULL);
|
g_return_val_if_fail (string != NULL, NULL);
|
||||||
|
|
||||||
if (!delimiters)
|
if (!delimiters)
|
||||||
delimiters = G_STR_DELIMITERS;
|
delimiters = G_STR_DELIMITERS;
|
||||||
@ -984,139 +984,138 @@ g_strdelimit (gchar *string,
|
|||||||
if (strchr (delimiters, *c))
|
if (strchr (delimiters, *c))
|
||||||
*c = new_delim;
|
*c = new_delim;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* blame Elliot for these next five routines */
|
/* blame Elliot for these next five routines */
|
||||||
char **
|
gchar*
|
||||||
g_str_split(const gchar *string, const gchar *delim, gint max_tokens)
|
g_strchug (gchar *string)
|
||||||
{
|
{
|
||||||
/* this could more easily be implemented using a GPtrArray */
|
gchar *start;
|
||||||
gchar **retval = NULL;
|
|
||||||
GList *items = NULL, *anode = NULL;
|
|
||||||
gint numitems = 0, dlen, i;
|
|
||||||
gchar *src, *cur, *nxt;
|
|
||||||
|
|
||||||
g_return_val_if_fail(string != NULL, NULL);
|
g_return_val_if_fail (string != NULL, NULL);
|
||||||
g_return_val_if_fail(delim != NULL, NULL);
|
|
||||||
|
|
||||||
if(max_tokens < 0)
|
for (start = string; *start && isspace (*start); start++)
|
||||||
max_tokens = INT_MAX;
|
;
|
||||||
|
|
||||||
dlen = strlen(delim);
|
strcpy (string, start);
|
||||||
nxt = strstr(string, delim);
|
|
||||||
if(!nxt) {
|
|
||||||
retval = g_malloc(sizeof(gchar *) * 2);
|
|
||||||
retval[0] = g_strdup(string);
|
|
||||||
retval[1] = NULL;
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
src = cur = g_strdup(string);
|
|
||||||
nxt = strstr(src, delim);
|
|
||||||
|
|
||||||
while(nxt && numitems < (max_tokens - 1)) {
|
return string;
|
||||||
*nxt = '\0';
|
|
||||||
items = g_list_append(items, g_strdup(cur));
|
|
||||||
cur = nxt + dlen;
|
|
||||||
nxt = strstr(cur, delim);
|
|
||||||
numitems++;
|
|
||||||
}
|
|
||||||
/* We have to take the rest of the string and put it as last token */
|
|
||||||
if(*cur) {
|
|
||||||
items = g_list_append(items, g_strdup(cur));
|
|
||||||
numitems++;
|
|
||||||
}
|
|
||||||
g_free(src);
|
|
||||||
|
|
||||||
retval = g_malloc(sizeof(gchar *) * (numitems + 1));
|
|
||||||
for(anode = items, i = 0; anode; anode = anode->next, i++)
|
|
||||||
retval[i] = anode->data;
|
|
||||||
retval[i] = NULL;
|
|
||||||
g_list_free(items);
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar *
|
gchar*
|
||||||
g_str_chug(gchar *astring, gboolean in_place)
|
g_strchomp (gchar *string)
|
||||||
{
|
{
|
||||||
gchar *retval, *start;
|
gchar *s;
|
||||||
|
|
||||||
g_return_val_if_fail(astring != NULL, NULL);
|
g_return_val_if_fail (string != NULL, NULL);
|
||||||
|
|
||||||
for(start = astring; *start && isspace(*start); start++)
|
if (!*string)
|
||||||
/* */;
|
return string;
|
||||||
|
|
||||||
if(in_place) {
|
for (s = string + strlen (string) - 1; s >= string && isspace (*s); s--)
|
||||||
retval = astring;
|
*s = '\0';
|
||||||
g_memmove(retval, start, strlen(start) + 1);
|
|
||||||
} else
|
|
||||||
retval = g_strdup(start);
|
|
||||||
|
|
||||||
return retval;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar *
|
gchar**
|
||||||
g_str_chomp(gchar *astring, gboolean in_place)
|
g_str_array_split (const gchar *string,
|
||||||
|
const gchar *delimiter,
|
||||||
|
gint max_tokens)
|
||||||
{
|
{
|
||||||
int i;
|
GSList *string_list = NULL, *slist;
|
||||||
gchar *retval, *end;
|
gchar **str_array, **as, *s;
|
||||||
|
guint n = 1;
|
||||||
|
|
||||||
g_return_val_if_fail(astring != NULL, NULL);
|
g_return_val_if_fail (string != NULL, NULL);
|
||||||
|
g_return_val_if_fail (delimiter != NULL, NULL);
|
||||||
|
|
||||||
if(in_place)
|
if (max_tokens < 1)
|
||||||
retval = astring;
|
max_tokens = G_MAXINT;
|
||||||
else
|
|
||||||
retval = g_strdup(astring);
|
|
||||||
|
|
||||||
i = strlen (retval);
|
s = strstr (string, delimiter);
|
||||||
if (!i)
|
if (s)
|
||||||
return retval;
|
{
|
||||||
|
guint delimiter_len = strlen (delimiter);
|
||||||
|
|
||||||
end = retval + i - 1;
|
do
|
||||||
for (; end >= retval && isspace (*end); end--)
|
{
|
||||||
*end = '\0';
|
guint len;
|
||||||
|
gchar *new_string;
|
||||||
|
|
||||||
return retval;
|
len = s - string;
|
||||||
|
new_string = g_new (gchar, len + 1);
|
||||||
|
strncpy (new_string, string, len);
|
||||||
|
new_string[len] = 0;
|
||||||
|
string_list = g_slist_prepend (string_list, new_string);
|
||||||
|
n++;
|
||||||
|
string = s + delimiter_len;
|
||||||
|
s = strstr (string, delimiter);
|
||||||
|
}
|
||||||
|
while (--max_tokens && s);
|
||||||
|
}
|
||||||
|
if (*string)
|
||||||
|
{
|
||||||
|
n++;
|
||||||
|
string_list = g_slist_prepend (string_list, g_strdup (string));
|
||||||
|
}
|
||||||
|
|
||||||
|
str_array = g_new (gchar*, n);
|
||||||
|
as = str_array + n - 1;
|
||||||
|
*(as--) = NULL;
|
||||||
|
for (slist = string_list; slist; slist = slist->next)
|
||||||
|
*(as--) = slist->data;
|
||||||
|
g_slist_free (string_list);
|
||||||
|
|
||||||
|
return str_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_str_array_free(gchar **strarray)
|
g_str_array_free (gchar **str_array)
|
||||||
{
|
{
|
||||||
int i;
|
if (str_array)
|
||||||
|
{
|
||||||
|
gchar **as;
|
||||||
|
|
||||||
if(strarray == NULL) return; /* Don't use g_return_if_fail,
|
for (as = str_array; *as; as++)
|
||||||
because this is legal */
|
g_free (*as);
|
||||||
|
g_free (str_array);
|
||||||
for(i = 0; strarray[i]; i++)
|
}
|
||||||
g_free(strarray[i]);
|
|
||||||
|
|
||||||
g_free(strarray);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar* g_strconcatv (const gchar *separator,
|
gchar*
|
||||||
const gchar **strarray)
|
g_str_array_join (gchar **str_array,
|
||||||
|
const gchar *separator)
|
||||||
{
|
{
|
||||||
guint l, sepl;
|
gchar *string;
|
||||||
gchar *concat;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
g_return_val_if_fail (strarray != NULL, NULL);
|
g_return_val_if_fail (str_array != NULL, NULL);
|
||||||
|
g_return_val_if_fail (separator != NULL, NULL);
|
||||||
|
|
||||||
l = strlen(strarray[0]) + 1;
|
if (*str_array)
|
||||||
sepl = strlen(separator);
|
{
|
||||||
for(i = 1; strarray[i]; i++) {
|
guint len;
|
||||||
l += sepl;
|
guint seperator_len;
|
||||||
l += strlen(strarray[i]);
|
gchar **as;
|
||||||
|
|
||||||
|
seperator_len = strlen (separator);
|
||||||
|
len = 1 + strlen (*str_array);
|
||||||
|
for (as = str_array + 1; *as; as++)
|
||||||
|
len += seperator_len + strlen (*as);
|
||||||
|
|
||||||
|
string = g_new (gchar, len);
|
||||||
|
*string = 0;
|
||||||
|
strcat (string, *str_array);
|
||||||
|
for (as = str_array + 1; *as; as++)
|
||||||
|
{
|
||||||
|
strcat (string, separator);
|
||||||
|
strcat (string, *as);
|
||||||
}
|
}
|
||||||
|
|
||||||
concat = g_new (gchar, l);
|
|
||||||
*concat = '\0';
|
|
||||||
|
|
||||||
strcat (concat, strarray[0]);
|
|
||||||
for(i = 1; strarray[i]; i++) {
|
|
||||||
strcat (concat, separator);
|
|
||||||
strcat (concat, strarray[i]);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
string = g_strdup ("");
|
||||||
|
|
||||||
return concat;
|
return string;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user