mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-09 19:06:15 +01:00
Avoid non-ANSI pointer comparison. (#54344, Morten Welinder)
Tue Nov 26 09:51:43 2002 Owen Taylor <otaylor@redhat.com> * glib/gstrfuncs.c (g_strchomp): Avoid non-ANSI pointer comparison. (#54344, Morten Welinder) * tests/strfunc-test.c (main): Add tests for strchomp().
This commit is contained in:
parent
c838b2a071
commit
4d059644f5
@ -2023,16 +2023,18 @@ g_strchug (gchar *string)
|
|||||||
gchar*
|
gchar*
|
||||||
g_strchomp (gchar *string)
|
g_strchomp (gchar *string)
|
||||||
{
|
{
|
||||||
gchar *s;
|
gsize len;
|
||||||
|
|
||||||
g_return_val_if_fail (string != NULL, NULL);
|
g_return_val_if_fail (string != NULL, NULL);
|
||||||
|
|
||||||
if (!*string)
|
len = strlen (string);
|
||||||
return string;
|
while (len--)
|
||||||
|
{
|
||||||
for (s = string + strlen (string) - 1; s >= string && g_ascii_isspace ((guchar)*s);
|
if (g_ascii_isspace ((guchar) string[len]))
|
||||||
s--)
|
string[len] = '\0';
|
||||||
*s = '\0';
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,20 @@ str_check (gchar *str,
|
|||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
strchomp_check (gchar *str,
|
||||||
|
gchar *expected)
|
||||||
|
{
|
||||||
|
gchar *tmp = strdup (str);
|
||||||
|
gboolean ok;
|
||||||
|
|
||||||
|
g_strchomp (tmp);
|
||||||
|
ok = (strcmp (tmp, expected) == 0);
|
||||||
|
g_free (tmp);
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
#define FOR_ALL_CTYPE(macro) \
|
#define FOR_ALL_CTYPE(macro) \
|
||||||
macro(isalnum) \
|
macro(isalnum) \
|
||||||
macro(isalpha) \
|
macro(isalpha) \
|
||||||
@ -331,6 +345,15 @@ main (int argc,
|
|||||||
|
|
||||||
#undef TEST_DIGIT
|
#undef TEST_DIGIT
|
||||||
|
|
||||||
|
/* Tests for strchomp () */
|
||||||
|
TEST (NULL, strchomp_check ("", ""));
|
||||||
|
TEST (NULL, strchomp_check (" ", ""));
|
||||||
|
TEST (NULL, strchomp_check (" \t\r\n", ""));
|
||||||
|
TEST (NULL, strchomp_check ("a ", "a"));
|
||||||
|
TEST (NULL, strchomp_check ("a ", "a"));
|
||||||
|
TEST (NULL, strchomp_check ("a a", "a a"));
|
||||||
|
TEST (NULL, strchomp_check ("a a ", "a a"));
|
||||||
|
|
||||||
/* Tests for g_build_path, g_build_filename */
|
/* Tests for g_build_path, g_build_filename */
|
||||||
|
|
||||||
TEST (NULL, str_check (g_build_path ("", NULL), ""));
|
TEST (NULL, str_check (g_build_path ("", NULL), ""));
|
||||||
|
Loading…
Reference in New Issue
Block a user