diff options
author | bertrand <Bertrand.Guiheneuf@aful.org> | 2000-01-04 06:40:54 +0800 |
---|---|---|
committer | Bertrand Guiheneuf <bertrand@src.gnome.org> | 2000-01-04 06:40:54 +0800 |
commit | c1d59fcb62563f31b5f753fa90b5c7bd2baa5fed (patch) | |
tree | 57a35f02b38b600eab3a706152d294072e170451 /camel/string-utils.c | |
parent | 01c8e48720676af9576b5eee0c3081432d61b133 (diff) | |
download | gsoc2013-evolution-c1d59fcb62563f31b5f753fa90b5c7bd2baa5fed.tar gsoc2013-evolution-c1d59fcb62563f31b5f753fa90b5c7bd2baa5fed.tar.gz gsoc2013-evolution-c1d59fcb62563f31b5f753fa90b5c7bd2baa5fed.tar.bz2 gsoc2013-evolution-c1d59fcb62563f31b5f753fa90b5c7bd2baa5fed.tar.lz gsoc2013-evolution-c1d59fcb62563f31b5f753fa90b5c7bd2baa5fed.tar.xz gsoc2013-evolution-c1d59fcb62563f31b5f753fa90b5c7bd2baa5fed.tar.zst gsoc2013-evolution-c1d59fcb62563f31b5f753fa90b5c7bd2baa5fed.zip |
detects netscape ".sdb" folders as well as simple non-suffixed folders (as
2000-01-03 bertrand <Bertrand.Guiheneuf@aful.org>
* camel/providers/mbox/camel-mbox-folder.c (_list_subfolders):
detects netscape ".sdb" folders as well as simple
non-suffixed folders (as the ones used in pine).
* camel/string-utils.c (string_prefix):
finished implementation.
(string_prefix): added a boolean flag to indicate if the
suffix has been found. When the suffix does not match,
return NULL.
svn path=/trunk/; revision=1531
Diffstat (limited to 'camel/string-utils.c')
-rw-r--r-- | camel/string-utils.c | 50 |
1 files changed, 44 insertions, 6 deletions
diff --git a/camel/string-utils.c b/camel/string-utils.c index beddfa8172..df973fc01b 100644 --- a/camel/string-utils.c +++ b/camel/string-utils.c @@ -253,23 +253,61 @@ string_trim (gchar *string, const gchar *trim_chars, StringTrimOption options) +/** + * remove_suffix: remove a suffix from a string + * @s: the string to remove the suffix from. + * @suffix: the suffix to remove + * @suffix_found : suffix found flag + * + * Remove a suffix from a string. If the + * string ends with the full suffix, a copy + * of the string without the suffix is returned and + * @suffix_found is set to %TRUE. + * Otherwise, NULL is returned and + * @suffix_found is set to %FALSE. + * + * Return value: an allocated copy of the string without the suffix or NULL if the suffix was not found. + **/ gchar * -string_prefix (const gchar *s, const gchar *suffix) +string_prefix (const gchar *s, const gchar *suffix, gboolean *suffix_found) { guint s_len, suf_len; guint suffix_pos; + char *result_string; g_assert (s); g_assert (suffix); + g_assert (suffix_found); s_len = strlen (s); suf_len = strlen (suffix); - if (s_len < suf_len) - return null; - + /* if the string is shorter than the suffix, do nothing */ + if (s_len < suf_len) { + *suffix_found = FALSE + return NULL; + } + + /* theoretical position of the prefix */ suffix_pos = s_len - suf_len; - if (!strncmp (s+suffix_pos, suffix, suf_len)) - + /* compare the right hand side of the string with the suffix */ + if (!strncmp (s+suffix_pos, suffix, suf_len)) { + + /* if the suffix matches, check that there are + characters before */ + if (suffix_pos == 0) { + result_string = NULL; + *suffix_found = TRUE; + } else { + result_string = g_strndup (s, suffix_pos); + *suffix_found = TRUE; + } + + } else { + result_string = NULL; + *suffix_found = FALSE; + } + + return result_string; } |