Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have to Humanize a string twice #318

Closed
carlowahlstedt opened this issue Jul 29, 2014 · 7 comments
Closed

Have to Humanize a string twice #318

carlowahlstedt opened this issue Jul 29, 2014 · 7 comments
Labels

Comments

@carlowahlstedt
Copy link

Start with string: "TEST 1 - THIS IS A TEST"
Humanize it once you get: "TEST 1 THIS IS A TEST"
Humanize it a second time and you get: "Test 1 This is a test"
The code would look something like:

var text = "TEST 1 - THIS IS THE TEST";
text = text.Humanize (); // TEST 1  THIS IS A TEST
text = text.Humanize (); // Test 1  This is a test

I would expect the second result after the first humanize call.

@MehdiK
Copy link
Member

MehdiK commented Jul 30, 2014

Calling Humanize on all caps shouldn't do anything. You're sure the second run returns what you've reported?!

From the documentation if you want Humanizer to change the casing of upper case input you will have to explicitly tell it; e.g.

// any unbroken upper case string is treated as an acronym
"HUMANIZER".Humanize() => "HUMANIZER"
"HUMANIZER".Transform(To.LowerCase | To.TitleCase) => "Humanizer"

This is the expected behavior. Please see this for more info.

@MehdiK MehdiK closed this as completed Jul 30, 2014
@carlowahlstedt
Copy link
Author

Yes, that is how it behaves.

screen shot 2014-07-30 at 10 26 07 am
screen shot 2014-07-30 at 10 26 15 am

@MehdiK MehdiK reopened this Jul 30, 2014
@MehdiK
Copy link
Member

MehdiK commented Jul 30, 2014

Hmmm, that looks like a bug. It shouldn't really change the casing of all caps!! Thanks. Will check it out.

As mentioned you can enforce the whole transformation in one hit by passing Transformers in Humanize.

@MehdiK MehdiK added bug and removed jump in labels Jul 30, 2014
@Borzoo
Copy link
Contributor

Borzoo commented Aug 1, 2014

It changes the caps because of the hyphen and the spaces. I'm not sure how Humanize should behave in this case.

@MehdiK
Copy link
Member

MehdiK commented Aug 10, 2014

The reason Humanize ignores upper case words is that they're considered acronyms and Humanizer doesn't want to mess with acronyms. So in this case Humanize should leave the text alone (because as far as it can see it's already human-readable). If you want the upper case string/word to be humanized regardless of the case you can turn it to lowercase and humanize it then.

@nzubair
Copy link
Contributor

nzubair commented Oct 22, 2014

First of all, based on earlier comments, the expected output should be TEST 1 THIS IS THE TEST instead of the lower/title cased version.

After my first failed attempt, I've spent some time familiarizing myself with the code and test suite. Durin my testing, I have observed the following behavior:

  1. None of the test cases address a string which contain a free-standing dash or underscore. The Humanize function detects the dash and replaces it with a space, without any further processing. This results in (three spaces), for-(space dash space) substring.
  2. The regular express used in FromPascalCase does not take into account a string with spaces. The test string is not split by the regex, resulting in a single word (containing the entire string), which is lower cased and then title cased before being returned.

I'm wrapping up my changes and will commit them shortly with workarounds for both behaviors.

@MehdiK
Copy link
Member

MehdiK commented Oct 29, 2014

Fixed in #341

@MehdiK MehdiK closed this as completed Oct 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants