changeset 89062:be059fb97bac

(compile_pattern_1): Don't adjust the multibyteness of the regexp pattern and the matching target. Set cp->buf.multibyte to the multibyteness of the regexp pattern. Set cp->but.target_multibyte to the multibyteness of the matching target. (wordify): Use FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE instead of FETCH_STRING_CHAR_ADVANCE. (Freplace_match): Convert unibyte chars to multibyte.
author Kenichi Handa <handa@m17n.org>
date Tue, 03 Sep 2002 04:09:59 +0000
parents 9a9b54d06f3d
children 2054397a36be
files src/search.c
diffstat 1 files changed, 11 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/src/search.c	Tue Sep 03 04:09:40 2002 +0000
+++ b/src/search.c	Tue Sep 03 04:09:59 2002 +0000
@@ -117,51 +117,20 @@
      int posix;
      int multibyte;
 {
-  unsigned char *raw_pattern;
-  int raw_pattern_size;
   char *val;
   reg_syntax_t old;
 
-  /* MULTIBYTE says whether the text to be searched is multibyte.
-     We must convert PATTERN to match that, or we will not really
-     find things right.  */
-
-  if (multibyte == STRING_MULTIBYTE (pattern))
-    {
-      raw_pattern = (unsigned char *) XSTRING (pattern)->data;
-      raw_pattern_size = STRING_BYTES (XSTRING (pattern));
-    }
-  else if (multibyte)
-    {
-      raw_pattern_size = count_size_as_multibyte (XSTRING (pattern)->data,
-						  XSTRING (pattern)->size);
-      raw_pattern = (unsigned char *) alloca (raw_pattern_size + 1);
-      copy_text (XSTRING (pattern)->data, raw_pattern,
-		 XSTRING (pattern)->size, 0, 1);
-    }
-  else
-    {
-      /* Converting multibyte to single-byte.
-
-	 ??? Perhaps this conversion should be done in a special way
-	 by subtracting nonascii-insert-offset from each non-ASCII char,
-	 so that only the multibyte chars which really correspond to
-	 the chosen single-byte character set can possibly match.  */
-      raw_pattern_size = XSTRING (pattern)->size;
-      raw_pattern = (unsigned char *) alloca (raw_pattern_size + 1);
-      copy_text (XSTRING (pattern)->data, raw_pattern,
-		 STRING_BYTES (XSTRING (pattern)), 1, 0);
-    }
-
   cp->regexp = Qnil;
   cp->buf.translate = (! NILP (translate) ? translate : make_number (0));
   cp->posix = posix;
-  cp->buf.multibyte = multibyte;
+  cp->buf.multibyte = STRING_MULTIBYTE (pattern);
+  cp->buf.target_multibyte = multibyte;
   BLOCK_INPUT;
   old = re_set_syntax (RE_SYNTAX_EMACS
 		       | (posix ? 0 : RE_NO_POSIX_BACKTRACKING));
-  val = (char *) re_compile_pattern ((char *)raw_pattern,
-				     raw_pattern_size, &cp->buf);
+  val = (char *) re_compile_pattern ((char *) (XSTRING (pattern)->data),
+				     STRING_BYTES (XSTRING (pattern)),
+				     &cp->buf);
   re_set_syntax (old);
   UNBLOCK_INPUT;
   if (val)
@@ -1952,7 +1921,7 @@
     {
       int c;
       
-      FETCH_STRING_CHAR_ADVANCE (c, string, i, i_byte);
+      FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, i, i_byte);
 
       if (SYNTAX (c) != Sword)
 	{
@@ -1987,7 +1956,7 @@
       int c;
       int i_byte_orig = i_byte;
       
-      FETCH_STRING_CHAR_ADVANCE (c, string, i, i_byte);
+      FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, i, i_byte);
 
       if (SYNTAX (c) == Sword)
 	{
@@ -2245,21 +2214,14 @@
     {
       /* Decide how to casify by examining the matched text. */
       int last;
-      int multibyte;
 
       pos = search_regs.start[sub];
       last = search_regs.end[sub];
 
       if (NILP (string))
-	{
-	  pos_byte = CHAR_TO_BYTE (pos);
-	  multibyte = ! NILP (current_buffer->enable_multibyte_characters);
-	}
+	pos_byte = CHAR_TO_BYTE (pos);
       else
-	{
-	  pos_byte = string_char_to_byte (string, pos);
-	  multibyte = STRING_MULTIBYTE (string);
-	}
+	pos_byte = string_char_to_byte (string, pos);
 
       prevc = '\n';
       case_action = all_caps;
@@ -2275,15 +2237,11 @@
 	{
 	  if (NILP (string))
 	    {
-	      c = FETCH_CHAR (pos_byte);
+	      c = FETCH_CHAR_AS_MULTIBYTE (pos_byte);
 	      INC_BOTH (pos, pos_byte);
 	    }
 	  else
-	    FETCH_STRING_CHAR_ADVANCE (c, string, pos, pos_byte);
-	  if (! multibyte)
-	    {
-	      MAKE_CHAR_MULTIBYTE (c);
-	    }
+	    FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, pos, pos_byte);
 
 	  if (LOWERCASEP (c))
 	    {