tweaks: rename a function, and elide a parameter that is always NULL

After the previous change, all remaining calls of parse_mbchar() have
NULL as their third parameter.  So, drop that parameter and remove the
chunk of code that handles it.  Also rename the function, as there are
already too many functions that start with "parse".
master
Benno Schulenberg 2019-10-21 12:35:14 +02:00
parent c2d8641f01
commit fa88fcc8f2
8 changed files with 20 additions and 41 deletions

View File

@ -160,7 +160,7 @@ bool is_word_mbchar(const char *c, bool allow_punct)
if (word_chars != NULL && *word_chars != '\0') {
char symbol[MAXCHARLEN + 1];
int symlen = parse_mbchar(c, symbol, NULL);
int symlen = collect_char(c, symbol);
symbol[symlen] = '\0';
return (strstr(word_chars, symbol) != NULL);
@ -287,9 +287,8 @@ size_t mbstrlen(const char *pointer)
}
/* Parse a multibyte character from buf. Return the number of bytes
* used. If chr isn't NULL, store the multibyte character in it. If
* col isn't NULL, add the character's width (in columns) to it. */
int parse_mbchar(const char *buf, char *chr, size_t *col)
* used, and store the multibyte character in *chr. */
int collect_char(const char *buf, char *chr)
{
int length;
@ -305,30 +304,10 @@ int parse_mbchar(const char *buf, char *chr, size_t *col)
#endif
length = 1;
/* When requested, store the multibyte character in chr. */
if (chr != NULL)
/* Store the multibyte character in chr. */
for (int i = 0; i < length; i++)
chr[i] = buf[i];
/* When requested, add the width of the character to col. */
if (col != NULL) {
/* If we have a tab, compute its width in columns based on the
* current value of col. */
if (*buf == '\t')
*col += tabsize - *col % tabsize;
/* If we have a control character, it's two columns wide: one
* column for the "^", and one for the visible character. */
else if (is_cntrl_mbchar(buf))
*col += 2;
/* If we have a normal character, get its width normally. */
else if (length == 1)
*col += 1;
#ifdef ENABLE_UTF8
else
*col += mbwidth(buf);
#endif
}
return length;
}
@ -622,7 +601,7 @@ bool has_blank_char(const char *string)
char symbol[MAXCHARLEN];
while (*string != '\0') {
string += parse_mbchar(string, symbol, NULL);
string += collect_char(string, symbol);
if (is_blank_mbchar(symbol))
return TRUE;

View File

@ -2489,10 +2489,10 @@ char *input_tab(char *buf, bool allow_files, size_t *place,
/* Get the number of characters that all matches have in common. */
while (TRUE) {
len1 = parse_mbchar(matches[0] + common_len, char1, NULL);
len1 = collect_char(matches[0] + common_len, char1);
for (match = 1; match < num_matches; match++) {
len2 = parse_mbchar(matches[match] + common_len, char2, NULL);
len2 = collect_char(matches[match] + common_len, char2);
if (len1 != len2 || strncmp(char1, char2, len2) != 0)
break;

View File

@ -1813,7 +1813,7 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
output[i] = '\n';
/* Get the next multibyte character. */
charlen = parse_mbchar(output + i, onechar, NULL);
charlen = collect_char(output + i, onechar);
i += charlen;

View File

@ -203,7 +203,7 @@ void do_statusbar_output(int *the_input, size_t input_len,
output[j] = '\n';
/* Interpret the next multibyte character. */
charlen = parse_mbchar(output + j, onechar, NULL);
charlen = collect_char(output + j, onechar);
j += charlen;

View File

@ -216,7 +216,7 @@ int mbwidth(const char *c);
char *make_mbchar(long chr, int *chr_mb_len);
int char_length(const char *pointer);
size_t mbstrlen(const char *s);
int parse_mbchar(const char *buf, char *chr, size_t *col);
int collect_char(const char *buf, char *chr);
int advance_over(const char *string, size_t *column);
size_t step_left(const char *buf, size_t pos);
size_t step_right(const char *buf, size_t pos);

View File

@ -1178,8 +1178,8 @@ void add_undo(undo_type action, const char *message)
* else purposely fall into the line-joining code. */
if (openfile->current->data[openfile->current_x] != '\0') {
char *char_buf = charalloc(MAXCHARLEN + 1);
int charlen = parse_mbchar(&openfile->current->data[u->begin],
char_buf, NULL);
int charlen = collect_char(&openfile->current->data[u->begin],
char_buf);
char_buf[charlen] = '\0';
u->strdata = char_buf;
if (u->type == BACK)
@ -1300,8 +1300,8 @@ void update_undo(undo_type action)
switch (u->type) {
case ADD:
char_buf = charalloc(MAXCHARLEN);
charlen = parse_mbchar(&openfile->current->data[u->mark_begin_x],
char_buf, NULL);
charlen = collect_char(&openfile->current->data[u->mark_begin_x],
char_buf);
u->strdata = addstrings(u->strdata, u->strdata ? strlen(u->strdata) : 0,
char_buf, charlen);
u->mark_begin_lineno = openfile->current->lineno;
@ -1314,8 +1314,8 @@ void update_undo(undo_type action)
case BACK:
case DEL:
char_buf = charalloc(MAXCHARLEN);
charlen = parse_mbchar(&openfile->current->data[openfile->current_x],
char_buf, NULL);
charlen = collect_char(&openfile->current->data[openfile->current_x],
char_buf);
if (openfile->current_x == u->begin) {
/* They deleted more: add removed character after earlier stuff. */
u->strdata = addstrings(u->strdata, strlen(u->strdata), char_buf, charlen);
@ -1637,7 +1637,7 @@ size_t indent_length(const char *line)
int charlen;
while (*line != '\0') {
charlen = parse_mbchar(line, onechar, NULL);
charlen = collect_char(line, onechar);
if (!is_blank_mbchar(onechar))
break;

View File

@ -203,8 +203,8 @@ bool is_separate_word(size_t position, size_t length, const char *buf)
size_t word_end = position + length;
/* Get the characters before and after the word, if any. */
parse_mbchar(buf + step_left(buf, position), before, NULL);
parse_mbchar(buf + word_end, after, NULL);
collect_char(buf + step_left(buf, position), before);
collect_char(buf + word_end, after);
/* If the word starts at the beginning of the line OR the character before
* the word isn't a letter, and if the word ends at the end of the line OR

View File

@ -2686,7 +2686,7 @@ void draw_row(int row, const char *converted, linestruct *line, size_t from_col)
size_t charlen = 1;
if (*(converted + target_x) != '\0') {
charlen = parse_mbchar(converted + target_x, striped_char, NULL);
charlen = collect_char(converted + target_x, striped_char);
target_column = wideness(converted, target_x);
} else if (target_column + 1 == editwincols) {
/* Defeat a VTE bug -- see https://sv.gnu.org/bugs/?55896. */