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

Support for different character separators #45

Closed
drgomesp opened this issue Oct 30, 2015 · 4 comments
Closed

Support for different character separators #45

drgomesp opened this issue Oct 30, 2015 · 4 comments

Comments

@drgomesp
Copy link
Contributor

Currently if I do this:

String::humanize('land-rover');

I get Land-Rover.

Is there any way to support setting a special character modified so that it doesn't always couple to the underscore character?

@norberttech
Copy link
Member

@drgomesp at the moment we have this feature, but I guess we can easly improve Humanize class to support mulitiple separators and also forbiden words. Now there is only one forbidden word, id but we should allow to remove it cuz there are some cases where id is valid part of name.

@drgomesp
Copy link
Contributor Author

@norzechowicz I made a small proof of concept of what it would look like to support multiple character separators.

Humanize.php

    public function __toString()
    {
        $humanized = trim(strtolower(preg_replace(array('/([A-Z])/', "/[{$this->separator}\\s]+/"), array('_$1', ' '), $this->text)));
        $humanized = trim(str_replace($this->forbiddenWords, "", $humanized));
        return $this->capitalize ?  ucfirst($humanized) : $humanized;
    }

And the String.php

 public static function humanize($text, $capitalize = true, $separator = Humanize::SEPARATOR_UNDERSCORE)
    {
        return (string) new Humanize($text, $capitalize, $separator);
    }

What do you think? Shall I open a PR?

@norberttech
Copy link
Member

@drgomesp yes, PR are more than welcome :P

@drgomesp
Copy link
Contributor Author

@norzechowicz done. Closing this one :)

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

2 participants