mirror of git://git.sv.gnu.org/nano.git
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:
parent
5398d986ef
commit
31ff7ead73
44
src/chars.c
44
src/chars.c
|
@ -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. */
|
||||
|
@ -347,7 +368,7 @@ size_t step_left(const char *buf, size_t pos)
|
|||
return before - charlen;
|
||||
} else
|
||||
#endif
|
||||
return (pos == 0 ? 0 : pos - 1);
|
||||
return (pos == 0 ? 0 : pos - 1);
|
||||
}
|
||||
|
||||
/* Return the index in buf of the beginning of the multibyte character
|
||||
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1984,7 +1984,7 @@ char *display_string(const char *buf, size_t column, size_t span,
|
|||
|
||||
/* If there is more text than can be shown, make room for the ">". */
|
||||
if (column > beyond || (*buf != '\0' && (isprompt ||
|
||||
(isdata && !ISSET(SOFTWRAP))))) {
|
||||
(isdata && !ISSET(SOFTWRAP))))) {
|
||||
#ifdef ENABLE_UTF8
|
||||
do {
|
||||
index = step_left(converted, index);
|
||||
|
|
Loading…
Reference in New Issue