After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 57375 - gtk_text_iter_starts/ends_sentence works wrong with '!', '?', '\n'
gtk_text_iter_starts/ends_sentence works wrong with '!', '?', '\n'
Status: RESOLVED DUPLICATE of bug 97545
Product: pango
Classification: Platform
Component: general
0.x
Other All
: Normal normal
: 1.4.0
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2001-07-11 09:15 UTC by Vitaly Tishkov
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Vitaly Tishkov 2001-07-11 09:15:13 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.
Comment 1 Owen Taylor 2001-07-12 16:39:26 UTC
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 

Comment 2 Owen Taylor 2002-01-22 21:30:19 UTC
Steps to fixing this:

 1. Decide the correct behaviors
 2. Extend pango/testboundaries.c to test these cases
Comment 3 Noah Levitt 2003-11-14 00:30:42 UTC

*** This bug has been marked as a duplicate of 97545 ***