Code Duplication    Length = 44-45 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

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