This commit is contained in:
Nathan Coad
2018-01-18 17:48:05 +11:00
parent 0e427a8416
commit c45dfa21b9

View File

@@ -37,35 +37,27 @@ function _booking_ucname($string) {
$suffixes = "'S"; $suffixes = "'S";
// captialize all first letters // captialize all first letters
//$string = preg_replace('/\\b(\\w)/e', 'strtoupper("$1")', strtolower(trim($string)));
$string = preg_replace_callback("/\b(\w)/", function ($m) { return strtoupper($m[1]); }, strtolower(trim($string))); $string = preg_replace_callback("/\b(\w)/", function ($m) { return strtoupper($m[1]); }, strtolower(trim($string)));
if ($all_uppercase) { if ($all_uppercase) {
// capitalize acronymns and initialisms e.g. PHP // capitalize acronymns and initialisms e.g. PHP
//$string = preg_replace("/\\b($all_uppercase)\\b/e", 'strtoupper("$1")', $string);
$string = preg_replace_callback("/\b($all_uppercase)\b/", function ($m) { return strtoupper($m[1]); }, $string); $string = preg_replace_callback("/\b($all_uppercase)\b/", function ($m) { return strtoupper($m[1]); }, $string);
} }
if ($all_lowercase) { if ($all_lowercase) {
// decapitalize short words e.g. and // decapitalize short words e.g. and
// all occurences will be changed to lowercase // all occurences will be changed to lowercase
//$string = preg_replace("/\\b($all_lowercase)\\b/e", 'strtolower("$1")', $string);
$string = preg_replace_callback("/\b($all_lowercase)\b/", function ($m) { return strtolower($m[1]); }, $string); $string = preg_replace_callback("/\b($all_lowercase)\b/", function ($m) { return strtolower($m[1]); }, $string);
} }
if ($prefixes) { if ($prefixes) {
//watchdog('booking_debug', "Checking prefixes");
//preg_match("/\b($prefixes)(\w)/", $string, $matches);
//watchdog('booking_debug', "<pre>Prefixes match test: \n@info</pre>", array('@info' => print_r( $matches, true)));
// capitalize letter after certain name prefixes e.g 'Mc' // capitalize letter after certain name prefixes e.g 'Mc'
//$string = preg_replace("/\\b($prefixes)(\\w)/e", '"$1".strtoupper("$2")', $string);
$string = preg_replace_callback("/\b($prefixes)(\w)/", function ($m) { $string = preg_replace_callback("/\b($prefixes)(\w)/", function ($m) {
watchdog('booking_debug', "<pre>Prefixes match: \n@info</pre>", array('@info' => print_r( $m, true))); //watchdog('booking_debug', "<pre>Prefixes match: \n@info</pre>", array('@info' => print_r( $m, true)));
return $m[1] . strtoupper($m[2]); return $m[1] . strtoupper($m[2]);
}, $string); }, $string);
} }
if ($suffixes) { if ($suffixes) {
// decapitalize certain word suffixes e.g. 's // decapitalize certain word suffixes e.g. 's
//$string = preg_replace("/(\\w)($suffixes)\\b/e", '"$1".strtolower("$2")', $string);
$string = preg_replace_callback("/(\w)($suffixes)\b/", function ($m) { return $m[1] . strtolower($m[2]); }, $string); $string = preg_replace_callback("/(\w)($suffixes)\b/", function ($m) { return $m[1] . strtolower($m[2]); }, $string);
} }