1
/* $Id: exo-string.c 47 2006-01-30 02:32:10Z pcmanx $ */
3
* Copyright (c) 2004 os-cillation e.K.
5
* Written by Benedikt Meurer <benny@xfce.org>.
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Library General Public
9
* License as published by the Free Software Foundation; either
10
* version 2 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Library General Public License for more details.
17
* You should have received a copy of the GNU Library General Public
18
* License along with this library; if not, write to the
19
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
* Boston, MA 02111-1307, USA.
34
#include "exo-string.h"
39
* exo_str_elide_underscores:
40
* @text : A zero terminated string.
42
* Returns a copy of @text with all mnemonic underscores
45
* Return value: A copy of @text without underscores. The
46
* returned string must be freed when no
50
exo_str_elide_underscores (const gchar *text)
53
gboolean last_underscore = FALSE;
57
g_return_val_if_fail (text != NULL, NULL);
59
result = g_malloc (strlen (text) + 1);
61
for (s = text, t = result; *s != '\0'; ++s)
62
if (!last_underscore && *s == '_')
64
last_underscore = TRUE;
68
last_underscore = FALSE;
81
* @a : A pointer to first string or %NULL.
82
* @b : A pointer to second string or %NULL.
84
* %NULL-safe string comparison. Returns %TRUE if both @a and @b are
85
* %NULL or if @a and @b refer to valid strings which are equal.
87
* You should always prefer this function over strcmp().
89
* Return value: %TRUE if @a equals @b, else %FALSE.
92
exo_str_is_equal (const gchar *a,
95
if (a == NULL && b == NULL)
97
else if (a == NULL || b == NULL)
111
* @strv : String vector to duplicate.
112
* @num : Number of strings in @strv to
115
* Creates a new string vector containing the
116
* first @n elements of @strv.
118
* Return value: The new string vector. Should be
119
* freed using g_strfreev() when no
123
exo_strndupv (gchar **strv,
128
g_return_val_if_fail (strv != NULL, NULL);
129
g_return_val_if_fail (num >= 0, NULL);
131
result = g_new (gchar *, num + 1);
132
result[num--] = NULL;
133
for (; num >= 0; --num)
134
result[num] = g_strdup (strv[num]);