in break_line(), fix a problem where a line could be broken in the

middle of a multibyte character


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3022 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2005-09-20 06:12:54 +00:00
parent c4b854d5c7
commit cd9a5f0377
2 changed files with 9 additions and 5 deletions

View File

@ -316,6 +316,9 @@ CVS code -
- text.c: - text.c:
do_enter() do_enter()
- Don't update the edit window until we set placewewant. (DLR) - Don't update the edit window until we set placewewant. (DLR)
break_line()
- Fix a problem where a line could be broken in the middle of
a multibyte character. (DLR)
do_word_count() do_word_count()
- Rename to do_wordlinechar_count(), and expand to also count - Rename to do_wordlinechar_count(), and expand to also count
the number of lines and characters in the file or selection, the number of lines and characters in the file or selection,

View File

@ -559,8 +559,8 @@ bool do_wrap(filestruct *line)
#if !defined(DISABLE_HELP) || !defined(DISABLE_JUSTIFY) || !defined(DISABLE_WRAPPING) #if !defined(DISABLE_HELP) || !defined(DISABLE_JUSTIFY) || !defined(DISABLE_WRAPPING)
/* We are trying to break a chunk off line. We find the last blank such /* We are trying to break a chunk off line. We find the last blank such
* that the display length to there is at most goal + 1. If there is no * that the display length to there is at most (goal + 1). If there is
* such blank, then we find the first blank. We then take the last * no such blank, then we find the first blank. We then take the last
* blank in that group of blanks. The terminating '\0' counts as a * blank in that group of blanks. The terminating '\0' counts as a
* blank, as does a '\n' if newline is TRUE. */ * blank, as does a '\n' if newline is TRUE. */
ssize_t break_line(const char *line, ssize_t goal, bool newline) ssize_t break_line(const char *line, ssize_t goal, bool newline)
@ -575,9 +575,10 @@ ssize_t break_line(const char *line, ssize_t goal, bool newline)
assert(line != NULL); assert(line != NULL);
while (*line != '\0' && goal >= 0) { while (*line != '\0' && goal >= 0) {
size_t pos = 0; int pos;
line_len = parse_mbchar(line, NULL, &pos); line_len = parse_mbchar(line, NULL, NULL);
pos = mbwidth(line);
if (is_blank_mbchar(line) || (newline && *line == '\n')) { if (is_blank_mbchar(line) || (newline && *line == '\n')) {
blank_loc = cur_loc; blank_loc = cur_loc;
@ -606,7 +607,7 @@ ssize_t break_line(const char *line, ssize_t goal, bool newline)
if (!found_blank) if (!found_blank)
found_blank = TRUE; found_blank = TRUE;
} else if (found_blank) } else if (found_blank)
return cur_loc - line_len; return move_mbleft(line, cur_loc);
line += line_len; line += line_len;
cur_loc += line_len; cur_loc += line_len;