utils: rename some variables, to match those in strnlenpt()

master
Benno Schulenberg 2016-05-28 13:23:41 +02:00
parent e3e3f655ee
commit fbd817fb94
1 changed files with 15 additions and 17 deletions

View File

@ -461,29 +461,28 @@ size_t xplustabs(void)
return strnlenpt(openfile->current->data, openfile->current_x); return strnlenpt(openfile->current->data, openfile->current_x);
} }
/* Return the index in s of the character displayed at the given column, /* Return the index in text of the character that (when displayed) will
* i.e. the largest value such that strnlenpt(s, actual_x(s, column)) <= * not overshoot the given column. */
* column. */ size_t actual_x(const char *text, size_t column)
size_t actual_x(const char *s, size_t column)
{ {
size_t i = 0; size_t index = 0;
/* The position in s, returned. */ /* The index in text, returned. */
size_t len = 0; size_t width = 0;
/* The screen display width to s[i]. */ /* The screen display width to text[index], in columns. */
assert(s != NULL); assert(text != NULL);
while (*s != '\0') { while (*text != '\0') {
int s_len = parse_mbchar(s, NULL, &len); int charlen = parse_mbchar(text, NULL, &width);
if (len > column) if (width > column)
break; break;
i += s_len; index += charlen;
s += s_len; text += charlen;
} }
return i; return index;
} }
/* A strnlen() with tabs and multicolumn characters factored in: /* A strnlen() with tabs and multicolumn characters factored in:
@ -501,12 +500,11 @@ size_t strnlenpt(const char *text, size_t maxlen)
while (*text != '\0') { while (*text != '\0') {
int charlen = parse_mbchar(text, NULL, &width); int charlen = parse_mbchar(text, NULL, &width);
text += charlen;
if (maxlen <= charlen) if (maxlen <= charlen)
break; break;
maxlen -= charlen; maxlen -= charlen;
text += charlen;
} }
return width; return width;