Code Duplication    Length = 44-45 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

@@ 5967-6011 (lines=45) @@
5964
   *
5965
   * @return string str with all alphabetic characters converted to lowercase.
5966
   */
5967
  public static function strtolower($str, $encoding = 'UTF-8', $cleanUtf8 = false, $lang = null)
5968
  {
5969
    // init
5970
    $str = (string)$str;
5971
5972
    if (!isset($str[0])) {
5973
      return '';
5974
    }
5975
5976
    if ($cleanUtf8 === true) {
5977
      // "\mb_strpos" and "\iconv_strpos" returns wrong position,
5978
      // if invalid characters are found in $haystack before $needle
5979
      $str = self::clean($str);
5980
    }
5981
5982
    if ($encoding !== 'UTF-8') {
5983
      $encoding = self::normalize_encoding($encoding, 'UTF-8');
5984
    }
5985
5986
    if ($lang !== null) {
5987
      if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) {
5988
        self::checkForSupport();
5989
      }
5990
5991
      if (
5992
          self::$SUPPORT['intl'] === true
5993
          &&
5994
          Bootup::is_php('5.4') === true
5995
      ) {
5996
5997
        $langCode = $lang . '-Lower';
5998
        if (!in_array($langCode, self::$SUPPORT['intl__transliterator_list_ids'], true)) {
5999
          trigger_error('UTF8::strtolower() without intl for special language: ' . $lang, E_USER_WARNING);
6000
6001
          $langCode = 'Any-Lower';
6002
        }
6003
6004
        return transliterator_transliterate($langCode, $str);
6005
      }
6006
6007
      trigger_error('UTF8::strtolower() without intl + PHP >= 5.4 cannot handle the "lang"-parameter: ' . $lang, E_USER_WARNING);
6008
    }
6009
6010
    return \mb_strtolower($str, $encoding);
6011
  }
6012
6013
  /**
6014
   * Generic case sensitive transformation for collation matching.
@@ 6038-6081 (lines=44) @@
6035
   *
6036
   * @return string str with all alphabetic characters converted to uppercase.
6037
   */
6038
  public static function strtoupper($str, $encoding = 'UTF-8', $cleanUtf8 = false, $lang = null)
6039
  {
6040
    $str = (string)$str;
6041
6042
    if (!isset($str[0])) {
6043
      return '';
6044
    }
6045
6046
    if ($cleanUtf8 === true) {
6047
      // "\mb_strpos" and "\iconv_strpos" returns wrong position,
6048
      // if invalid characters are found in $haystack before $needle
6049
      $str = self::clean($str);
6050
    }
6051
6052
    if ($encoding !== 'UTF-8') {
6053
      $encoding = self::normalize_encoding($encoding, 'UTF-8');
6054
    }
6055
6056
    if ($lang !== null) {
6057
      if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) {
6058
        self::checkForSupport();
6059
      }
6060
6061
      if (
6062
          self::$SUPPORT['intl'] === true
6063
          &&
6064
          Bootup::is_php('5.4') === true
6065
      ) {
6066
6067
        $langCode = $lang . '-Upper';
6068
        if (!in_array($langCode, self::$SUPPORT['intl__transliterator_list_ids'], true)) {
6069
          trigger_error('UTF8::strtoupper() without intl for special language: ' . $lang, E_USER_WARNING);
6070
6071
          $langCode = 'Any-Upper';
6072
        }
6073
6074
        return transliterator_transliterate($langCode, $str);
6075
      }
6076
6077
      trigger_error('UTF8::strtolower() without intl + PHP >= 5.4 cannot handle the "lang"-parameter: ' . $lang, E_USER_WARNING);
6078
    }
6079
6080
    return \mb_strtoupper($str, $encoding);
6081
  }
6082
6083
  /**
6084
   * Translate characters or replace sub-strings.