Code Duplication    Length = 18-19 lines in 2 locations

src/voku/helper/Bootup.php 1 location

@@ 185-202 (lines=18) @@
182
      $s = str_replace(array("\r\n", "\r"), "\n", $s);
183
    }
184
185
    if (preg_match('/[\x80-\xFF]/', $s)) {
186
      if (Normalizer::isNormalized($s, $normalization_form)) {
187
        $n = '-';
188
      } else {
189
        $n = Normalizer::normalize($s, $normalization_form);
190
        if (isset($n[0])) {
191
          $s = $n;
192
        } else {
193
          $s = UTF8::encode('UTF-8', $s);
194
        }
195
      }
196
197
      if ($s[0] >= "\x80" && isset($n[0], $leading_combining[0]) && preg_match('/^\p{Mn}/u', $s)) {
198
        // Prevent leading combining chars
199
        // for NFC-safe concatenations.
200
        $s = $leading_combining . $s;
201
      }
202
    }
203
204
    return $s;
205
  }

src/voku/helper/UTF8.php 1 location

@@ 2402-2420 (lines=19) @@
2399
          // Workaround https://bugs.php.net/65732
2400
          $var = str_replace(array("\r\n", "\r"), "\n", $var);
2401
        }
2402
        if (preg_match('/[\x80-\xFF]/', $var)) {
2403
          if (\Normalizer::isNormalized($var, $normalization_form)) {
2404
            $n = '-';
2405
          } else {
2406
            $n = \Normalizer::normalize($var, $normalization_form);
2407
2408
            if (isset($n[0])) {
2409
              $var = $n;
2410
            } else {
2411
              $var = self::encode('UTF-8', $var);
2412
            }
2413
2414
          }
2415
          if ($var[0] >= "\x80" && isset($n[0], $leading_combining[0]) && preg_match('/^\p{Mn}/u', $var)) {
2416
            // Prevent leading combining chars
2417
            // for NFC-safe concatenations.
2418
            $var = $leading_combining . $var;
2419
          }
2420
        }
2421
        break;
2422
    }
2423