Commit 3b216596 authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

tweaks: elide four #ifdefs, improve one comment and unwrap some others

No related merge requests found
Showing with 14 additions and 22 deletions
+14 -22
...@@ -55,18 +55,18 @@ bool using_utf8(void) ...@@ -55,18 +55,18 @@ bool using_utf8(void)
} }
#endif /* ENABLE_UTF8 */ #endif /* ENABLE_UTF8 */
/* Concatenate two allocated strings. */ /* Concatenate two allocated strings, and free the second. */
char *addstrings(char* str1, size_t len1, char* str2, size_t len2) char *addstrings(char* str1, size_t len1, char* str2, size_t len2)
{ {
str1 = charealloc(str1, len1 + len2 + 1); str1 = charealloc(str1, len1 + len2 + 1);
str1[len1] = '\0'; str1[len1] = '\0';
strncat(&str1[len1], str2, len2); strncat(&str1[len1], str2, len2);
free(str2); free(str2);
return str1; return str1;
} }
#ifndef HAVE_ISBLANK #ifndef HAVE_ISBLANK
/* This function is equivalent to isblank(). */ /* This function is equivalent to isblank(). */
bool nisblank(int c) bool nisblank(int c)
...@@ -83,8 +83,7 @@ bool niswblank(wchar_t wc) ...@@ -83,8 +83,7 @@ bool niswblank(wchar_t wc)
} }
#endif #endif
/* Return TRUE if the value of c is in byte range, and FALSE /* Return TRUE if the value of c is in byte range, and FALSE otherwise. */
* otherwise. */
bool is_byte(int c) bool is_byte(int c)
{ {
return ((unsigned int)c == (unsigned char)c); return ((unsigned int)c == (unsigned char)c);
...@@ -274,13 +273,12 @@ char *control_mbrep(const char *c, char *crep, int *crep_len) ...@@ -274,13 +273,12 @@ char *control_mbrep(const char *c, char *crep, int *crep_len)
*crep_len = 0; *crep_len = 0;
} }
} }
} else { } else
#endif #endif
{
*crep_len = 1; *crep_len = 1;
*crep = control_rep(*c); *crep = control_rep(*c);
#ifdef ENABLE_UTF8
} }
#endif
return crep; return crep;
} }
...@@ -309,13 +307,12 @@ char *mbrep(const char *c, char *crep, int *crep_len) ...@@ -309,13 +307,12 @@ char *mbrep(const char *c, char *crep, int *crep_len)
*crep_len = 0; *crep_len = 0;
} }
} }
} else { } else
#endif #endif
{
*crep_len = 1; *crep_len = 1;
*crep = *c; *crep = *c;
#ifdef ENABLE_UTF8
} }
#endif
return crep; return crep;
} }
...@@ -379,13 +376,12 @@ char *make_mbchar(long chr, int *chr_mb_len) ...@@ -379,13 +376,12 @@ char *make_mbchar(long chr, int *chr_mb_len)
wctomb_reset(); wctomb_reset();
*chr_mb_len = 0; *chr_mb_len = 0;
} }
} else { } else
#endif #endif
{
*chr_mb_len = 1; *chr_mb_len = 1;
chr_mb = mallocstrncpy(NULL, (char *)&chr, 1); chr_mb = mallocstrncpy(NULL, (char *)&chr, 1);
#ifdef ENABLE_UTF8
} }
#endif
return chr_mb; return chr_mb;
} }
...@@ -448,8 +444,9 @@ int parse_mbchar(const char *buf, char *chr, size_t *col) ...@@ -448,8 +444,9 @@ int parse_mbchar(const char *buf, char *chr, size_t *col)
} else } else
*col += mbwidth(buf); *col += mbwidth(buf);
} }
} else { } else
#endif #endif
{
/* Get the number of bytes in the byte character. */ /* Get the number of bytes in the byte character. */
buf_mb_len = 1; buf_mb_len = 1;
...@@ -472,9 +469,7 @@ int parse_mbchar(const char *buf, char *chr, size_t *col) ...@@ -472,9 +469,7 @@ int parse_mbchar(const char *buf, char *chr, size_t *col)
else else
(*col)++; (*col)++;
} }
#ifdef ENABLE_UTF8
} }
#endif
return buf_mb_len; return buf_mb_len;
} }
...@@ -542,8 +537,7 @@ int nstrncasecmp(const char *s1, const char *s2, size_t n) ...@@ -542,8 +537,7 @@ int nstrncasecmp(const char *s1, const char *s2, size_t n)
} }
#endif #endif
/* This function is equivalent to strncasecmp() for multibyte /* This function is equivalent to strncasecmp() for multibyte strings. */
* strings. */
int mbstrncasecmp(const char *s1, const char *s2, size_t n) int mbstrncasecmp(const char *s1, const char *s2, size_t n)
{ {
#ifdef ENABLE_UTF8 #ifdef ENABLE_UTF8
...@@ -706,8 +700,7 @@ char *revstrcasestr(const char *haystack, const char *needle, const char ...@@ -706,8 +700,7 @@ char *revstrcasestr(const char *haystack, const char *needle, const char
} }
/* This function is equivalent to strcasestr() for multibyte strings, /* This function is equivalent to strcasestr() for multibyte strings,
* except in that it scans the string in reverse, starting at * except in that it scans the string in reverse, starting at rev_start. */
* rev_start. */
char *mbrevstrcasestr(const char *haystack, const char *needle, const char *mbrevstrcasestr(const char *haystack, const char *needle, const
char *rev_start) char *rev_start)
{ {
...@@ -875,8 +868,7 @@ char *revstrpbrk(const char *s, const char *accept, const char ...@@ -875,8 +868,7 @@ char *revstrpbrk(const char *s, const char *accept, const char
} }
/* This function is equivalent to strpbrk() for multibyte strings, /* This function is equivalent to strpbrk() for multibyte strings,
* except in that it scans the string in reverse, starting at * except in that it scans the string in reverse, starting at rev_start. */
* rev_start. */
char *mbrevstrpbrk(const char *s, const char *accept, const char char *mbrevstrpbrk(const char *s, const char *accept, const char
*rev_start) *rev_start)
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment