Avoiding a compiler warning, and straightening out the logic.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4772 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
Benno Schulenberg 2014-04-14 20:42:10 +00:00
parent cd634e074c
commit ff8454a6f5
2 changed files with 7 additions and 9 deletions

View File

@ -8,6 +8,8 @@
* src/text.c (break_line): Initialize a variable to avoid a compiler
warning, rename it to be more apt, add a comment, tweak some others,
and remove an unneeded 'if'.
* src/char.c (move_mbleft): Avoid a compiler warning (int → size_t),
rename the variable, and another, and straighten out the logic.
2014-04-13 Benno Schulenberg <bensberg@justemail.net>
* proto.h, global.c, rcfile.c: Remove the unused parameter 'menu'

View File

@ -472,22 +472,18 @@ int parse_mbchar(const char *buf, char *chr, size_t *col)
* before the one at pos. */
size_t move_mbleft(const char *buf, size_t pos)
{
size_t pos_prev = pos;
size_t before = 0, char_len = 0;
assert(buf != NULL && pos <= strlen(buf));
/* There is no library function to move backward one multibyte
* character. Here is the naive, O(pos) way to do it. */
while (TRUE) {
int buf_mb_len = parse_mbchar(buf + pos - pos_prev, NULL, NULL);
if (pos_prev <= buf_mb_len)
break;
pos_prev -= buf_mb_len;
while (before < pos) {
char_len = parse_mbchar(buf + before, NULL, NULL);
before += char_len;
}
return pos - pos_prev;
return before - char_len;
}
/* Return the index in buf of the beginning of the multibyte character