X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-core%2Finclude%2Fsmarty%2Fplugins%2Fmodifier.capitalize.php;h=cd24589d8df3bbc70f9415077a60983fc21d8d8c;hb=6cf1d45205641e6641780b1488d2f20c0ac00ebe;hp=acff0bc9dce538003c8fb56c69c9eb2a34df82dc;hpb=d6336a0c6f44b2bbf61ac56bad2beb3d570a1e23;p=gosa.git diff --git a/gosa-core/include/smarty/plugins/modifier.capitalize.php b/gosa-core/include/smarty/plugins/modifier.capitalize.php index acff0bc9d..cd24589d8 100644 --- a/gosa-core/include/smarty/plugins/modifier.capitalize.php +++ b/gosa-core/include/smarty/plugins/modifier.capitalize.php @@ -1,41 +1,37 @@ * Name: capitalize
* Purpose: capitalize words in the string - * @link http://smarty.php.net/manual/en/language.modifiers.php#LANGUAGE.MODIFIER.CAPITALIZE - * capitalize (Smarty online manual) - * @author Monte Ohrt - * @param string - * @return string + * + * @link + * @author Monte Ohrt + * @param string $ + * @return string */ function smarty_modifier_capitalize($string, $uc_digits = false) -{ - smarty_modifier_capitalize_ucfirst(null, $uc_digits); - return preg_replace_callback('!\'?\b\w(\w|\')*\b!', 'smarty_modifier_capitalize_ucfirst', $string); -} +{ + // uppercase with php function ucwords + $upper_string = ucwords($string); + // check for any missed hyphenated words + $upper_string = preg_replace("!(^|[^\p{L}'])([\p{Ll}])!ue", "'\\1'.ucfirst('\\2')", $upper_string); + // check uc_digits case + if (!$uc_digits) { + if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!u", $string, $matches, PREG_OFFSET_CAPTURE)) { + foreach($matches[1] as $match) + $upper_string = substr_replace($upper_string, $match[0], $match[1], strlen($match[0])); + } + } + return $upper_string; +} -function smarty_modifier_capitalize_ucfirst($string, $uc_digits = null) -{ - static $_uc_digits = false; - - if(isset($uc_digits)) { - $_uc_digits = $uc_digits; - return; - } - - if(substr($string[0],0,1) != "'" && !preg_match("!\d!",$string[0]) || $_uc_digits) - return ucfirst($string[0]); - else - return $string[0]; -} -?> +?> \ No newline at end of file