Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ParserAbstract.php

function ParserAbstract::stripIndentation

Parameters

array<string, mixed> $attributes :

1 call to ParserAbstract::stripIndentation()
ParserAbstract::parseDocString in vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php

File

vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php, line 772

Class

ParserAbstract

Namespace

PhpParser

Code

protected function stripIndentation(string $string, int $indentLen, string $indentChar, bool $newlineAtStart, bool $newlineAtEnd, array $attributes) : string {
    if ($indentLen === 0) {
        return $string;
    }
    $start = $newlineAtStart ? '(?:(?<=\\n)|\\A)' : '(?<=\\n)';
    $end = $newlineAtEnd ? '(?:(?=[\\r\\n])|\\z)' : '(?=[\\r\\n])';
    $regex = '/' . $start . '([ \\t]*)(' . $end . ')?/';
    return preg_replace_callback($regex, function ($matches) use ($indentLen, $indentChar, $attributes) {
        $prefix = substr($matches[1], 0, $indentLen);
        if (false !== strpos($prefix, $indentChar === " " ? "\t" : " ")) {
            $this->emitError(new Error('Invalid indentation - tabs and spaces cannot be mixed', $attributes));
        }
        elseif (strlen($prefix) < $indentLen && !isset($matches[2])) {
            $this->emitError(new Error('Invalid body indentation level ' . '(expecting an indentation level of at least ' . $indentLen . ')', $attributes));
        }
        return substr($matches[0], strlen($prefix));
    }, $string);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal