Code Duplication    Length = 44-45 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

@@ 6092-6136 (lines=45) @@
6089
   *
6090
   * @return string str with all alphabetic characters converted to lowercase.
6091
   */
6092
  public static function strtolower($str, $encoding = 'UTF-8', $cleanUtf8 = false, $lang = null)
6093
  {
6094
    // init
6095
    $str = (string)$str;
6096
6097
    if (!isset($str[0])) {
6098
      return '';
6099
    }
6100
6101
    if ($cleanUtf8 === true) {
6102
      // "\mb_strpos" and "\iconv_strpos" returns wrong position,
6103
      // if invalid characters are found in $haystack before $needle
6104
      $str = self::clean($str);
6105
    }
6106
6107
    if ($encoding !== 'UTF-8') {
6108
      $encoding = self::normalize_encoding($encoding, 'UTF-8');
6109
    }
6110
6111
    if ($lang !== null) {
6112
      if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) {
6113
        self::checkForSupport();
6114
      }
6115
6116
      if (
6117
          self::$SUPPORT['intl'] === true
6118
          &&
6119
          Bootup::is_php('5.4') === true
6120
      ) {
6121
6122
        $langCode = $lang . '-Lower';
6123
        if (!in_array($langCode, self::$SUPPORT['intl__transliterator_list_ids'], true)) {
6124
          trigger_error('UTF8::strtolower() without intl for special language: ' . $lang, E_USER_WARNING);
6125
6126
          $langCode = 'Any-Lower';
6127
        }
6128
6129
        return transliterator_transliterate($langCode, $str);
6130
      }
6131
6132
      trigger_error('UTF8::strtolower() without intl + PHP >= 5.4 cannot handle the "lang"-parameter: ' . $lang, E_USER_WARNING);
6133
    }
6134
6135
    return \mb_strtolower($str, $encoding);
6136
  }
6137
6138
  /**
6139
   * Generic case sensitive transformation for collation matching.
@@ 6163-6206 (lines=44) @@
6160
   *
6161
   * @return string str with all alphabetic characters converted to uppercase.
6162
   */
6163
  public static function strtoupper($str, $encoding = 'UTF-8', $cleanUtf8 = false, $lang = null)
6164
  {
6165
    $str = (string)$str;
6166
6167
    if (!isset($str[0])) {
6168
      return '';
6169
    }
6170
6171
    if ($cleanUtf8 === true) {
6172
      // "\mb_strpos" and "\iconv_strpos" returns wrong position,
6173
      // if invalid characters are found in $haystack before $needle
6174
      $str = self::clean($str);
6175
    }
6176
6177
    if ($encoding !== 'UTF-8') {
6178
      $encoding = self::normalize_encoding($encoding, 'UTF-8');
6179
    }
6180
6181
    if ($lang !== null) {
6182
      if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) {
6183
        self::checkForSupport();
6184
      }
6185
6186
      if (
6187
          self::$SUPPORT['intl'] === true
6188
          &&
6189
          Bootup::is_php('5.4') === true
6190
      ) {
6191
6192
        $langCode = $lang . '-Upper';
6193
        if (!in_array($langCode, self::$SUPPORT['intl__transliterator_list_ids'], true)) {
6194
          trigger_error('UTF8::strtoupper() without intl for special language: ' . $lang, E_USER_WARNING);
6195
6196
          $langCode = 'Any-Upper';
6197
        }
6198
6199
        return transliterator_transliterate($langCode, $str);
6200
      }
6201
6202
      trigger_error('UTF8::strtolower() without intl + PHP >= 5.4 cannot handle the "lang"-parameter: ' . $lang, E_USER_WARNING);
6203
    }
6204
6205
    return \mb_strtoupper($str, $encoding);
6206
  }
6207
6208
  /**
6209
   * Translate characters or replace sub-strings.