applied fix for bug #476840.

2007-09-14 15:07:28  Tim Janik  <timj@gtk.org>

        * glib/gutf8.c (g_utf8_strreverse): applied fix for bug #476840.

        * tests/utf8-pointer.c (test_misc): added test for g_utf8_strreverse().



svn path=/trunk/; revision=5757
This commit is contained in:
15:07:28 Tim Janik 2007-09-14 13:28:07 +00:00 committed by Tim Janik
parent f2ee7ca6e8
commit 63828ea746
3 changed files with 25 additions and 7 deletions

View File

@ -1,3 +1,9 @@
2007-09-14 15:07:28 Tim Janik <timj@gtk.org>
* glib/gutf8.c (g_utf8_strreverse): applied fix for bug #476840.
* tests/utf8-pointer.c (test_misc): added test for g_utf8_strreverse().
2007-09-11 Marco Barisione <marco@barisione.org>
* glib/Makefile.am:

View File

@ -1783,11 +1783,10 @@ g_unichar_validate (gunichar ch)
*/
gchar *
g_utf8_strreverse (const gchar *str,
gssize len)
gssize len)
{
gchar *result;
gchar *r, *result;
const gchar *p;
gchar *m, *r, skip;
if (len < 0)
len = strlen (str);
@ -1795,9 +1794,9 @@ g_utf8_strreverse (const gchar *str,
result = g_new (gchar, len + 1);
r = result + len;
p = str;
while (*p)
while (r > result)
{
skip = g_utf8_skip[*(guchar*)p];
gchar *m, skip = g_utf8_skip[*(guchar*) p];
r -= skip;
for (m = r; skip; skip--)
*m++ = *p++;

View File

@ -90,10 +90,23 @@ test_length (void)
g_assert (g_utf8_strlen ("a\340\250\201c", 5) == 3);
}
static void
test_misc (void)
{
char *s;
s = g_utf8_strreverse ("1234", -1);
g_assert (strcmp (s, "4321") == 0);
g_free (s);
s = g_utf8_strreverse ("1234", 3);
g_assert (strcmp (s, "321") == 0);
g_free (s);
}
int main (int argc, char *argv[])
{
test_utf8 (longline);
test_length ();
test_misc ();
return 0;
}