Code Duplication    Length = 44-45 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

@@ 6177-6221 (lines=45) @@
6174
   *
6175
   * @return string str with all alphabetic characters converted to lowercase.
6176
   */
6177
  public static function strtolower($str, $encoding = 'UTF-8', $cleanUtf8 = false, $lang = null)
6178
  {
6179
    // init
6180
    $str = (string)$str;
6181
6182
    if (!isset($str[0])) {
6183
      return '';
6184
    }
6185
6186
    if ($cleanUtf8 === true) {
6187
      // "\mb_strpos" and "\iconv_strpos" returns wrong position,
6188
      // if invalid characters are found in $haystack before $needle
6189
      $str = self::clean($str);
6190
    }
6191
6192
    if ($encoding !== 'UTF-8') {
6193
      $encoding = self::normalize_encoding($encoding, 'UTF-8');
6194
    }
6195
6196
    if ($lang !== null) {
6197
      if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) {
6198
        self::checkForSupport();
6199
      }
6200
6201
      if (
6202
          self::$SUPPORT['intl'] === true
6203
          &&
6204
          Bootup::is_php('5.4') === true
6205
      ) {
6206
6207
        $langCode = $lang . '-Lower';
6208
        if (!in_array($langCode, self::$SUPPORT['intl__transliterator_list_ids'], true)) {
6209
          trigger_error('UTF8::strtolower() without intl for special language: ' . $lang, E_USER_WARNING);
6210
6211
          $langCode = 'Any-Lower';
6212
        }
6213
6214
        return transliterator_transliterate($langCode, $str);
6215
      }
6216
6217
      trigger_error('UTF8::strtolower() without intl + PHP >= 5.4 cannot handle the "lang"-parameter: ' . $lang, E_USER_WARNING);
6218
    }
6219
6220
    return \mb_strtolower($str, $encoding);
6221
  }
6222
6223
  /**
6224
   * Generic case sensitive transformation for collation matching.
@@ 6248-6291 (lines=44) @@
6245
   *
6246
   * @return string str with all alphabetic characters converted to uppercase.
6247
   */
6248
  public static function strtoupper($str, $encoding = 'UTF-8', $cleanUtf8 = false, $lang = null)
6249
  {
6250
    $str = (string)$str;
6251
6252
    if (!isset($str[0])) {
6253
      return '';
6254
    }
6255
6256
    if ($cleanUtf8 === true) {
6257
      // "\mb_strpos" and "\iconv_strpos" returns wrong position,
6258
      // if invalid characters are found in $haystack before $needle
6259
      $str = self::clean($str);
6260
    }
6261
6262
    if ($encoding !== 'UTF-8') {
6263
      $encoding = self::normalize_encoding($encoding, 'UTF-8');
6264
    }
6265
6266
    if ($lang !== null) {
6267
      if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) {
6268
        self::checkForSupport();
6269
      }
6270
6271
      if (
6272
          self::$SUPPORT['intl'] === true
6273
          &&
6274
          Bootup::is_php('5.4') === true
6275
      ) {
6276
6277
        $langCode = $lang . '-Upper';
6278
        if (!in_array($langCode, self::$SUPPORT['intl__transliterator_list_ids'], true)) {
6279
          trigger_error('UTF8::strtoupper() without intl for special language: ' . $lang, E_USER_WARNING);
6280
6281
          $langCode = 'Any-Upper';
6282
        }
6283
6284
        return transliterator_transliterate($langCode, $str);
6285
      }
6286
6287
      trigger_error('UTF8::strtolower() without intl + PHP >= 5.4 cannot handle the "lang"-parameter: ' . $lang, E_USER_WARNING);
6288
    }
6289
6290
    return \mb_strtoupper($str, $encoding);
6291
  }
6292
6293
  /**
6294
   * Translate characters or replace sub-strings.