| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #include <config.h> |
|
|
| |
| #include "unilbrk.h" |
|
|
| #include "unilbrk/internal.h" |
| #include "unilbrk/lbrktables.h" |
| #include "unistr.h" |
| #include "uniwidth.h" |
|
|
| static int |
| u16_width_linebreaks_internal (const uint16_t *s, size_t n, |
| int width, int start_column, int at_end_columns, |
| const char *o, const char *encoding, int cr, |
| char *p) |
| { |
| const uint16_t *s_end; |
| char *last_p; |
| int last_column; |
| int piece_width; |
|
|
| u16_possible_linebreaks_loop (s, n, encoding, cr, p); |
|
|
| s_end = s + n; |
| last_p = NULL; |
| last_column = start_column; |
| piece_width = 0; |
| while (s < s_end) |
| { |
| ucs4_t uc; |
| int count = u16_mbtouc_unsafe (&uc, s, s_end - s); |
|
|
| |
| if (o != NULL && *o != UC_BREAK_UNDEFINED) |
| *p = *o; |
|
|
| if (*p == UC_BREAK_POSSIBLE |
| || *p == UC_BREAK_MANDATORY || *p == UC_BREAK_CR_BEFORE_LF) |
| { |
| |
| if (last_p != NULL && last_column + piece_width > width) |
| { |
| |
| *last_p = UC_BREAK_POSSIBLE; |
| last_column = 0; |
| } |
| } |
|
|
| if (*p == UC_BREAK_MANDATORY || *p == UC_BREAK_CR_BEFORE_LF) |
| { |
| |
| |
| last_p = NULL; |
| last_column = 0; |
| piece_width = 0; |
| } |
| else |
| { |
| |
| int w; |
|
|
| if (*p == UC_BREAK_POSSIBLE) |
| { |
| |
| last_p = p; |
| last_column += piece_width; |
| piece_width = 0; |
| |
| |
| } |
|
|
| *p = UC_BREAK_PROHIBITED; |
|
|
| w = uc_width (uc, encoding); |
| if (w >= 0) |
| piece_width += w; |
| } |
|
|
| s += count; |
| p += count; |
| if (o != NULL) |
| o += count; |
| } |
|
|
| |
| if (last_p != NULL && last_column + piece_width + at_end_columns > width) |
| { |
| |
| *last_p = UC_BREAK_POSSIBLE; |
| last_column = 0; |
| } |
|
|
| return last_column + piece_width; |
| } |
|
|
| #if defined IN_LIBUNISTRING |
| |
|
|
| # undef u16_width_linebreaks |
|
|
| int |
| u16_width_linebreaks (const uint16_t *s, size_t n, |
| int width, int start_column, int at_end_columns, |
| const char *o, const char *encoding, |
| char *p) |
| { |
| return u16_width_linebreaks_internal (s, n, |
| width, start_column, at_end_columns, |
| o, encoding, -1, p); |
| } |
|
|
| #endif |
|
|
| int |
| u16_width_linebreaks_v2 (const uint16_t *s, size_t n, |
| int width, int start_column, int at_end_columns, |
| const char *o, const char *encoding, |
| char *p) |
| { |
| return u16_width_linebreaks_internal (s, n, |
| width, start_column, at_end_columns, |
| o, encoding, LBP_CR, p); |
| } |
|
|