Code Duplication    Length = 44-45 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

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