* 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'
* 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