New function to revert a utf8 string. Gone, replaced by g_utf8_strreverse.
authorMatthias Clasen <matthiasc@src.gnome.org>
Fri, 26 Jul 2002 19:48:02 +0000 (19:48 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Fri, 26 Jul 2002 19:48:02 +0000 (19:48 +0000)
* 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)

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
glib/gpattern.c
glib/gunicode.h
glib/gutf8.c

index 452687a..01aea27 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
 
        * glib/giochannel.c (g_io_channel_read_line): Fix 
index 452687a..01aea27 100644 (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>
 
        * glib/giochannel.c (g_io_channel_read_line): Fix 
index 452687a..01aea27 100644 (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>
 
        * glib/giochannel.c (g_io_channel_read_line): Fix 
index 452687a..01aea27 100644 (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>
 
        * glib/giochannel.c (g_io_channel_read_line): Fix 
index 452687a..01aea27 100644 (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>
 
        * glib/giochannel.c (g_io_channel_read_line): Fix 
index 452687a..01aea27 100644 (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>
 
        * glib/giochannel.c (g_io_channel_read_line): Fix 
index 452687a..01aea27 100644 (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>
 
        * glib/giochannel.c (g_io_channel_read_line): Fix 
index d930cea..9249980 100644 (file)
@@ -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;
index f93f3b1..036f7ca 100644 (file)
@@ -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,            
index ab76fb4..c774668 100644 (file)
@@ -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;
+}