Code Duplication    Length = 44-45 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

@@ 6124-6168 (lines=45) @@
6121
   *
6122
   * @return string str with all alphabetic characters converted to lowercase.
6123
   */
6124
  public static function strtolower($str, $encoding = 'UTF-8', $cleanUtf8 = false, $lang = null)
6125
  {
6126
    // init
6127
    $str = (string)$str;
6128
6129
    if (!isset($str[0])) {
6130
      return '';
6131
    }
6132
6133
    if ($cleanUtf8 === true) {
6134
      // "\mb_strpos" and "\iconv_strpos" returns wrong position,
6135
      // if invalid characters are found in $haystack before $needle
6136
      $str = self::clean($str);
6137
    }
6138
6139
    if ($encoding !== 'UTF-8') {
6140
      $encoding = self::normalize_encoding($encoding, 'UTF-8');
6141
    }
6142
6143
    if ($lang !== null) {
6144
      if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) {
6145
        self::checkForSupport();
6146
      }
6147
6148
      if (
6149
          self::$SUPPORT['intl'] === true
6150
          &&
6151
          Bootup::is_php('5.4') === true
6152
      ) {
6153
6154
        $langCode = $lang . '-Lower';
6155
        if (!in_array($langCode, self::$SUPPORT['intl__transliterator_list_ids'], true)) {
6156
          trigger_error('UTF8::strtolower() without intl for special language: ' . $lang, E_USER_WARNING);
6157
6158
          $langCode = 'Any-Lower';
6159
        }
6160
6161
        return transliterator_transliterate($langCode, $str);
6162
      }
6163
6164
      trigger_error('UTF8::strtolower() without intl + PHP >= 5.4 cannot handle the "lang"-parameter: ' . $lang, E_USER_WARNING);
6165
    }
6166
6167
    return \mb_strtolower($str, $encoding);
6168
  }
6169
6170
  /**
6171
   * Generic case sensitive transformation for collation matching.
@@ 6195-6238 (lines=44) @@
6192
   *
6193
   * @return string str with all alphabetic characters converted to uppercase.
6194
   */
6195
  public static function strtoupper($str, $encoding = 'UTF-8', $cleanUtf8 = false, $lang = null)
6196
  {
6197
    $str = (string)$str;
6198
6199
    if (!isset($str[0])) {
6200
      return '';
6201
    }
6202
6203
    if ($cleanUtf8 === true) {
6204
      // "\mb_strpos" and "\iconv_strpos" returns wrong position,
6205
      // if invalid characters are found in $haystack before $needle
6206
      $str = self::clean($str);
6207
    }
6208
6209
    if ($encoding !== 'UTF-8') {
6210
      $encoding = self::normalize_encoding($encoding, 'UTF-8');
6211
    }
6212
6213
    if ($lang !== null) {
6214
      if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) {
6215
        self::checkForSupport();
6216
      }
6217
6218
      if (
6219
          self::$SUPPORT['intl'] === true
6220
          &&
6221
          Bootup::is_php('5.4') === true
6222
      ) {
6223
6224
        $langCode = $lang . '-Upper';
6225
        if (!in_array($langCode, self::$SUPPORT['intl__transliterator_list_ids'], true)) {
6226
          trigger_error('UTF8::strtoupper() without intl for special language: ' . $lang, E_USER_WARNING);
6227
6228
          $langCode = 'Any-Upper';
6229
        }
6230
6231
        return transliterator_transliterate($langCode, $str);
6232
      }
6233
6234
      trigger_error('UTF8::strtolower() without intl + PHP >= 5.4 cannot handle the "lang"-parameter: ' . $lang, E_USER_WARNING);
6235
    }
6236
6237
    return \mb_strtoupper($str, $encoding);
6238
  }
6239
6240
  /**
6241
   * Translate characters or replace sub-strings.