commit 31ff7ead7327b9c29df0b96c910f1581c2171603
parent 5398d986eff2084ecc166a6dc4d7ae3f62b9cd28
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Thu, 3 Oct 2019 11:20:48 +0200
tweaks: move a function to before its callers and next to its kind
Also, improve the indentation of two random lines.
Diffstat:
3 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/src/chars.c b/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)
diff --git a/src/proto.h b/src/proto.h
@@ -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
diff --git a/src/winio.c b/src/winio.c
@@ -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);