GNOME Bugzilla – Bug 57375
gtk_text_iter_starts/ends_sentence works wrong with '!', '?', '\n'
Last modified: 2004-12-22 21:47:04 UTC
1. Looks like gtk_text_iter_begins/ends_sentence work incorrectly with '!', '?', '\n' Test case: #include <gtk/gtk.h> void starts (const char *str, gint pos); void ends (const char *str, gint pos); int main (int argc, char** argv) { gtk_init (&argc, &argv); printf ("1\n"); starts ("Sentence one. Sentence two", 14); ends ("Sentence one. Sentence two", 13); printf ("2\n"); starts ("Sentence one! Sentence two", 14); ends ("Sentence one! Sentence two", 13); printf ("3\n"); starts ("Sentence one? Sentence two", 14); ends ("Sentence one? Sentence two", 13); printf ("4\n"); starts ("Sentence one?! Sentence two", 15); ends ("Sentence one?! Sentence two", 14); printf ("5\n"); starts ("Sentence one?! Sentence two", 15); ends ("Sentence one?! Sentence two", 14); printf ("6\n"); starts ("Sentence one.\n Sentence two", 15); ends ("Sentence one.\n Sentence two", 13); ends ("Sentence one.\n Sentence two", 14); printf ("7\n"); starts ("Sentence one!\n Sentence two", 15); ends ("Sentence one!\n Sentence two", 13); ends ("Sentence one!\n Sentence two", 14); printf ("8\n"); starts ("Sentence one?! Sentence two", 15); ends ("Sentence one?! Sentence two", 13); ends ("Sentence one?! Sentence two", 14); printf ("9\n"); starts ("Sentence \none!", 10); ends ("Sentence \none!", 9); } void starts (const char *str, gint pos) { GtkTextIter iter; GtkTextBuffer* buffer; buffer = gtk_text_buffer_new (NULL); gtk_text_buffer_set_text (buffer, str, strlen (str)); gtk_text_buffer_get_iter_at_offset(buffer, &iter, pos); if (gtk_text_iter_starts_sentence (&iter)) { printf ("STARTS\n"); } else { printf ("DOESN'T START\n"); } } void ends (const char *str, gint pos) { GtkTextIter iter; GtkTextBuffer* buffer; buffer = gtk_text_buffer_new (NULL); gtk_text_buffer_set_text (buffer, str, strlen (str)); gtk_text_buffer_get_iter_at_offset(buffer, &iter, pos); if (gtk_text_iter_ends_sentence (&iter)) { printf ("ENDS\n"); } else { printf ("DOESN'T END\n"); } } Output of the compiled code: 1 STARTS ENDS 2 DOESN'T START ENDS 3 DOESN'T START ENDS 4 DOESN'T START ENDS 5 DOESN'T START ENDS 6 STARTS ENDS DOESN'T END 7 STARTS ENDS DOESN'T END 8 DOESN'T START DOESN'T END ENDS 9 STARTS ENDS I assume that these parts of output show wrong behaviour of the functions above: 2: DOESN'T START 3: DOESN'T START 4: DOESN'T START 5: DOESN'T START 8: DOESN'T START 9: BOTH Probably, this is a Pango bug.
It would be useful to develop these tests at the level of pango_get_log_attrs () rather than in the derived GtkTextIter API. [ There are some tests in Pango already you could extend ] The last test is correct - a newline resets all parts of the boundary-resolution algorithm. The normative behavior here for line-breaking is defined (unless overridden for a language) by: http://www.unicode.org/unicode/reports/tr14/ For other boundaries, the behavior should correspond to that described in 5.15
Steps to fixing this: 1. Decide the correct behaviors 2. Extend pango/testboundaries.c to test these cases
*** This bug has been marked as a duplicate of 97545 ***