]> granicus.if.org Git - mutt/commitdiff
A nicer version of {capitalize,...}-word functions.
authorThomas Roessler <roessler@does-not-exist.org>
Fri, 27 Oct 2000 10:51:01 +0000 (10:51 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Fri, 27 Oct 2000 10:51:01 +0000 (10:51 +0000)
enter.c

diff --git a/enter.c b/enter.c
index 6795ddc7263a75e5915cc507275875c195f3276d..3414d717a890bd8cfde52ee0cf416e07a9ed33ef 100644 (file)
--- a/enter.c
+++ b/enter.c
@@ -332,48 +332,32 @@ int _mutt_enter_string (unsigned char *buf, size_t buflen, int y, int x,
          break;
 
        case OP_EDITOR_CAPITALIZE_WORD:
-         if (curpos == lastchar)
-         {
-           BEEP ();
-           break;
-         }
-         while (curpos < lastchar && ISSPACE (buf[curpos]))
-           curpos++;
-         if (curpos < lastchar)
-         {
-           buf[curpos] = toupper (buf[curpos]);
-           curpos++;
-         }
-         if (curpos == lastchar || ISSPACE (buf[curpos]))
-         {       
-           if (!pass)
-           {
-             if (curpos >= begin + width)
-               begin = curpos - width / 2;
-             else
-               move (y, x + curpos - begin);
-             redraw = M_REDRAW_LINE;
-           }
-           break;
-         }
-         
-         /* fall through */
        case OP_EDITOR_UPCASE_WORD:
        case OP_EDITOR_DOWNCASE_WORD:
          if (curpos == lastchar)
          {
-           BEEP();
+           BEEP ();
            break;
          }
+         while (curpos > 0 && !ISSPACE (buf[curpos]))
+           curpos--;
          while (curpos < lastchar && ISSPACE (buf[curpos]))
            curpos++;
          while (curpos < lastchar && !ISSPACE(buf[curpos]))
          {
-           if (ch == OP_EDITOR_UPCASE_WORD)
-             buf[curpos] = toupper (buf[curpos]);
-           else /* DOWNCASE_WORD, CAPITALIZE_WORD */
-             buf[curpos] = tolower (buf[curpos]);
+           if (ch == OP_EDITOR_DOWNCASE_WORD)
+           {
+             if (isupper (buf[curpos]))
+               buf[curpos] = tolower (buf[curpos]);
+           }
+           else /* UPCASE_WORD, CAPITALIZE_WORD */
+           {
+             if (islower (buf[curpos]))
+               buf[curpos] = toupper (buf[curpos]);
+           }
            curpos++;
+           if (ch == OP_EDITOR_CAPITALIZE_WORD)
+             ch = OP_EDITOR_DOWNCASE_WORD;
          }
          if (!pass)
          {