diff src/regex.c @ 1377:19738a2a5138

[xemacs-hg @ 2003-03-24 15:01:47 by stephent] don't use DB_AUTO_COMMIT <87ptog3j6t.fsf@tleepslib.sk.tsukuba.ac.jp> fix word boundary code in regex.c <87smtc3jfv.fsf@tleepslib.sk.tsukuba.ac.jp>
author stephent
date Mon, 24 Mar 2003 15:01:50 +0000
parents 8d350b095c21
children 56496b493888
line wrap: on
line diff
--- a/src/regex.c	Mon Mar 24 14:51:46 2003 +0000
+++ b/src/regex.c	Mon Mar 24 15:01:50 2003 +0000
@@ -6070,43 +6070,63 @@
 	matchwordbound:
 	  {
 	    /* XEmacs change */
-	    int result;
-	    if (AT_STRINGS_BEG (d) || AT_STRINGS_END (d))
-	      result = 1;
+	    /* Straightforward and (I hope) correct implementation.
+	       Probably should be optimized by arranging to compute
+	       pos only once. */
+	    /* emch1 is the character before d, syn1 is the syntax of
+	       emch1, emch2 is the character at d, and syn2 is the
+	       syntax of emch2. */
+	    Ichar emch1, emch2;
+	    int syn1, syn2;
+	    re_char *d_before, *d_after;
+	    int result,
+		at_beg = AT_STRINGS_BEG (d),
+		at_end = AT_STRINGS_END (d);
+#ifdef emacs
+	    Charxpos pos;
+#endif
+
+	    if (at_beg && at_end)
+	      {
+		result = 0;
+	      }
 	    else
 	      {
-		re_char *d_before = POS_BEFORE_GAP_UNSAFE (d);
-		re_char *d_after = POS_AFTER_GAP_UNSAFE (d);
-
-		/* emch1 is the character before d, syn1 is the syntax of
-		   emch1, emch2 is the character at d, and syn2 is the
-		   syntax of emch2. */
-		Ichar emch1, emch2;
-		int syn1, syn2;
+		if (!at_beg)
+		  {
+		    d_before = POS_BEFORE_GAP_UNSAFE (d);
+		    DEC_IBYTEPTR_FMT (d_before, fmt);
+		    emch1 = itext_ichar_fmt (d_before, fmt, lispobj);
 #ifdef emacs
-		Charxpos pos_before;
+		    pos = offset_to_charxpos (lispobj, PTR_TO_OFFSET (d)) - 1;
+		    BEGIN_REGEX_MALLOC_OK ();
+		    UPDATE_SYNTAX_CACHE (scache, pos);
 #endif
-
-		DEC_IBYTEPTR_FMT (d_before, fmt);
-		emch1 = itext_ichar_fmt (d_before, fmt, lispobj);
-		emch2 = itext_ichar_fmt (d_after, fmt, lispobj);
-
+		    syn1 = SYNTAX_FROM_CACHE (scache, emch1);
+		    END_REGEX_MALLOC_OK ();
+		  }
+		if (!at_end)
+		  {
+		    d_after = POS_AFTER_GAP_UNSAFE (d);
+		    emch2 = itext_ichar_fmt (d_after, fmt, lispobj);
 #ifdef emacs
-		pos_before =
-		  offset_to_charxpos (lispobj, PTR_TO_OFFSET (d)) - 1;
-		BEGIN_REGEX_MALLOC_OK ();
-		UPDATE_SYNTAX_CACHE (scache, pos_before);
+		    pos = offset_to_charxpos (lispobj, PTR_TO_OFFSET (d));
+		    BEGIN_REGEX_MALLOC_OK ();
+		    UPDATE_SYNTAX_CACHE_FORWARD (scache, pos);
 #endif
-		syn1 = SYNTAX_FROM_CACHE (scache, emch1);
-#ifdef emacs
-		UPDATE_SYNTAX_CACHE_FORWARD (scache, pos_before + 1);
-#endif
-		syn2 = SYNTAX_FROM_CACHE (scache, emch2);
-
-		result = ((syn1 == Sword) != (syn2 == Sword));
-		END_REGEX_MALLOC_OK ();
+		    syn2 = SYNTAX_FROM_CACHE (scache, emch2);
+		    END_REGEX_MALLOC_OK ();
+		  }
 		RE_MATCH_RELOCATE_MOVEABLE_DATA_POINTERS ();
+
+		if (at_beg)
+		  result = (syn2 == Sword);
+		else if (at_end)
+		  result = (syn1 == Sword);
+		else
+		  result = ((syn1 == Sword) != (syn2 == Sword));
 	      }
+
 	    if (result == should_succeed)
 	      break;
 	    goto fail;