]> andersk Git - moira.git/blobdiff - lib/fixname.c
Command line printer manipulation client, and build goo.
[moira.git] / lib / fixname.c
index 178f3feaef92195ebfdd816aa7c9551510509702..d77bf37afb17179058a4fe4594ba401c4f79ec20 100644 (file)
@@ -48,21 +48,31 @@ void FixName(char *ilnm, char *ifnm, char *last, char *first, char *middle)
   strncpy(first, ifnm, FIRST_LEN);
 }
 
-void FixCase(char *p)
+void FixCase(unsigned 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 if (*p >= 0x80)      /* If the high bit is set, don't touch it. */
+       up = 0;
       else
-       cflag = 0;
+       up = 1;                 /* If other punctuation (eg, -), upper */
     }
 }
 
@@ -147,3 +157,17 @@ void GetMidInit(char *nm, char *mi)
     *mi++ = *nm;
   *mi = '\0';
 }
+
+/*     Function Name: RemoveHyphens
+ *     Description: Removes all hyphens from the string passed to it.
+ *     Arguments: str - the string to remove the hyphens from
+ *     Returns: none
+ */
+
+void RemoveHyphens(char *str)
+{
+  char *hyphen;
+
+  while ((hyphen = strchr(str, '-')))
+    strcpy(hyphen, hyphen + 1);
+}
This page took 0.034161 seconds and 4 git commands to generate.