Skip to content

Commit 93c2aad

Browse files
jpsiitonencommit-bot@chromium.org
authored andcommitted
Documentation update for LineSplitter
Adding example of usage Closes #47621 #47621 GitOrigin-RevId: e2509b5 Change-Id: I1cd79309799d8361c359c4e5194473bc4e46463b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/219280 Reviewed-by: Lasse R.H. Nielsen <[email protected]> Commit-Queue: Lasse R.H. Nielsen <[email protected]>
1 parent 56035a7 commit 93c2aad

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

sdk/lib/convert/line_splitter.dart

+24-5
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,31 @@ const int _CR = 13;
1010

1111
/// A [StreamTransformer] that splits a [String] into individual lines.
1212
///
13-
/// A line is terminated by either a CR (U+000D), a LF (U+000A), a
14-
/// CR+LF sequence (DOS line ending),
15-
/// and a final non-empty line can be ended by the end of the string.
13+
/// A line is terminated by either:
14+
/// * a CR, carriage return: U+000D ('\r')
15+
/// * a LF, line feed (Unix line break): U+000A ('\n') or
16+
/// * a CR+LF sequence (DOS/Windows line break), and
17+
/// * a final non-empty line can be ended by the end of the input.
1618
///
17-
/// The returned lines do not contain the line terminators.
18-
19+
/// The resulting lines do not contain the line terminators.
20+
///
21+
/// Example:
22+
/// ```dart
23+
/// const splitter = LineSplitter();
24+
/// const sampleText =
25+
/// 'Dart is: \r an object-oriented \n class-based \n garbage-collected '
26+
/// '\r\n language with C-style syntax \r\n';
27+
///
28+
/// final sampleTextLines = splitter.convert(sampleText);
29+
/// for (var i = 0; i < sampleTextLines.length; i++) {
30+
/// print('$i: ${sampleTextLines[i]}');
31+
/// }
32+
/// // 0: Dart is:
33+
/// // 1: an object-oriented
34+
/// // 2: class-based
35+
/// // 3: garbage-collected
36+
/// // 4: language with C-style syntax
37+
/// ```
1938
class LineSplitter extends StreamTransformerBase<String, String> {
2039
const LineSplitter();
2140

0 commit comments

Comments
 (0)