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

Double Barrel Name conversion #620

Closed
archergod opened this issue Mar 9, 2017 · 11 comments
Closed

Double Barrel Name conversion #620

archergod opened this issue Mar 9, 2017 · 11 comments

Comments

@archergod
Copy link

I like the library but it add a value if you can include Name Casing (I call it like that), along with TitleCase. The idea is to change Double Barrel name and name like O'Neil to be properly cased. I wrote a novice function for it using Humanizer itself

   public static string ToNameCase(string name)
    {
        string x = name.Replace("-", " #7# " ).Replace("'", " $7$ ");
        x = x.ToLower().Transform(To.TitleCase);
        return x.Replace(" #7# ", "-").Replace(" $7$ ", "'");
    }

It does both, but I am not sure how to improve it further, my idea is to write it in Regular expression for better results, but for now it works.

@aloisdg
Copy link
Contributor

aloisdg commented Mar 9, 2017

So in TitleCase mode, you expect:

O'Neil

and we get

O'neil

right?

but what should we do for:

It's my life. O'Neill, O'Donnell and O'Doherty are irish.

We have to define what is a word. TitleCase.com seems to agree with the current implementation.

And what if you send "O'Nei" #7# "l" to ToNameCase? The TitleCase logic is:

class ToTitleCase : IStringTransformer
{
    public string Transform(string input)
    {
        var words = input.Split(' ');
        var result = new List<string>();
        foreach (var word in words)
        {
            if (word.Length == 0 || AllCapitals(word))
                result.Add(word);
            else if(word.Length == 1)
                result.Add(word.ToUpper());
            else 
                result.Add(char.ToUpper(word[0]) + word.Remove(0, 1).ToLower());
        }

        return string.Join(" ", result);
    }

    static bool AllCapitals(string input)
    {
        return input.ToCharArray().All(char.IsUpper);
    }
}

source

Also, you dont need to do ToLower() before a Transform(To.TitleCase).

@archergod
Copy link
Author

archergod commented Mar 9, 2017

Hey, no I want
O'neil to become O'Neil

And yes, if we pass that string it will mess, and hence I am not sure how to implement it better. I just know that my source do not have such random string, but not reliable enough, hence I need someone good to improve it and make it part of this library which is already good.

@aloisdg
Copy link
Contributor

aloisdg commented Mar 9, 2017

ok. You can trust your source but a public library cant. How a string like It's my life. O'Neill, O'Donnell and O'Doherty are irish. or L'éléphant est rose. would be handle?

@archergod
Copy link
Author

archergod commented Mar 9, 2017

That is why I name it as NameCase, I believe it is up to user to use properly. This Transformation is not for String but for Name. Having said It is not intended for sentences but for Fixing Name display on your project. If we go for sentence it will become a natural language parser and that is, for me is beyond the scope of this.

All purpose of Humanizer is that it make small things easy, it is one of most common and missing thing I found. Maybe you can improve it with regular expression to make transformation of name. Or in your example split it with ' or - and improve that function specific for Naming Case and not sentences.

@hazzik
Copy link
Member

hazzik commented Mar 9, 2017 via email

@archergod
Copy link
Author

@hazzik not sure what you mean by putting name as exception. We are taking about a method to transform a name string in proper case for display. Putting data as exception totally destroy the concept of humanizer itself. Idea of this thread request is to make it easier for other developer to format names properly. which ToTitleCase won't do for those two types.

@hazzik
Copy link
Member

hazzik commented May 2, 2017

not sure what you mean by putting name as exception

I mean that you have to have a dictionary with the exception cases (like O'Neil, McDonald, DiCaprio, d'Estaing, etc)

First of all, trying to do anything with names is a very bad idea. It shall be displayed as user have entered the name.
Second, the rules to transform these names are really complicated.

@archergod
Copy link
Author

First of all, trying to do anything with names is a very bad idea. It shall be displayed as user have entered the name.

I am sure not many agree with you, Some site allow user to enter name and for design sack and consistency they display them Upper case or lower case or Name Case.

And for name like McDonald, well there is no rule about it, some write it as Mcdonald and some as McDonald, but for name like O'Neil or Double Barrel name it is the way of writing. I know it because my client don't like it when I write O'neil in their name or Stuart-smith, and the logic as simple as Camel casing after any special character. My logic works for my use. Just if author of Humanizer find it interesting to improve and add will be good as I am sure there are few project who can use it.

@hazzik
Copy link
Member

hazzik commented May 2, 2017

I know it because my client don't like it when I write O'neil in their name or Stuart-smith

Because you should stop trying to mess with customers' surnames and let them enter it and display it as is.

@hazzik
Copy link
Member

hazzik commented May 2, 2017

I would say that the only "allowed" (to some degree at least) transformation of customer names is to transform it to all upper case. But even with this "safe" transformation some would not agree that even this is acceptable.

@hazzik hazzik closed this as completed May 2, 2017
@aloisdg
Copy link
Contributor

aloisdg commented May 11, 2017

@hazzik indeed. For example, my last name is de Gouvello and de GOUVELLO would be the uppercase. A nobiliary particle must be written in lowercase. If my last name is used as a name (for example if you want to call me by my last name only), you can drop the particle.

Bonus: Falsehoods Programmers Believe About Names

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants