Automattic\WooCommerce\Vendor\GraphQL\Language
BlockString::getIndentation
Method of the class: BlockString{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = BlockString::getIndentation( $value ): int;
- $value(string) (required)
- .
BlockString::getIndentation() BlockString::getIndentation code WC 10.9.1
public static function getIndentation(string $value): int
{
$isFirstLine = true;
$isEmptyLine = true;
$indent = 0;
$commonIndent = null;
$valueLength = mb_strlen($value);
for ($i = 0; $i < $valueLength; ++$i) {
switch (Utils::charCodeAt($value, $i)) {
case 13: // \r
if (Utils::charCodeAt($value, $i + 1) === 10) {
++$i; // skip \r\n as one symbol
}
// falls through
// no break
case 10: // \n
$isFirstLine = false;
$isEmptyLine = true;
$indent = 0;
break;
case 9: // \t
case 32: // <space>
++$indent;
break;
default:
if (
$isEmptyLine
&& ! $isFirstLine
&& ($commonIndent === null || $indent < $commonIndent)
) {
$commonIndent = $indent;
}
$isEmptyLine = false;
}
}
return $commonIndent ?? 0;
}