Skip to content

Case a single word

Applies a first-match-wins sequence of casing rules (preformatted mixed-case, acronym list, minor-word list, irregular spelling, ordinal suffix, default proper-case) to a single word token.

Field Value
Operation ID op-02-case-single-word
Trigger Called once per token from Convert text to title case, step 4
Inputs Word token (String)
Outputs Cased word
Primary components TitleCaseSingleWord (private), HasNumberSuffix, ToProperCase
Entry point SAIF.Business.Utilities/TitleCase.vb

Steps

First matching branch wins:

  1. If the word already contains both an upper-case and a lower-case character, return it untouched — pre-formatted mixed-case input is respected (BR-004).
  2. Else if word.ToUpper is in UpperCaseWordList, upper-case the word (BR-005).
  3. Else if word.ToLower is in LowerCaseWordList, lower-case the word (BR-006).
  4. Else if word.ToLower matches an entry of MixedCaseWordList case-insensitively, replace with that list's canonical spelling (e.g. PhD, LaCombe) (BR-007).
  5. Else if HasNumberSuffix(word) — the token splits into a purely numeric part plus one of st/nd/rd/th — rejoin the number with the lower-cased suffix (BR-008).
  6. Else apply ToProperCase (StrConv ... VbStrConv.ProperCase) (BR-009).
  7. Post-step: if the resulting word starts with a MixedCasePrefixList entry (Mc, O'), keep the prefix as-is and proper-case the remainder (BR-012).

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start(["Caller invokes<br>TitleCaseSingleWord"]) --> MixedCheck{Contains both upper-<br>and lower-case chars?}
    MixedCheck -->|Yes| ReturnAsIs(["Return word untouched"])
    MixedCheck -->|No| UpperCheck{word.ToUpper in<br>UpperCaseWordList?}
    UpperCheck -->|Yes| UpperCase["Upper-case the word"]
    UpperCheck -->|No| LowerCheck{word.ToLower in<br>LowerCaseWordList?}
    LowerCheck -->|Yes| LowerCase["Lower-case the word"]
    LowerCheck -->|No| MixedListCheck{Matches MixedCaseWordList<br>case-insensitively?}
    MixedListCheck -->|Yes| Canonical["Replace with canonical<br>spelling"]
    MixedListCheck -->|No| SuffixCheck{HasNumberSuffix?}
    SuffixCheck -->|Yes| Rejoin["Rejoin number with<br>lower-cased suffix"]
    SuffixCheck -->|No| ProperCase["Apply ToProperCase"]
    UpperCase --> PrefixCheck{Starts with<br>MixedCasePrefixList entry?}
    LowerCase --> PrefixCheck
    Canonical --> PrefixCheck
    Rejoin --> PrefixCheck
    ProperCase --> PrefixCheck
    PrefixCheck -->|Yes| KeepPrefix["Keep prefix as-is,<br>proper-case remainder"]
    PrefixCheck -->|No| Done(["Return cased word"])
    KeepPrefix --> Done

Sources

  • SAIF.Business.Utilities/TitleCase.vb