]> andersk Git - moira.git/commitdiff
fix FixCase() to only capitalize the letter after an apostrophe if the
authordanw <danw>
Sun, 20 Dec 1998 21:23:18 +0000 (21:23 +0000)
committerdanw <danw>
Sun, 20 Dec 1998 21:23:18 +0000 (21:23 +0000)
apostrophe is the second character in the word. (eg, "O'BRIEN" ->
"O'Brien", but "PRESIDENT'S OFFICE" -> "President's Office", not
"President'S Office".)

lib/fixname.c

index 26e880e263aad1bd83f00dce21674fd1704e9aad..dc37c0e597c0a65167962cc11c8136775ff95fb6 100644 (file)
@@ -50,19 +50,27 @@ void FixName(char *ilnm, char *ifnm, char *last, char *first, char *middle)
 
 void FixCase(char *p)
 {
-  int cflag;   /* convert to lcase, unless at start or following */
-               /* a space or punctuation mark (e.g., '-') */
+  int up;      /* Should next letter be uppercase */
+  int pos;     /* Position within word */
 
-  for (cflag = 0; *p; p++)
+  for (up = 1, pos = 1; *p; p++, pos++)
     {
-      if (cflag && isupper(*p))
+      if (!up && isupper(*p))
        *p = tolower(*p);
-      else if (!cflag && islower(*p))
+      else if (up && islower(*p))
        *p = toupper(*p);
-      if (isalpha(*p))
-       cflag = 1;
+
+      if (isalpha(*p))         /* If letter, next letter should be lower */
+       up = 0;
+      else if (isspace(*p))    /* If space, next letter should be upper */
+       {
+         pos = 0;
+         up = 1;
+       }
+      else if (*p == '\'')     /* If ', next letter should be upper only */
+       up = (pos == 2);        /* if the ' is the 2nd char in the name */
       else
-       cflag = 0;
+       up = 1;                 /* If other punctuation (eg, -), upper */
     }
 }
 
This page took 0.298918 seconds and 5 git commands to generate.