In creating an AutoLisp string function to format proper names, I haven't found a definitive source for the format for proper names. ( Queen's English I think ) Most spreadsheets (etc) can only handle the first letter of each word. I want something a bit more robust.
I think the comma should always be the indicator for a suffix. I also think Jr. & PhD are proper. Are professional suffixes ( or whatever they are called ) always CAPS?
Anyone care to enlighten me? Or add to the list of special conditions?
(defun proper (s / tmp pv sx rl i cl)
(while (= " " (substr s (strlen s)))
(setq s (substr s 1 (1- (strlen s)))))
(setq tmp (strcase (substr s 1 1));1st letter always CAP
pv tmp ;previous letter
i 2)
(while (<= i (strlen s))
(setq cl (substr s i 1) ;current letter
rl (substr s i)) ;remaining letters
(cond (sx
(cond ((= " JR." (strcase rl))
(setq tmp (strcat tmp " Jr.")))
((= " PHD" (strcase rl))
(setq tmp (strcat tmp " PhD")))
(T
(setq tmp (strcat tmp (strcase rl)))))
(setq i (1+ (strlen s))))
((= cl " ")
(setq tmp (strcat tmp cl)
pv cl
i (1+ i)))
((and (/= cl " ")
(or (= pv " ")
(= pv ".")))
(setq tmp (strcat tmp (strcase cl))
pv cl
i (1+ i)))
((= cl ",")
(setq tmp (strcat tmp cl)
pv cl
sx T
i (1+ i)))
((and (/= cl " ")
(/= pv " "))
(setq tmp (strcat tmp (strcase cl t))
pv cl
i (1+ i)))
(T
(setq tmp (strcat tmp (strcase cl))
pv cl
i (1+ i)))))
tmp)
The test bed:
(textpage)
(foreach n '("john doe"
"mr.john doe"
"mr. JOHN q. doe"
"mr. & mrs. John Q. doe"
"mr. & mrs. John Q. doe, esq"
"john doe, jr."
"dr. j.q. Doe"
"JOHN DOE, III"
"john doe, aia"
)
(princ "\n")
(princ (proper n)))
I stripped all spaces off of the end of the orginal string just to make things a little easier. -David