Code Duplication    Length = 13-17 lines in 2 locations

lib/Drupal/Component/Utility/Unicode.php 2 locations

@@ 426-438 (lines=13) @@
423
          }
424
        }
425
      }
426
      elseif ($start < 0) {
427
        // Count all the characters except continuation bytes from the end
428
        // until we have found abs($start) characters.
429
        $start = abs($start);
430
        $bytes = $strlen; $chars = 0;
431
        while ($bytes > 0 && $chars < $start) {
432
          $bytes--;
433
          $c = ord($text[$bytes]);
434
          if ($c < 0x80 || $c >= 0xC0) {
435
            $chars++;
436
          }
437
        }
438
      }
439
      $istart = $bytes;
440
441
      // Find the ending byte offset.
@@ 467-483 (lines=17) @@
464
          $iend--;
465
        }
466
      }
467
      elseif ($length < 0) {
468
        // Count all the characters except continuation bytes from the end
469
        // until we have found abs($start) characters, then backtrace one byte.
470
        $length = abs($length);
471
        $iend = $strlen; $chars = 0;
472
        while ($iend > 0 && $chars < $length) {
473
          $iend--;
474
          $c = ord($text[$iend]);
475
          if ($c < 0x80 || $c >= 0xC0) {
476
            $chars++;
477
          }
478
        }
479
        // Backtrace one byte if we are not at the beginning of the string.
480
        if ($iend > 0) {
481
          $iend--;
482
        }
483
      }
484
      else {
485
        // $length == 0, return an empty string.
486
        return '';