New function to revert a utf8 string. Gone, replaced by g_utf8_strreverse.

* 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)
This commit is contained in:
Matthias Clasen 2002-07-26 19:48:02 +00:00
parent 7c10c67f99
commit 1bb885b3b2
10 changed files with 102 additions and 37 deletions

View File

@ -1,3 +1,11 @@
2002-07-26 Matthias Clasen <maclas@gmx.de>
* 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 <otaylor@redhat.com> Thu Jul 25 20:57:20 2002 Owen Taylor <otaylor@redhat.com>
* glib/giochannel.c (g_io_channel_read_line): Fix * glib/giochannel.c (g_io_channel_read_line): Fix

View File

@ -1,3 +1,11 @@
2002-07-26 Matthias Clasen <maclas@gmx.de>
* 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 <otaylor@redhat.com> Thu Jul 25 20:57:20 2002 Owen Taylor <otaylor@redhat.com>
* glib/giochannel.c (g_io_channel_read_line): Fix * glib/giochannel.c (g_io_channel_read_line): Fix

View File

@ -1,3 +1,11 @@
2002-07-26 Matthias Clasen <maclas@gmx.de>
* 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 <otaylor@redhat.com> Thu Jul 25 20:57:20 2002 Owen Taylor <otaylor@redhat.com>
* glib/giochannel.c (g_io_channel_read_line): Fix * glib/giochannel.c (g_io_channel_read_line): Fix

View File

@ -1,3 +1,11 @@
2002-07-26 Matthias Clasen <maclas@gmx.de>
* 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 <otaylor@redhat.com> Thu Jul 25 20:57:20 2002 Owen Taylor <otaylor@redhat.com>
* glib/giochannel.c (g_io_channel_read_line): Fix * glib/giochannel.c (g_io_channel_read_line): Fix

View File

@ -1,3 +1,11 @@
2002-07-26 Matthias Clasen <maclas@gmx.de>
* 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 <otaylor@redhat.com> Thu Jul 25 20:57:20 2002 Owen Taylor <otaylor@redhat.com>
* glib/giochannel.c (g_io_channel_read_line): Fix * glib/giochannel.c (g_io_channel_read_line): Fix

View File

@ -1,3 +1,11 @@
2002-07-26 Matthias Clasen <maclas@gmx.de>
* 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 <otaylor@redhat.com> Thu Jul 25 20:57:20 2002 Owen Taylor <otaylor@redhat.com>
* glib/giochannel.c (g_io_channel_read_line): Fix * glib/giochannel.c (g_io_channel_read_line): Fix

View File

@ -1,3 +1,11 @@
2002-07-26 Matthias Clasen <maclas@gmx.de>
* 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 <otaylor@redhat.com> Thu Jul 25 20:57:20 2002 Owen Taylor <otaylor@redhat.com>
* glib/giochannel.c (g_io_channel_read_line): Fix * glib/giochannel.c (g_io_channel_read_line): Fix

View File

@ -46,41 +46,6 @@ struct _GPatternSpec
/* --- functions --- */ /* --- 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 static inline gboolean
g_pattern_ph_match (const gchar *match_pattern, g_pattern_ph_match (const gchar *match_pattern,
@ -172,7 +137,7 @@ g_pattern_match (GPatternSpec *pspec,
{ {
gboolean result; gboolean result;
gchar *tmp; gchar *tmp;
tmp = g_utf8_reverse (string_length, string); tmp = g_utf8_strreverse (string, string_length);
result = g_pattern_ph_match (pspec->pattern, tmp); result = g_pattern_ph_match (pspec->pattern, tmp);
g_free (tmp); g_free (tmp);
return result; 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; pspec->match_type = tj_pos > hj_pos ? G_MATCH_ALL_TAIL : G_MATCH_ALL;
if (pspec->match_type == G_MATCH_ALL_TAIL) { if (pspec->match_type == G_MATCH_ALL_TAIL) {
gchar *tmp = pspec->pattern; 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); g_free (tmp);
} }
return pspec; return pspec;

View File

@ -195,6 +195,8 @@ gchar* g_utf8_strchr (const gchar *p,
gchar* g_utf8_strrchr (const gchar *p, gchar* g_utf8_strrchr (const gchar *p,
gssize len, gssize len,
gunichar c); gunichar c);
gchar* g_utf8_strreverse (const gchar *str,
gssize len);
gunichar2 *g_utf8_to_utf16 (const gchar *str, gunichar2 *g_utf8_to_utf16 (const gchar *str,
glong len, glong len,

View File

@ -1567,3 +1567,45 @@ g_unichar_validate (gunichar ch)
{ {
return UNICODE_VALID (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;
}