X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Funilbrk%2Fu8-possible-linebreaks.c;h=94e14f40bec20c1208a531a0ca8e0fc69ea9b088;hb=72b730e68b340a28fc29ed71168124d68be1f567;hp=fa1fbc136c816e35ab4f221029df0771a9fe0d03;hpb=9abda809d44be61025d67d5980a4e780010c7b5b;p=gnulib.git diff --git a/lib/unilbrk/u8-possible-linebreaks.c b/lib/unilbrk/u8-possible-linebreaks.c index fa1fbc136..94e14f40b 100644 --- a/lib/unilbrk/u8-possible-linebreaks.c +++ b/lib/unilbrk/u8-possible-linebreaks.c @@ -1,5 +1,5 @@ /* Line breaking of UTF-8 strings. - Copyright (C) 2001-2003, 2006-2008 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2006-2009 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -23,7 +23,7 @@ #include #include -#include "unilbrk/tables.h" +#include "unilbrk/lbrktables.h" #include "uniwidth/cjk.h" #include "unistr.h" @@ -77,33 +77,52 @@ u8_possible_linebreaks (const uint8_t *s, size_t n, const char *encoding, char * break; } - /* Deal with combining characters. */ + /* Deal with spaces and combining characters. */ q = p; - if (prop == LBP_CM) - { - /* Don't break just before a combining character. */ - *p = UC_BREAK_PROHIBITED; - /* A combining character turns a preceding space into LBP_AL. */ - if (seen_space != NULL) - { - q = seen_space; - seen_space = seen_space2; - prop = LBP_AL; - goto lookup_via_table; - } - } - else if (prop == LBP_SP) + if (prop == LBP_SP) { /* Don't break just before a space. */ *p = UC_BREAK_PROHIBITED; seen_space2 = seen_space; seen_space = p; } + else if (prop == LBP_ZW) + { + /* Don't break just before a zero-width space. */ + *p = UC_BREAK_PROHIBITED; + last_prop = LBP_ZW; + seen_space = NULL; + seen_space2 = NULL; + } + else if (prop == LBP_CM) + { + /* Don't break just before a combining character, except immediately after a + zero-width space. */ + if (last_prop == LBP_ZW) + { + /* Break after zero-width space. */ + *p = UC_BREAK_POSSIBLE; + /* A combining character turns a preceding space into LBP_ID. */ + last_prop = LBP_ID; + } + else + { + *p = UC_BREAK_PROHIBITED; + /* A combining character turns a preceding space into LBP_ID. */ + if (seen_space != NULL) + { + q = seen_space; + seen_space = seen_space2; + prop = LBP_ID; + goto lookup_via_table; + } + } + } else { lookup_via_table: /* prop must be usable as an index for table 7.3 of UTR #14. */ - if (!(prop >= 1 && prop <= sizeof (unilbrk_table) / sizeof (unilbrk_table[0]))) + if (!(prop >= 0 && prop < sizeof (unilbrk_table) / sizeof (unilbrk_table[0]))) abort (); if (last_prop == LBP_BK) @@ -111,9 +130,14 @@ u8_possible_linebreaks (const uint8_t *s, size_t n, const char *encoding, char * /* Don't break at the beginning of a line. */ *q = UC_BREAK_PROHIBITED; } + else if (last_prop == LBP_ZW) + { + /* Break after zero-width space. */ + *q = UC_BREAK_POSSIBLE; + } else { - switch (unilbrk_table [last_prop-1] [prop-1]) + switch (unilbrk_table [last_prop] [prop]) { case D: *q = UC_BREAK_POSSIBLE;