danielstjules / Stringy

A PHP string manipulation library with multibyte support
MIT License
2.46k stars 216 forks source link

Changed titleize and toTitleCase methods to be much more accurate. #171

Open hipsterjazzbo opened 7 years ago

hipsterjazzbo commented 7 years ago

Currently, title casing is very naive, in that it simply capitalises each word.

This changes titleize() and toTitleCase() do a much better job at doing proper title casing, including lower casing words that should be lower cased, and hyphenates like "Stand-In" (but not man-in-the-middle).

I have made sure that the method signature has not changed, although the output will change in a lot of cases so I'm not toll sure if this counts as breaking.

If the behaviour of upper casing every word in a string is still desired, I suggest adding a upperCaseEach() method or similar.

(Adapted from John Gruber’s script)

PS: If there is a concern about the $smallWords list being mono-lingual, I believe the Inflectors from #170 could be used here as well.