Code Duplication    Length = 44-45 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

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