diff --git a/ChangeLog b/ChangeLog index 452687a6d..01aea27a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2002-07-26 Matthias Clasen + + * glib/gunicode.h: + * glib/gutf8.c (g_utf8_strreverse): New function to revert + a utf8 string. + * glib/gpattern.c (g_utf8_reverse): Gone, replaced by + g_utf8_strreverse. (#87725) + Thu Jul 25 20:57:20 2002 Owen Taylor * glib/giochannel.c (g_io_channel_read_line): Fix diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 452687a6d..01aea27a1 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,11 @@ +2002-07-26 Matthias Clasen + + * glib/gunicode.h: + * glib/gutf8.c (g_utf8_strreverse): New function to revert + a utf8 string. + * glib/gpattern.c (g_utf8_reverse): Gone, replaced by + g_utf8_strreverse. (#87725) + Thu Jul 25 20:57:20 2002 Owen Taylor * glib/giochannel.c (g_io_channel_read_line): Fix diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 452687a6d..01aea27a1 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,11 @@ +2002-07-26 Matthias Clasen + + * glib/gunicode.h: + * glib/gutf8.c (g_utf8_strreverse): New function to revert + a utf8 string. + * glib/gpattern.c (g_utf8_reverse): Gone, replaced by + g_utf8_strreverse. (#87725) + Thu Jul 25 20:57:20 2002 Owen Taylor * glib/giochannel.c (g_io_channel_read_line): Fix diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 452687a6d..01aea27a1 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,11 @@ +2002-07-26 Matthias Clasen + + * glib/gunicode.h: + * glib/gutf8.c (g_utf8_strreverse): New function to revert + a utf8 string. + * glib/gpattern.c (g_utf8_reverse): Gone, replaced by + g_utf8_strreverse. (#87725) + Thu Jul 25 20:57:20 2002 Owen Taylor * glib/giochannel.c (g_io_channel_read_line): Fix diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 452687a6d..01aea27a1 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,11 @@ +2002-07-26 Matthias Clasen + + * glib/gunicode.h: + * glib/gutf8.c (g_utf8_strreverse): New function to revert + a utf8 string. + * glib/gpattern.c (g_utf8_reverse): Gone, replaced by + g_utf8_strreverse. (#87725) + Thu Jul 25 20:57:20 2002 Owen Taylor * glib/giochannel.c (g_io_channel_read_line): Fix diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 452687a6d..01aea27a1 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,11 @@ +2002-07-26 Matthias Clasen + + * glib/gunicode.h: + * glib/gutf8.c (g_utf8_strreverse): New function to revert + a utf8 string. + * glib/gpattern.c (g_utf8_reverse): Gone, replaced by + g_utf8_strreverse. (#87725) + Thu Jul 25 20:57:20 2002 Owen Taylor * glib/giochannel.c (g_io_channel_read_line): Fix diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 452687a6d..01aea27a1 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,11 @@ +2002-07-26 Matthias Clasen + + * glib/gunicode.h: + * glib/gutf8.c (g_utf8_strreverse): New function to revert + a utf8 string. + * glib/gpattern.c (g_utf8_reverse): Gone, replaced by + g_utf8_strreverse. (#87725) + Thu Jul 25 20:57:20 2002 Owen Taylor * glib/giochannel.c (g_io_channel_read_line): Fix diff --git a/glib/gpattern.c b/glib/gpattern.c index d930cea10..924998080 100644 --- a/glib/gpattern.c +++ b/glib/gpattern.c @@ -46,41 +46,6 @@ struct _GPatternSpec /* --- functions --- */ -/** - * g_utf8_reverse: - * @string: a UTF-8 string. - * - * Reverses a UTF-8 string. The @string must be valid UTF-8 encoded text. - * (Use g_utf8_validate() on all text before trying to use UTF-8 - * utility functions with it.) - * - * Note that unlike g_strreverse(), this function returns - * newly-allocated memory, which should be freed with g_free() when - * no longer needed. - * - * Returns: a newly-allocated string which is the reverse of @string. - */ -static gchar * -g_utf8_reverse (guint len, const gchar *string) -{ - gchar *result; - const gchar *p; - gchar *m, *r, skip; - - result = g_new (gchar, len + 1); - r = result + len; - p = string; - while (*p) - { - skip = g_utf8_skip[*(guchar*)p]; - r -= skip; - for (m = r; skip; skip--) - *m++ = *p++; - } - result[len] = 0; - - return result; -} static inline gboolean g_pattern_ph_match (const gchar *match_pattern, @@ -172,7 +137,7 @@ g_pattern_match (GPatternSpec *pspec, { gboolean result; gchar *tmp; - tmp = g_utf8_reverse (string_length, string); + tmp = g_utf8_strreverse (string, string_length); result = g_pattern_ph_match (pspec->pattern, tmp); g_free (tmp); return result; @@ -296,7 +261,7 @@ g_pattern_spec_new (const gchar *pattern) pspec->match_type = tj_pos > hj_pos ? G_MATCH_ALL_TAIL : G_MATCH_ALL; if (pspec->match_type == G_MATCH_ALL_TAIL) { gchar *tmp = pspec->pattern; - pspec->pattern = g_utf8_reverse (pspec->pattern_length, pspec->pattern); + pspec->pattern = g_utf8_strreverse (pspec->pattern, pspec->pattern_length); g_free (tmp); } return pspec; diff --git a/glib/gunicode.h b/glib/gunicode.h index f93f3b1d8..036f7caea 100644 --- a/glib/gunicode.h +++ b/glib/gunicode.h @@ -195,6 +195,8 @@ gchar* g_utf8_strchr (const gchar *p, gchar* g_utf8_strrchr (const gchar *p, gssize len, gunichar c); +gchar* g_utf8_strreverse (const gchar *str, + gssize len); gunichar2 *g_utf8_to_utf16 (const gchar *str, glong len, diff --git a/glib/gutf8.c b/glib/gutf8.c index ab76fb41a..c7746680e 100644 --- a/glib/gutf8.c +++ b/glib/gutf8.c @@ -1567,3 +1567,45 @@ g_unichar_validate (gunichar ch) { return UNICODE_VALID (ch); } + +/** + * g_utf8_strreverse: + * @str: a UTF-8 encoded string + * @len: the maximum length of @str to use. If @len < 0, then + * the string is nul-terminated. + * + * Reverses a UTF-8 string. @str must be valid UTF-8 encoded text. + * (Use g_utf8_validate() on all text before trying to use UTF-8 + * utility functions with it.) + * + * Note that unlike g_strreverse(), this function returns + * newly-allocated memory, which should be freed with g_free() when + * no longer needed. + * + * Returns: a newly-allocated string which is the reverse of @str. + */ +gchar * +g_utf8_strreverse (const gchar *str, + gssize len) +{ + gchar *result; + const gchar *p; + gchar *m, *r, skip; + + if (len < 0) + len = strlen (str); + + result = g_new (gchar, len + 1); + r = result + len; + p = str; + while (*p) + { + skip = g_utf8_skip[*(guchar*)p]; + r -= skip; + for (m = r; skip; skip--) + *m++ = *p++; + } + result[len] = 0; + + return result; +}