Path: redb-route/redb.Route/Expressions/Tokenizers/LineTokenizer.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route/Expressions/Tokenizers/LineTokenizer.cs ---- using System.Runtime.CompilerServices; using System.Text; namespace redb.Route.Expressions.Tokenizers; /// /// Splits body content into lines using a configurable separator. /// Supports , , and byte[] bodies. /// internal static class LineTokenizer { /// Tokenizes the body into individual lines. /// Exchange body (Stream, string, or byte[]). /// Line separator string. /// Whether to skip empty/whitespace lines. /// Cancellation token. internal static async IAsyncEnumerable Tokenize( object? body, string separator, bool skipEmpty, [EnumeratorCancellation] CancellationToken ct = default) { switch (body) { case Stream stream: using (var reader = new StreamReader(stream, leaveOpen: true)) { while (await reader.ReadLineAsync(ct).ConfigureAwait(false) is { } line) { if (skipEmpty && string.IsNullOrWhiteSpace(line)) continue; yield return line; } } break; case string str: foreach (var line in str.Split(separator)) { ct.ThrowIfCancellationRequested(); if (skipEmpty && string.IsNullOrWhiteSpace(line)) continue; yield return line; } break; case byte[] bytes: var text = Encoding.UTF8.GetString(bytes); foreach (var line in text.Split(separator)) { ct.ThrowIfCancellationRequested(); if (skipEmpty && string.IsNullOrWhiteSpace(line)) continue; yield return line; } break; } } }