public static function titleToVar($title, $maxLength = 31) {
$variable = self::munge($title, '_', $maxLength);
+ // FIXME: nothing below this line makes sense. The above call to self::munge will always
+ // return a safe string of the correct length, so why are we now checking if it's a safe
+ // string of the correct length?
if (CRM_Utils_Rule::title($variable, $maxLength)) {
return $variable;
}
- // if longer than the maxLength lets just return a substr of the
- // md5 to prevent errors downstream
+ // FIXME: When would this ever be reachable?
return substr(md5($title), 0, $maxLength);
}
* @return bool
*/
public static function isUtf8($str) {
- if (!function_exists(mb_detect_encoding)) {
- // eliminate all white space from the string
- $str = preg_replace('/\s+/', '', $str);
-
- // pattern stolen from the php.net function documentation for
- // utf8decode();
- // comment by JF Sebastian, 30-Mar-2005
- return preg_match('/^([\x00-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xec][\x80-\xbf]{2}|\xed[\x80-\x9f][\x80-\xbf]|[\xee-\xef][\x80-\xbf]{2}|f0[\x90-\xbf][\x80-\xbf]{2}|[\xf1-\xf3][\x80-\xbf]{3}|\xf4[\x80-\x8f][\x80-\xbf]{2})*$/', $str);
- // ||
- // iconv('ISO-8859-1', 'UTF-8', $str);
- }
- else {
- $enc = mb_detect_encoding($str, ['UTF-8'], TRUE);
- return ($enc !== FALSE);
- }
+ $enc = mb_detect_encoding($str, ['UTF-8'], TRUE);
+ return ($enc !== FALSE);
}
/**
* @param string $str
* The string to be translated.
*
- * @return bool
+ * @return string|false
*/
public static function strtoboolstr($str) {
if (!is_scalar($str)) {