Open knusperpixel opened 8 years ago
you don't understand it right. Lowercasing the string is the last thing it does. The other thing it does is converting camelCase to underscore-separated words
@stof Sorry, but the first thing the code does is lowercasing it. So this whole camelCase to underscore_seperated words thing can't happen, I think.
/**
* Cleans up the text and adds separator.
*
* @param string $text
* @param string $separator
*
* @return string
*/
private static function postProcessText($text, $separator)
{
if (function_exists('mb_strtolower')) {
$text = mb_strtolower($text);
} else {
$text = strtolower($text);
}
// Remove all none word characters
$text = preg_replace('/\W/', ' ', $text);
// More stripping. Replace spaces with dashes
$text = strtolower(preg_replace('/[^A-Za-z0-9\/]+/', $separator,
preg_replace('/([a-z\d])([A-Z])/', '\1_\2',
preg_replace('/([A-Z]+)([A-Z][a-z])/', '\1_\2',
preg_replace('/::/', '/', $text)))));
return trim($text, $separator);
}
If I understand the code correctly, there is unneccessary code in
Transliterator::postProcessText
(https://github.com/Behat/Transliterator/blob/master/src/Behat/Transliterator/Transliterator.php#L568)The first thing the function does is lowercase the input. After that, in line 580 there is a lot of
preg_replace
going on, checking uppercase chars and finally lowercasing the whole string again.I was wondering why that is there. I think, the code could be simplified
before
after