do_cursorpos(). (DLR)
- Change the NANO_WIDE #define to ENABLE_UTF8, as the latter is
clearer. (DLR)
- - Properly handle cases where a search string and a match to it
- are not the same length in bytes, i.e, when the latter
- contains invalid multibyte characters interpreted as normal
- characters. Changes to mbstrncasecmp(), mbstrcasestr(),
- mbrevstrcasestr(), findnextstr(), and do_replace_loop(). (DLR)
- Make sure that the current position in the history list is
properly set to the bottom if we cancel out of the prompt.
New function history_reset(); changes to nanogetstr(). (DLR)
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;
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;
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;
/* Is this potential match a whole word? */
/* Set found_len to the length of the potential match. */
+ found_len =
#ifdef HAVE_REGEX_H
- if (ISSET(USE_REGEXP))
- found_len = regmatches[0].rm_eo - regmatches[0].rm_so;
- else
+ ISSET(USE_REGEXP) ?
+ regmatches[0].rm_eo - regmatches[0].rm_so :
#endif
- {
- size_t needle_len = mbstrlen(needle);
-
- /* Get found's length in single-byte characters. */
- found_len = 0;
-
- for (; needle_len > 0; needle_len--)
- found_len += parse_mbchar(found + found_len, NULL,
- NULL, NULL);
- }
+ strlen(needle);
/* If we're searching for whole words, see if this potential
* match is a whole word. */
#endif
if (i > 0 || replaceall) { /* Yes, replace it!!!! */
- char *match, *copy;
+ char *copy;
size_t length_change;
if (i == 2)
replaceall = TRUE;
- /* Make sure the string we replace is the match's length in
- * single-byte characters. */
- match = mallocstrncpy(NULL, openfile->current->data +
- openfile->current_x, match_len + 1);
- match[match_len] = '\0';
-
- copy = replace_line(match);
-
- free(match);
+ copy = replace_line(needle);
length_change = strlen(copy) -
strlen(openfile->current->data);