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

Breadcrumb

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

function Comment::getShortestWhitespacePrefixLen

Get length of shortest whitespace prefix (at the start of a line).

If there is a line with no prefix whitespace, 0 is a valid return value.

Parameters

string $str String to check:

Return value

int Length in characters. Tabs count as single characters.

1 call to Comment::getShortestWhitespacePrefixLen()
Comment::getReformattedText in vendor/nikic/php-parser/lib/PhpParser/Comment.php
Gets the reformatted comment text.

File

vendor/nikic/php-parser/lib/PhpParser/Comment.php, line 178

Class

Comment

Namespace

PhpParser

Code

private function getShortestWhitespacePrefixLen(string $str) : int {
    $lines = explode("\n", $str);
    $shortestPrefixLen = \PHP_INT_MAX;
    foreach ($lines as $line) {
        preg_match('(^\\s*)', $line, $matches);
        $prefixLen = strlen($matches[0]);
        if ($prefixLen < $shortestPrefixLen) {
            $shortestPrefixLen = $prefixLen;
        }
    }
    return $shortestPrefixLen;
}
RSS feed
Powered by Drupal