# Lines

> Splits, inspects and rebuilds text line by line while keeping the original end-of-line bytes.

[API reference](/docs/api/index.md) › [Scaffold](/docs/extensions/scaffold/reference/index.md) › [Merge](/docs/extensions/scaffold/reference/merge/index.md) › Lines

| final class | `PHPForge\Scaffold\Merge\Lines` |
| --- | --- |
| Source | [`src/Merge/Lines.php`](https://github.com/php-forge/scaffold/blob/main/src/Merge/Lines.php#L22) |

Splits, inspects and rebuilds text line by line while keeping the original end-of-line bytes.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`detectEol()`](#method-detectEol) static | Returns the dominant end-of-line sequence: `"\r\n"`, `"\r"`, or `"\n"` (also for content without one). | `Lines` |
| [`endsWithEol()`](#method-endsWithEol) static | Returns whether the content ends with an end-of-line sequence. | `Lines` |
| [`normalise()`](#method-normalise) static | Converts `"\r\n"` and `"\r"` terminators to `"\n"`. | `Lines` |
| [`rebuild()`](#method-rebuild) static | Rebuilds consumer segments verbatim with inserted lines and appended blocks, each block after one blank line. | `Lines` |
| [`split()`](#method-split) static | Splits content normalised to `"\n"` into lines, ignoring the terminator of the last line. | `Lines` |
| [`splitRaw()`](#method-splitRaw) static | Splits raw content into lines that keep their original terminator. | `Lines` |

## Method details

### detectEol() <span id="method-detectEol"></span>

```php
public static function detectEol(string $content): string
```

Returns 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() <span id="method-endsWithEol"></span>

```php
public static function endsWithEol(string $content): bool
```

Returns 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() <span id="method-normalise"></span>

```php
public static function normalise(string $content): string
```

Converts `"\r\n"` and `"\r"` terminators to `"\n"`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$content` | `string` | Content to normalise. |

**Returns**

`string`: Content with `"\n"` terminators only.

### rebuild() <span id="method-rebuild"></span>

```php
public static function rebuild(list<array{string, string}> $segments, array<int, list<string>> $insertAfter, list<list<string>> $blocks, string $eol, bool $finalEol): string
```

Rebuilds consumer segments verbatim with inserted lines and appended blocks, each block after one blank line.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$segments` | `list<array{string, string}>` | Consumer `[text, terminator]` segments. |
| `$insertAfter` | `array<int, list<string>>` | 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() <span id="method-split"></span>

```php
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 `"\n"` terminators. |

**Returns**

`list<string>`: Lines; empty for empty content.

### splitRaw() <span id="method-splitRaw"></span>

```php
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 `"\r\n"`, `"\r"` and `"\n"` 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.