diff --git a/sdk/lib/convert/line_splitter.dart b/sdk/lib/convert/line_splitter.dart index 85f0ab6e414e..2e01ae697109 100644 --- a/sdk/lib/convert/line_splitter.dart +++ b/sdk/lib/convert/line_splitter.dart @@ -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 { const LineSplitter();