Code Duplication    Length = 44-45 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

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