Lines
API reference › Scaffold › Merge › Lines
Splits, inspects and rebuilds text line by line while keeping the original end-of-line bytes.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
detectEol() static | Returns the dominant end-of-line sequence: "\, "\, or "\ (also for content without one). | Lines |
endsWithEol() static | Returns whether the content ends with an end-of-line sequence. | Lines |
normalise() static | Converts "\ and "\ terminators to "\. | Lines |
rebuild() static | Rebuilds consumer segments verbatim with inserted lines and appended blocks, each block after one blank line. | Lines |
split() static | Splits content normalised to "\ into lines, ignoring the terminator of the last line. | Lines |
splitRaw() static | Splits raw content into lines that keep their original terminator. | Lines |
Method details
Section titled “Method details”detectEol()
Section titled “detectEol() ”public static function detectEol(string $content): stringReturns the dominant end-of-line sequence: "\r\n", "\r", or "\n" (also for content without one).
Parameters
| Parameter | Type | Description |
|---|---|---|
$content | string | Content to inspect. |
Returns
string: "\r\n" when present, otherwise "\r" when present, otherwise "\n".
endsWithEol()
Section titled “endsWithEol() ”public static function endsWithEol(string $content): boolReturns whether the content ends with an end-of-line sequence.
Parameters
| Parameter | Type | Description |
|---|---|---|
$content | string | Content to inspect. |
Returns
bool: true when the content ends with "\n" or "\r".
normalise()
Section titled “normalise() ”public static function normalise(string $content): stringConverts "\r\n" and "\r" terminators to "\n".
Parameters
| Parameter | Type | Description |
|---|---|---|
$content | string | Content to normalise. |
Returns
string: Content with "\n" terminators only.
rebuild()
Section titled “rebuild() ”public static function rebuild(list<array{string, string}> $segments, array<int, list<string>> $insertAfter, list<list<string>> $blocks, string $eol, bool $finalEol): stringRebuilds consumer segments verbatim with inserted lines and appended blocks, each block after one blank line.
Parameters
| Parameter | Type | Description |
|---|---|---|
$segments | list<array{string, | Consumer [text, segments. |
$insertAfter | array<int, | Lines to insert after the segment with the given index; index -1 inserts before the first segment. |
$blocks | list<list<string>> | Blocks of lines appended at the end, in order. |
$eol | string | End-of-line sequence used for inserted lines. |
$finalEol | bool | Whether the result must end with an end-of-line sequence. |
Returns
string: Rebuilt content.
split()
Section titled “split() ”public static function split(string $content): list<string>Splits content normalised to "\n" into lines, ignoring the terminator of the last line.
Parameters
| Parameter | Type | Description |
|---|---|---|
$content | string | Content normalised to "\ terminators. |
Returns
list<string>: Lines; empty for empty content.
splitRaw()
Section titled “splitRaw() ”public static function splitRaw(string $content): list<array{string, string}>Splits raw content into lines that keep their original terminator.
Parameters
| Parameter | Type | Description |
|---|---|---|
$content | string | Content with any mix of "\, "\ and "\ terminators. |
Returns
list<array{string, string}>: [text, terminator] pairs; the last terminator is empty when the content does not end with an end-of-line sequence.