From 3f9c37b072e64c8a7ca4fdb8d3521ccf347806af Mon Sep 17 00:00:00 2001 From: danw Date: Sun, 20 Dec 1998 21:23:18 +0000 Subject: [PATCH] fix FixCase() to only capitalize the letter after an apostrophe if the 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 | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/fixname.c b/lib/fixname.c index 26e880e2..dc37c0e5 100644 --- a/lib/fixname.c +++ b/lib/fixname.c @@ -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 */ } } -- 2.45.2