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:
Owen Taylor 2002-11-26 15:04:06 +00:00 committed by Owen Taylor
parent c838b2a071
commit 4d059644f5
2 changed files with 32 additions and 7 deletions

View File

@ -2023,16 +2023,18 @@ g_strchug (gchar *string)
gchar*
g_strchomp (gchar *string)
{
gchar *s;
gsize len;
g_return_val_if_fail (string != NULL, NULL);
if (!*string)
return string;
for (s = string + strlen (string) - 1; s >= string && g_ascii_isspace ((guchar)*s);
s--)
*s = '\0';
len = strlen (string);
while (len--)
{
if (g_ascii_isspace ((guchar) string[len]))
string[len] = '\0';
else
break;
}
return string;
}

View File

@ -92,6 +92,20 @@ str_check (gchar *str,
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) \
macro(isalnum) \
macro(isalpha) \
@ -331,6 +345,15 @@ main (int argc,
#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 */
TEST (NULL, str_check (g_build_path ("", NULL), ""));