aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKarl Heuer <[email protected]>1998-06-20 22:28:28 +0000
committerKarl Heuer <[email protected]>1998-06-20 22:28:28 +0000
commitac3b28b1940043dec8e2e77ecb0a0956783403a5 (patch)
tree4990bd1568b759ff92f122558f10d6fdf61b89ee /src
parenta9155e8732d3ce369769311946ac932b589a3749 (diff)
(Freplace_match): Work by chars, not by bytes,
for scanning the old text, and for inserting new string in buffer.
Diffstat (limited to 'src')
-rw-r--r--src/search.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/search.c b/src/search.c
index d9d445afad..d706854743 100644
--- a/src/search.c
+++ b/src/search.c
@@ -2187,7 +2187,7 @@ since only regular expressions have distinguished subexpressions.")
Lisp_Object newtext, fixedcase, literal, string, subexp;
{
enum { nochange, all_caps, cap_initial } case_action;
- register int pos, last;
+ register int pos, pos_byte;
int some_multiletter_word;
int some_lowercase;
int some_uppercase;
@@ -2237,18 +2237,16 @@ since only regular expressions have distinguished subexpressions.")
if (NILP (fixedcase))
{
- int beg;
/* Decide how to casify by examining the matched text. */
+ int last;
- if (NILP (string))
- last = CHAR_TO_BYTE (search_regs.end[sub]);
- else
- last = search_regs.end[sub];
+ pos = search_regs.start[sub];
+ last = search_regs.end[sub];
if (NILP (string))
- beg = CHAR_TO_BYTE (search_regs.start[sub]);
+ pos_byte = CHAR_TO_BYTE (pos);
else
- beg = search_regs.start[sub];
+ pos_byte = string_char_to_byte (string, pos);
prevc = '\n';
case_action = all_caps;
@@ -2260,12 +2258,15 @@ since only regular expressions have distinguished subexpressions.")
some_nonuppercase_initial = 0;
some_uppercase = 0;
- for (pos = beg; pos < last; pos++)
+ while (pos < last)
{
if (NILP (string))
- c = FETCH_BYTE (pos);
+ {
+ c = FETCH_CHAR (pos_byte);
+ INC_BOTH (pos, pos_byte);
+ }
else
- c = XSTRING (string)->data[pos];
+ FETCH_STRING_CHAR_ADVANCE (c, string, pos, pos_byte);
if (LOWERCASEP (c))
{
@@ -2329,11 +2330,11 @@ since only regular expressions have distinguished subexpressions.")
/* We build up the substituted string in ACCUM. */
Lisp_Object accum;
Lisp_Object middle;
- int pos_byte;
+ int length = STRING_BYTES (XSTRING (newtext));
accum = Qnil;
- for (pos_byte = 0, pos = 0; pos_byte < STRING_BYTES (XSTRING (newtext));)
+ for (pos_byte = 0, pos = 0; pos_byte < length;)
{
int substart = -1;
int subend;
@@ -2425,16 +2426,19 @@ since only regular expressions have distinguished subexpressions.")
else
{
struct gcpro gcpro1;
+ int length = STRING_BYTES (XSTRING (newtext));
+
GCPRO1 (newtext);
- for (pos = 0; pos < XSTRING (newtext)->size; pos++)
+ for (pos_byte = 0, pos = 0; pos_byte < length;)
{
int offset = PT - search_regs.start[sub];
- c = XSTRING (newtext)->data[pos];
+ FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte);
+
if (c == '\\')
{
- c = XSTRING (newtext)->data[++pos];
+ FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte);
if (c == '&')
Finsert_buffer_substring
(Fcurrent_buffer (),