changeset 2393:a35d2c5cbb3b

(Freplace_match): Clean up criterion about converting case. If old text has any capitalized words, capitalize new text.
author Richard M. Stallman <rms@gnu.org>
date Sun, 28 Mar 1993 05:21:24 +0000
parents 319c8db6eb51
children 6ec15e6b2a08
files src/search.c
diffstat 1 files changed, 19 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/search.c	Sun Mar 28 05:20:42 1993 +0000
+++ b/src/search.c	Sun Mar 28 05:21:24 1993 +0000
@@ -1147,7 +1147,8 @@
   enum { nochange, all_caps, cap_initial } case_action;
   register int pos, last;
   int some_multiletter_word;
-  int some_letter = 0;
+  int some_lowercase;
+  int some_uppercase_initial;
   register int c, prevc;
   int inslen;
 
@@ -1162,8 +1163,8 @@
   if (search_regs.start[0] < BEGV
       || search_regs.start[0] > search_regs.end[0]
       || search_regs.end[0] > ZV)
-    args_out_of_range(make_number (search_regs.start[0]),
-		      make_number (search_regs.end[0]));
+    args_out_of_range (make_number (search_regs.start[0]),
+		       make_number (search_regs.end[0]));
 
   if (NILP (fixedcase))
     {
@@ -1176,6 +1177,8 @@
       /* some_multiletter_word is set nonzero if any original word
 	 is more than one letter long. */
       some_multiletter_word = 0;
+      some_lowercase = 0;
+      some_uppercase_initial = 0;
 
       for (pos = search_regs.start[0]; pos < last; pos++)
 	{
@@ -1184,33 +1187,32 @@
 	    {
 	      /* Cannot be all caps if any original char is lower case */
 
-	      case_action = cap_initial;
+	      some_lowercase = 1;
 	      if (SYNTAX (prevc) != Sword)
-		{
-		  /* Cannot even be cap initials
-		     if some original initial is lower case */
-		  case_action = nochange;
-		  break;
-		}
+		;
 	      else
 		some_multiletter_word = 1;
 	    }
 	  else if (!NOCASEP (c))
 	    {
-	      some_letter = 1;
-	      if (!some_multiletter_word && SYNTAX (prevc) == Sword)
+	      if (SYNTAX (prevc) != Sword)
+		some_uppercase_initial = 1;
+	      else
 		some_multiletter_word = 1;
 	    }
 
 	  prevc = c;
 	}
 
-      /* Do not make new text all caps
-	 if the original text contained only single letter words. */
-      if (case_action == all_caps && !some_multiletter_word)
+      /* Convert to all caps if the old text is all caps
+	 and has at least one multiletter word.  */
+      if (! some_lowercase && some_multiletter_word)
+	case_action = all_caps;
+      /* Capitalize each word, if the old text has a capitalized word.  */
+      else if (some_uppercase_initial)
 	case_action = cap_initial;
-
-      if (!some_letter) case_action = nochange;
+      else
+	case_action = nochange;
     }
 
   SET_PT (search_regs.end[0]);