mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-24 16:16:52 +02:00
New functions g_str_has_suffix and g_str_has_prefix.
2002-05-14 Alex Larsson <alexl@redhat.com> * glib/gstrfuncs.c: * glib/gstrfuncs.h: New functions g_str_has_suffix and g_str_has_prefix. * tests/string-test.c: (main): Test the new functions.
This commit is contained in:
parent
22b31d3313
commit
c8bf903639
@ -1,3 +1,12 @@
|
||||
2002-05-14 Alex Larsson <alexl@redhat.com>
|
||||
|
||||
* glib/gstrfuncs.c:
|
||||
* glib/gstrfuncs.h:
|
||||
New functions g_str_has_suffix and g_str_has_prefix.
|
||||
|
||||
* tests/string-test.c: (main):
|
||||
Test the new functions.
|
||||
|
||||
Mon May 13 23:20:00 2002 Owen Taylor <otaylor@redhat.com>
|
||||
|
||||
* autogen.sh (have_gettext): Add a check for GNU gettext.
|
||||
|
@ -1,3 +1,12 @@
|
||||
2002-05-14 Alex Larsson <alexl@redhat.com>
|
||||
|
||||
* glib/gstrfuncs.c:
|
||||
* glib/gstrfuncs.h:
|
||||
New functions g_str_has_suffix and g_str_has_prefix.
|
||||
|
||||
* tests/string-test.c: (main):
|
||||
Test the new functions.
|
||||
|
||||
Mon May 13 23:20:00 2002 Owen Taylor <otaylor@redhat.com>
|
||||
|
||||
* autogen.sh (have_gettext): Add a check for GNU gettext.
|
||||
|
@ -1,3 +1,12 @@
|
||||
2002-05-14 Alex Larsson <alexl@redhat.com>
|
||||
|
||||
* glib/gstrfuncs.c:
|
||||
* glib/gstrfuncs.h:
|
||||
New functions g_str_has_suffix and g_str_has_prefix.
|
||||
|
||||
* tests/string-test.c: (main):
|
||||
Test the new functions.
|
||||
|
||||
Mon May 13 23:20:00 2002 Owen Taylor <otaylor@redhat.com>
|
||||
|
||||
* autogen.sh (have_gettext): Add a check for GNU gettext.
|
||||
|
@ -1,3 +1,12 @@
|
||||
2002-05-14 Alex Larsson <alexl@redhat.com>
|
||||
|
||||
* glib/gstrfuncs.c:
|
||||
* glib/gstrfuncs.h:
|
||||
New functions g_str_has_suffix and g_str_has_prefix.
|
||||
|
||||
* tests/string-test.c: (main):
|
||||
Test the new functions.
|
||||
|
||||
Mon May 13 23:20:00 2002 Owen Taylor <otaylor@redhat.com>
|
||||
|
||||
* autogen.sh (have_gettext): Add a check for GNU gettext.
|
||||
|
@ -1,3 +1,12 @@
|
||||
2002-05-14 Alex Larsson <alexl@redhat.com>
|
||||
|
||||
* glib/gstrfuncs.c:
|
||||
* glib/gstrfuncs.h:
|
||||
New functions g_str_has_suffix and g_str_has_prefix.
|
||||
|
||||
* tests/string-test.c: (main):
|
||||
Test the new functions.
|
||||
|
||||
Mon May 13 23:20:00 2002 Owen Taylor <otaylor@redhat.com>
|
||||
|
||||
* autogen.sh (have_gettext): Add a check for GNU gettext.
|
||||
|
@ -1,3 +1,12 @@
|
||||
2002-05-14 Alex Larsson <alexl@redhat.com>
|
||||
|
||||
* glib/gstrfuncs.c:
|
||||
* glib/gstrfuncs.h:
|
||||
New functions g_str_has_suffix and g_str_has_prefix.
|
||||
|
||||
* tests/string-test.c: (main):
|
||||
Test the new functions.
|
||||
|
||||
Mon May 13 23:20:00 2002 Owen Taylor <otaylor@redhat.com>
|
||||
|
||||
* autogen.sh (have_gettext): Add a check for GNU gettext.
|
||||
|
@ -1,3 +1,12 @@
|
||||
2002-05-14 Alex Larsson <alexl@redhat.com>
|
||||
|
||||
* glib/gstrfuncs.c:
|
||||
* glib/gstrfuncs.h:
|
||||
New functions g_str_has_suffix and g_str_has_prefix.
|
||||
|
||||
* tests/string-test.c: (main):
|
||||
Test the new functions.
|
||||
|
||||
Mon May 13 23:20:00 2002 Owen Taylor <otaylor@redhat.com>
|
||||
|
||||
* autogen.sh (have_gettext): Add a check for GNU gettext.
|
||||
|
@ -2270,3 +2270,59 @@ g_strrstr_len (const gchar *haystack,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* g_str_has_suffix:
|
||||
* @str: a nul-terminated string.
|
||||
* @suffix: the nul-terminated suffix to look for.
|
||||
*
|
||||
* Looks whether the string @str ends with @suffix.
|
||||
*
|
||||
* Return value: TRUE if @str end with @suffix, FALSE otherwise.
|
||||
**/
|
||||
gboolean
|
||||
g_str_has_suffix (const gchar *str,
|
||||
const gchar *suffix)
|
||||
{
|
||||
int str_len;
|
||||
int suffix_len;
|
||||
|
||||
g_return_val_if_fail (str != NULL, FALSE);
|
||||
g_return_val_if_fail (suffix != NULL, FALSE);
|
||||
|
||||
str_len = strlen (str);
|
||||
suffix_len = strlen (suffix);
|
||||
|
||||
if (str_len < suffix_len)
|
||||
return FALSE;
|
||||
|
||||
return strcmp (str + str_len - suffix_len, suffix) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_str_has_prefix:
|
||||
* @str: a nul-terminated string.
|
||||
* @prefix: the nul-terminated prefix to look for.
|
||||
*
|
||||
* Looks whether the string @str begins with @prefix.
|
||||
*
|
||||
* Return value: TRUE if @str begins with @prefix, FALSE otherwise.
|
||||
**/
|
||||
gboolean
|
||||
g_str_has_prefix (const gchar *str,
|
||||
const gchar *prefix)
|
||||
{
|
||||
int str_len;
|
||||
int prefix_len;
|
||||
|
||||
g_return_val_if_fail (str != NULL, FALSE);
|
||||
g_return_val_if_fail (prefix != NULL, FALSE);
|
||||
|
||||
str_len = strlen (str);
|
||||
prefix_len = strlen (prefix);
|
||||
|
||||
if (str_len < prefix_len)
|
||||
return FALSE;
|
||||
|
||||
return strncmp (str, prefix, prefix_len) == 0;
|
||||
}
|
||||
|
||||
|
@ -116,6 +116,11 @@ gchar * g_strrstr_len (const gchar *haystack,
|
||||
gssize haystack_len,
|
||||
const gchar *needle);
|
||||
|
||||
gboolean g_str_has_suffix (const gchar *str,
|
||||
const gchar *suffix);
|
||||
gboolean g_str_has_prefix (const gchar *str,
|
||||
const gchar *prefix);
|
||||
|
||||
/* String to/from double conversion functions */
|
||||
|
||||
gdouble g_strtod (const gchar *nptr,
|
||||
|
@ -210,6 +210,22 @@ main (int argc,
|
||||
g_string_free (string1, TRUE);
|
||||
g_string_free (string2, TRUE);
|
||||
|
||||
g_assert (g_str_has_prefix("foobar", "gazonk") == FALSE);
|
||||
g_assert (g_str_has_prefix("xyzzy", "xyzzy") == TRUE);
|
||||
g_assert (g_str_has_prefix("xyzzy", "xy") == TRUE);
|
||||
g_assert (g_str_has_prefix("xyzzy", "") == TRUE);
|
||||
g_assert (g_str_has_prefix("xyz", "xyzzy") == FALSE);
|
||||
g_assert (g_str_has_prefix("", "xyzzy") == FALSE);
|
||||
g_assert (g_str_has_prefix("", "") == TRUE);
|
||||
|
||||
g_assert (g_str_has_suffix("foobar", "gazonk") == FALSE);
|
||||
g_assert (g_str_has_suffix("xyzzy", "xyzzy") == TRUE);
|
||||
g_assert (g_str_has_suffix("xyzzy", "zy") == TRUE);
|
||||
g_assert (g_str_has_suffix("xyzzy", "") == TRUE);
|
||||
g_assert (g_str_has_suffix("zzy", "xyzzy") == FALSE);
|
||||
g_assert (g_str_has_suffix("", "xyzzy") == FALSE);
|
||||
g_assert (g_str_has_suffix("", "") == TRUE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user