nbubna / Case

String case utitility: convert, identify, flip, extend
http://nbubna.github.io/Case/
MIT License
282 stars 23 forks source link

Title bugs #15

Closed zanemcca closed 8 years ago

zanemcca commented 8 years ago

Title turns I'm into I'M.

Also it will turn -30 into 30. Oddly enough it works fine if there is another word such as -30 degrees

zanemcca commented 8 years ago

It seems as though if there is only one word it will strip it of special characters. I just tried can't which turns into Can T and something like can't stop won't stop would be Can'T Stop Won'T Stop. So in the I'm case it will be I M if it is alone and I'M if it is with other words.

nbubna commented 8 years ago

Lone words are the worst. It ain't easy to tell if "word-wrap" is some custom case or a hyphenated word.

The "magic" idea in this library was that you could get to any case without knowing what case you came from. Since a lot of cases involve concatenating words with special chars in between, and i wanted this to be flexible and easily extensible, the code basically looks for markers between words (space first, then special_chars or caseChangesLikeThis). You see how this necessarily fails for a single word with special chars involved, right? :) Still, i think this is much more convenient and powerful than having to specify the case you are coming from each time.

If it were just the "I'm" to "I'M" issue, then i might say the gain is worth the trouble and not worth special casing apostrophes, but the "can't stop won't stop" example is quite galling. I'll have to come up with some for this, methinks. But not tonight...

zanemcca commented 8 years ago

Yeah the single word issue is not as important as the contractions. Where the single word case starts to become important is when you are live updating an input value as a user types.

Do you know of a case where there should ever be a capital letter directly after an apostrophe?

nbubna commented 8 years ago

Sure, when run thru Case.upper(s)! ;) But that's not the real question. The real question is whether ' should be treated as a special character (current option), generally ignored, or is worth handling as a special case.

Ignoring ' is the easy fix for title case, but would make Case.constant("can't stop") return CAN'T_STOP, which is definitely not right.

Handling ' as a special case could get ugly, requiring decisions about it to be made on a case by case basis (pun unavoidable).

And ' is not just used as an apostrophe. It serves as single quote too. I haven't thought about this enough yet to decide whether that complicates things or not.

nbubna commented 8 years ago

Ok, i went with the case-by-case approach. 'Twas best i could think of for now. Default for cases is to ignore '. So it now explicitly strips it from cases where it is not appropriate.

As for that Case.title('-30') business... that's actually a totally unrelated issue. Would you mind opening a separate issue? :)

zanemcca commented 8 years ago

It works wonderfully. Thanks for your help. I opened #16 for the -30 issue