Merge pull request #23290 from eileenmcnaughton/import_cont
[civicrm-core.git] / CRM / Utils / String.php
index 991a3761425522c95ec6b3cea1808e5c67d9143c..82d36093ad77683e2b27848e6987e0789ed30dc8 100644 (file)
@@ -43,12 +43,14 @@ class CRM_Utils_String {
   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);
   }
 
@@ -327,21 +329,8 @@ class CRM_Utils_String {
    * @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);
   }
 
   /**