tweaks: move a function to before its callers and next to its kind

Also, improve the indentation of two random lines.
This commit is contained in:
Benno Schulenberg 2019-10-03 11:20:48 +02:00
parent 5398d986ef
commit 31ff7ead73
3 changed files with 24 additions and 24 deletions

View File

@ -265,6 +265,27 @@ int char_length(const char *pointer)
return 1;
}
/* Return the number of (multibyte) characters in the given string. */
size_t mbstrlen(const char *pointer)
{
size_t count = 0;
while (*pointer != '\0') {
#ifdef ENABLE_UTF8
if ((signed char)*pointer < 0) {
int length = mblen(pointer, MAXCHARLEN);
pointer += (length < 0 ? 1 : length);
} else
#endif
pointer++;
count++;
}
return count;
}
/* 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. */
@ -488,27 +509,6 @@ char *mbrevstrcasestr(const char *haystack, const char *needle,
return revstrcasestr(haystack, needle, pointer);
}
/* Count the number of (multibyte) characters in the given string. */
size_t mbstrlen(const char *pointer)
{
size_t count = 0;
while (*pointer != '\0') {
#ifdef ENABLE_UTF8
if ((signed char)*pointer < 0) {
int length = mblen(pointer, MAXCHARLEN);
pointer += (length < 0 ? 1 : length);
} else
#endif
pointer++;
count++;
}
return count;
}
#if !defined(NANO_TINY) || defined(ENABLE_JUSTIFY)
/* This function is equivalent to strchr() for multibyte strings. */
char *mbstrchr(const char *string, const char *chr)

View File

@ -218,6 +218,7 @@ int mbwidth(const char *c);
#endif
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);
size_t step_left(const char *buf, size_t pos);
size_t step_right(const char *buf, size_t pos);
@ -226,7 +227,6 @@ int mbstrncasecmp(const char *s1, const char *s2, size_t n);
char *mbstrcasestr(const char *haystack, const char *needle);
char *revstrstr(const char *haystack, const char *needle, const char *index);
char *mbrevstrcasestr(const char *haystack, const char *needle, const char *index);
size_t mbstrlen(const char *s);
#if !defined(NANO_TINY) || defined(ENABLE_JUSTIFY)
char *mbstrchr(const char *s, const char *c);
#endif