Code Duplication    Length = 44-45 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

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