Code Duplication    Length = 44-45 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

@@ 6072-6116 (lines=45) @@
6069
   *
6070
   * @return string str with all alphabetic characters converted to lowercase.
6071
   */
6072
  public static function strtolower($str, $encoding = 'UTF-8', $cleanUtf8 = false, $lang = null)
6073
  {
6074
    // init
6075
    $str = (string)$str;
6076
6077
    if (!isset($str[0])) {
6078
      return '';
6079
    }
6080
6081
    if ($cleanUtf8 === true) {
6082
      // "\mb_strpos" and "\iconv_strpos" returns wrong position,
6083
      // if invalid characters are found in $haystack before $needle
6084
      $str = self::clean($str);
6085
    }
6086
6087
    if ($encoding !== 'UTF-8') {
6088
      $encoding = self::normalize_encoding($encoding, 'UTF-8');
6089
    }
6090
6091
    if ($lang !== null) {
6092
      if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) {
6093
        self::checkForSupport();
6094
      }
6095
6096
      if (
6097
          self::$SUPPORT['intl'] === true
6098
          &&
6099
          Bootup::is_php('5.4') === true
6100
      ) {
6101
6102
        $langCode = $lang . '-Lower';
6103
        if (!in_array($langCode, self::$SUPPORT['intl__transliterator_list_ids'], true)) {
6104
          trigger_error('UTF8::strtolower() without intl for special language: ' . $lang, E_USER_WARNING);
6105
6106
          $langCode = 'Any-Lower';
6107
        }
6108
6109
        return transliterator_transliterate($langCode, $str);
6110
      }
6111
6112
      trigger_error('UTF8::strtolower() without intl + PHP >= 5.4 cannot handle the "lang"-parameter: ' . $lang, E_USER_WARNING);
6113
    }
6114
6115
    return \mb_strtolower($str, $encoding);
6116
  }
6117
6118
  /**
6119
   * Generic case sensitive transformation for collation matching.
@@ 6143-6186 (lines=44) @@
6140
   *
6141
   * @return string str with all alphabetic characters converted to uppercase.
6142
   */
6143
  public static function strtoupper($str, $encoding = 'UTF-8', $cleanUtf8 = false, $lang = null)
6144
  {
6145
    $str = (string)$str;
6146
6147
    if (!isset($str[0])) {
6148
      return '';
6149
    }
6150
6151
    if ($cleanUtf8 === true) {
6152
      // "\mb_strpos" and "\iconv_strpos" returns wrong position,
6153
      // if invalid characters are found in $haystack before $needle
6154
      $str = self::clean($str);
6155
    }
6156
6157
    if ($encoding !== 'UTF-8') {
6158
      $encoding = self::normalize_encoding($encoding, 'UTF-8');
6159
    }
6160
6161
    if ($lang !== null) {
6162
      if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) {
6163
        self::checkForSupport();
6164
      }
6165
6166
      if (
6167
          self::$SUPPORT['intl'] === true
6168
          &&
6169
          Bootup::is_php('5.4') === true
6170
      ) {
6171
6172
        $langCode = $lang . '-Upper';
6173
        if (!in_array($langCode, self::$SUPPORT['intl__transliterator_list_ids'], true)) {
6174
          trigger_error('UTF8::strtoupper() without intl for special language: ' . $lang, E_USER_WARNING);
6175
6176
          $langCode = 'Any-Upper';
6177
        }
6178
6179
        return transliterator_transliterate($langCode, $str);
6180
      }
6181
6182
      trigger_error('UTF8::strtolower() without intl + PHP >= 5.4 cannot handle the "lang"-parameter: ' . $lang, E_USER_WARNING);
6183
    }
6184
6185
    return \mb_strtoupper($str, $encoding);
6186
  }
6187
6188
  /**
6189
   * Translate characters or replace sub-strings.