Code Duplication    Length = 44-45 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

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