Skip to content

Documentation update for LineSplitter #47621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions sdk/lib/convert/line_splitter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,31 @@ const int _CR = 13;

/// A [StreamTransformer] that splits a [String] into individual lines.
///
/// A line is terminated by either a CR (U+000D), a LF (U+000A), a
/// CR+LF sequence (DOS line ending),
/// and a final non-empty line can be ended by the end of the string.
/// A line is terminated by either:
/// * a CR, carriage return: U+000D ('\r')
/// * a LF, line feed (Unix line break): U+000A ('\n') or
/// * a CR+LF sequence (DOS/Windows line break), and
/// * a final non-empty line can be ended by the end of the input.
///
/// The returned lines do not contain the line terminators.

/// The resulting lines do not contain the line terminators.
///
/// Example:
/// ```dart
/// const splitter = LineSplitter();
/// const sampleText =
/// 'Dart is: \r an object-oriented \n class-based \n garbage-collected '
/// '\r\n language with C-style syntax \r\n';
///
/// final sampleTextLines = splitter.convert(sampleText);
/// for (var i = 0; i < sampleTextLines.length; i++) {
/// print('$i: ${sampleTextLines[i]}');
/// }
/// // 0: Dart is:
/// // 1: an object-oriented
/// // 2: class-based
/// // 3: garbage-collected
/// // 4: language with C-style syntax
/// ```
class LineSplitter extends StreamTransformerBase<String, String> {
const LineSplitter();

Expand Down