main(), search_init(), nanorc.sample, nano.1, nanorc.5,
nano.texi, etc. (DLR)
- Various cleanups in chars.c. Remove some unnecessary (w)ctype
- wrappers, change other ctype wrappers to take wint_t instead
- of wchar_t, and rename some functions for consistency. Changes
+ wrappers; change other ctype wrappers to take wint_t instead
+ of wchar_t; rename some functions for consistency; and don't
+ count matches between valid and invalid multibyte sequences
+ anymore, as it causes problems when doing a replace. Changes
to is_alnum_mbchar(), is_blank_char() (renamed nisblank()),
is_blank_mbchar(), is_blank_wchar() (renamed niswblank()),
- is_cntrl_wchar(), control_rep(), control_mbrep(), etc.;
+ is_cntrl_wchar(), control_rep(), control_mbrep(),
+ mbstrncasecmp(), mbstrcasestr(), mbrevstrcasestr(), etc.;
removal of is_alnum_char() and is_alnum_wchar(). (DLR)
- Implement word count via Meta-D at the main window. Note that
this is disabled when NANO_SMALL is defined. New functions
}
*crep_len = crep_mb_len;
-
- return crep;
} else {
#endif
*crep_len = 1;
*crep = control_rep(*c);
-
- return crep;
#ifdef NANO_WIDE
}
#endif
+
+ return crep;
}
/* This function is equivalent to wcwidth() for multibyte characters. */
{
return
#ifdef NANO_WIDE
- !ISSET(NO_UTF8) ? MB_CUR_MAX :
+ (!ISSET(NO_UTF8)) ? MB_CUR_MAX :
#endif
1;
}
size_t str_mb_len = 0;
while (*str != '\0') {
- bool bad_char;
+ bool bad_chr;
int i;
- chr_mb_len = parse_mbchar(str, chr_mb, &bad_char, NULL);
+ chr_mb_len = parse_mbchar(str, chr_mb, &bad_chr, NULL);
- if (bad_char) {
+ if (bad_chr) {
char *bad_chr_mb;
int bad_chr_mb_len;
#endif
return mallocstrcpy(NULL, str);
}
-#endif
+#endif /* ENABLE_NANORC || NANO_EXTRA */
/* Parse a multibyte character from buf. Return the number of bytes
* used. If chr isn't NULL, store the multibyte character in it. If
}
if (n > 0)
- return (tolower(*s1) - tolower(*s2));
+ return tolower(*s1) - tolower(*s2);
else
return 0;
}
assert(s1 != NULL && s2 != NULL);
while (n > 0 && *s1 != '\0' && *s2 != '\0') {
+ bool bad_s1_mb = FALSE, bad_s2_mb = FALSE;
int s1_mb_len, s2_mb_len;
s1_mb_len = parse_mbchar(s1, s1_mb, NULL, NULL);
if (mbtowc(&ws1, s1_mb, s1_mb_len) <= 0) {
mbtowc(NULL, NULL, 0);
ws1 = (unsigned char)*s1_mb;
+ bad_s1_mb = TRUE;
}
s2_mb_len = parse_mbchar(s2, s2_mb, NULL, NULL);
if (mbtowc(&ws2, s2_mb, s2_mb_len) <= 0) {
mbtowc(NULL, NULL, 0);
ws2 = (unsigned char)*s2_mb;
+ bad_s2_mb = TRUE;
}
- if (n == 0 || towlower(ws1) != towlower(ws2))
+ if (n == 0 || bad_s1_mb != bad_s2_mb ||
+ towlower(ws1) != towlower(ws2))
break;
s1 += s1_mb_len;
free(s1_mb);
free(s2_mb);
- return (towlower(ws1) - towlower(ws2));
+ return towlower(ws1) - towlower(ws2);
} else
#endif
return strncasecmp(s1, s2, n);
int r_mb_len, q_mb_len;
while (*q != '\0') {
+ bool bad_r_mb = FALSE, bad_q_mb = FALSE;
+
r_mb_len = parse_mbchar(r, r_mb, NULL, NULL);
if (mbtowc(&wr, r_mb, r_mb_len) <= 0) {
mbtowc(NULL, NULL, 0);
wr = (unsigned char)*r;
+ bad_r_mb = TRUE;
}
q_mb_len = parse_mbchar(q, q_mb, NULL, NULL);
if (mbtowc(&wq, q_mb, q_mb_len) <= 0) {
mbtowc(NULL, NULL, 0);
wq = (unsigned char)*q;
+ bad_q_mb = TRUE;
}
- if (towlower(wr) != towlower(wq))
+ if (bad_r_mb != bad_q_mb ||
+ towlower(wr) != towlower(wq))
break;
r += r_mb_len;
free(r_mb);
free(q_mb);
- return found_needle ? haystack : NULL;
+ return (found_needle) ? haystack : NULL;
} else
#endif
return strcasestr(haystack, needle);
}
-#if !defined(NANO_SMALL) || !defined(DISABLE_TABCOMP)
+#ifndef NANO_SMALL
+#ifndef DISABLE_TABCOMP
/* This function is equivalent to strstr(), except in that it scans the
* string in reverse, starting at rev_start. */
const char *revstrstr(const char *haystack, const char *needle, const
return NULL;
}
-#endif
+#endif /* !DISABLE_TABCOMP */
-#ifndef NANO_SMALL
/* This function is equivalent to strcasestr(), except in that it scans
* the string in reverse, starting at rev_start. */
const char *revstrcasestr(const char *haystack, const char *needle,
int r_mb_len, q_mb_len;
while (*q != '\0') {
+ bool bad_r_mb = FALSE, bad_q_mb = FALSE;
+
r_mb_len = parse_mbchar(r, r_mb, NULL, NULL);
if (mbtowc(&wr, r_mb, r_mb_len) <= 0) {
mbtowc(NULL, NULL, 0);
wr = (unsigned char)*r;
+ bad_r_mb = TRUE;
}
q_mb_len = parse_mbchar(q, q_mb, NULL, NULL);
if (mbtowc(&wq, q_mb, q_mb_len) <= 0) {
mbtowc(NULL, NULL, 0);
wq = (unsigned char)*q;
+ bad_q_mb = TRUE;
}
- if (towlower(wr) != towlower(wq))
+ if (bad_r_mb != bad_q_mb ||
+ towlower(wr) != towlower(wq))
break;
r += r_mb_len;
free(r_mb);
free(q_mb);
- return found_needle ? rev_start : NULL;
+ return (found_needle) ? rev_start : NULL;
} else
#endif
return revstrcasestr(haystack, needle, rev_start);
}
-#endif
+#endif /* !NANO_SMALL */
/* This function is equivalent to strlen() for multibyte strings. */
size_t mbstrlen(const char *s)
#ifdef NANO_WIDE
if (!ISSET(NO_UTF8)) {
size_t n = 0;
- char *s_mb = charalloc(MB_CUR_MAX);
int s_mb_len;
while (*s != '\0') {
- s_mb_len = parse_mbchar(s, s_mb, NULL, NULL);
+ s_mb_len = parse_mbchar(s, NULL, NULL, NULL);
if (maxlen == 0)
break;
n++;
}
- free(s_mb);
-
return n;
} else
#endif
#endif
return strchr(s, *c);
}
-#endif
+#endif /* !DISABLE_JUSTIFY */