diff --git a/ChangeLog b/ChangeLog index 5a3dc7d47..dfa4a23dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-02-24 Matthias Clasen + + * tests/utf8-pointer.c: Add tests for g_utf8_strlen(). + + * glib/gutf8.c: Fix boundary cases in g_utf8_strlen(). + (#332435) + 2006-02-23 Kjartan Maraas * tests/completion-test.c: (main): Plug leaks reported by diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 5a3dc7d47..dfa4a23dc 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,10 @@ +2006-02-24 Matthias Clasen + + * tests/utf8-pointer.c: Add tests for g_utf8_strlen(). + + * glib/gutf8.c: Fix boundary cases in g_utf8_strlen(). + (#332435) + 2006-02-23 Kjartan Maraas * tests/completion-test.c: (main): Plug leaks reported by diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 5a3dc7d47..dfa4a23dc 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,10 @@ +2006-02-24 Matthias Clasen + + * tests/utf8-pointer.c: Add tests for g_utf8_strlen(). + + * glib/gutf8.c: Fix boundary cases in g_utf8_strlen(). + (#332435) + 2006-02-23 Kjartan Maraas * tests/completion-test.c: (main): Plug leaks reported by diff --git a/glib/gutf8.c b/glib/gutf8.c index 23f2a424d..69105e235 100644 --- a/glib/gutf8.c +++ b/glib/gutf8.c @@ -242,7 +242,7 @@ g_utf8_strlen (const gchar *p, /* only do the last len increment if we got a complete * char (don't count partial chars) */ - if (p - start == max) + if (p - start <= max) ++len; } diff --git a/tests/utf8-pointer.c b/tests/utf8-pointer.c index 3072851a7..00b03d14b 100644 --- a/tests/utf8-pointer.c +++ b/tests/utf8-pointer.c @@ -64,9 +64,35 @@ gchar *longline = "asdasdas dsaf asfd as fdasdf asfd asdf as dfas dfasdf a" "asd fasdf asdf asdf asd fasfd as fdasfd asdf as fdas ffsd asfd as fdASASASAs D" "Asfdsf sdfg sdfg dsfg dfg sdfgsdfgsdfgsdfg sdfgsdfg sdfg sdfg sdf gsdfg sdfg sd\n\nlalala\n"; +static void +test_length (void) +{ + g_assert (g_utf8_strlen ("1234", -1) == 4); + g_assert (g_utf8_strlen ("1234", 0) == 0); + g_assert (g_utf8_strlen ("1234", 1) == 1); + g_assert (g_utf8_strlen ("1234", 2) == 2); + g_assert (g_utf8_strlen ("1234", 3) == 3); + g_assert (g_utf8_strlen ("1234", 4) == 4); + g_assert (g_utf8_strlen ("1234", 5) == 4); + + g_assert (g_utf8_strlen (longline, -1) == 762); + g_assert (g_utf8_strlen (longline, strlen (longline)) == 762); + g_assert (g_utf8_strlen (longline, 1024) == 762); + + g_assert (g_utf8_strlen (NULL, 0) == 0); + + g_assert (g_utf8_strlen ("a\340\250\201c", -1) == 3); + g_assert (g_utf8_strlen ("a\340\250\201c", 1) == 1); + g_assert (g_utf8_strlen ("a\340\250\201c", 2) == 1); + g_assert (g_utf8_strlen ("a\340\250\201c", 3) == 1); + g_assert (g_utf8_strlen ("a\340\250\201c", 4) == 2); + g_assert (g_utf8_strlen ("a\340\250\201c", 5) == 3); +} + int main (int argc, char *argv[]) { test_utf8 (longline); - + test_length (); + return 0; }