From 187255e6344361251b61103f95a043ebd7fba772 Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Thu, 6 Dec 2001 19:51:49 +0000 Subject: hu Dec 6 12:10:53 2001 Owen Taylor * pango/break.c (pango_default_break): Simplify by being lazy and calling g_utf8_strlen() (causes a two passes over the array but shouldn't be a huge performance loss). Fix bug where attributes weren't set correctly for empty strings. Handle internal NULLs consistently with other functions (truncate) rather than dying with an assertion failure. (#65183) --- pango/break.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) (limited to 'pango') diff --git a/pango/break.c b/pango/break.c index dd979e5b..d49c242e 100644 --- a/pango/break.c +++ b/pango/break.c @@ -398,14 +398,12 @@ pango_default_break (const gchar *text, */ const gchar *next; - const gchar *end; - gint i = 0; + gint i; gunichar prev_wc; gunichar next_wc; GUnicodeType prev_type; GUnicodeBreakType prev_break_type; /* skips spaces */ gboolean prev_was_break_space; - gboolean prev_was_end = FALSE; WordType current_word_type = WordNone; gunichar last_word_letter = 0; SentenceState sentence_state = STATE_SENTENCE_OUTSIDE; @@ -415,45 +413,45 @@ pango_default_break (const gchar *text, gint possible_sentence_end = -1; /* possible sentence break before Open* after a period-ended sentence */ gint possible_sentence_boundary = -1; + gint n_chars; g_return_if_fail (text != NULL); g_return_if_fail (attrs != NULL); - if (length < 0) - length = strlen (text); - + n_chars = g_utf8_strlen (text, length); + next = text; - end = text + length; - if (next == end) - return; - + /* + 1 because of the extra newline we stick on the end */ + if (attrs_len < n_chars + 1) + { + g_warning ("pango_default_break(): the array of PangoLogAttr passed in must have at least N+1 elements, if there are N characters in the text being broken"); + return; + } + prev_type = (GUnicodeType) -1; prev_break_type = G_UNICODE_BREAK_UNKNOWN; prev_was_break_space = FALSE; prev_wc = 0; - next_wc = g_utf8_get_char (next); - - g_assert (next_wc != 0); + if (n_chars) + { + next_wc = g_utf8_get_char (next); + g_assert (next_wc != 0); + } + else + next_wc = '\n'; - while (next_wc != 0) + for (i = 0; i <= n_chars; i++) { GUnicodeType type; gunichar wc; GUnicodeBreakType break_type; BreakOpportunity break_op; - /* >, not >=, because of the extra newline we stick on the end */ - if (i > attrs_len) - { - g_warning ("pango_default_break(): the array of PangoLogAttr passed in must have at least N+1 elements, if there are N characters in the text being broken"); - return; - } - wc = next_wc; - if (prev_was_end) + if (i == n_chars) { /* * If we have already reached the end of @text g_utf8_next_char() @@ -465,13 +463,12 @@ pango_default_break (const gchar *text, { next = g_utf8_next_char (next); - if (next == end) + if (i == n_chars - 1) { /* This is how we fill in the last element (end position) of the * attr array - assume there's a newline off the end of @text. */ next_wc = '\n'; - prev_was_end = TRUE; } else { @@ -1280,7 +1277,6 @@ pango_default_break (const gchar *text, prev_type = type; prev_wc = wc; - ++i; } } -- cgit v1.2.1