commit cd9a5f03770761d89323b262854a9dbd7e9b8457
parent c4b854d5c7b537d5425aab4426c6dcf0b945950c
Author: David Lawrence Ramsey <pooka109@gmail.com>
Date: Tue, 20 Sep 2005 06:12:54 +0000
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
Diffstat:
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -316,6 +316,9 @@ CVS code -
- text.c:
do_enter()
- 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()
- Rename to do_wordlinechar_count(), and expand to also count
the number of lines and characters in the file or selection,
diff --git a/src/text.c b/src/text.c
@@ -559,8 +559,8 @@ bool do_wrap(filestruct *line)
#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
- * that the display length to there is at most goal + 1. If there is no
- * such blank, then we find the first blank. We then take the last
+ * that the display length to there is at most (goal + 1). If there is
+ * 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, as does a '\n' if newline is TRUE. */
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);
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')) {
blank_loc = cur_loc;
@@ -606,7 +607,7 @@ ssize_t break_line(const char *line, ssize_t goal, bool newline)
if (!found_blank)
found_blank = TRUE;
} else if (found_blank)
- return cur_loc - line_len;
+ return move_mbleft(line, cur_loc);
line += line_len;
cur_loc += line_len;