Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(715)

Side by Side Diff: sdk/lib/convert/line_splitter.dart

Issue 22860004: nits from cr 22070003 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: trailing whitespace Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/lib/convert/line_splitter_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.convert; 5 part of dart.convert;
6 6
7 /** 7 /**
8 * This class splits [String] values into individual lines. 8 * This class splits [String] values into individual lines.
9 */ 9 */
10 class LineSplitter extends Converter<String, List<String>> { 10 class LineSplitter extends Converter<String, List<String>> {
(...skipping 20 matching lines...) Expand all
31 static const int _LF = 10; 31 static const int _LF = 10;
32 static const int _CR = 13; 32 static const int _CR = 13;
33 33
34 final StringConversionSink _sink; 34 final StringConversionSink _sink;
35 35
36 String _carry; 36 String _carry;
37 37
38 _LineSplitterSink(this._sink); 38 _LineSplitterSink(this._sink);
39 39
40 void addSlice(String chunk, int start, int end, bool isLast) { 40 void addSlice(String chunk, int start, int end, bool isLast) {
41 if(_carry != null) { 41 if (_carry != null) {
42 chunk = _carry + chunk.substring(start, end); 42 chunk = _carry + chunk.substring(start, end);
43 start = 0; 43 start = 0;
44 end = chunk.length; 44 end = chunk.length;
45 _carry = null; 45 _carry = null;
46 } 46 }
47 _carry = _addSlice(chunk, start, end, isLast, _sink.add); 47 _carry = _addSlice(chunk, start, end, isLast, _sink.add);
48 if(isLast) _sink.close(); 48 if (isLast) _sink.close();
49 } 49 }
50 50
51 void close() { 51 void close() {
52 addSlice('', 0, 0, true); 52 addSlice('', 0, 0, true);
53 } 53 }
54 54
55 static String _addSlice(String chunk, int start, int end, bool isLast, void ad der(String val)) { 55 static String _addSlice(String chunk, int start, int end, bool isLast,
56 void adder(String val)) {
57
56 int pos = start; 58 int pos = start;
57 while (pos < end) { 59 while (pos < end) {
58 int skip = 0; 60 int skip = 0;
59 int char = chunk.codeUnitAt(pos); 61 int char = chunk.codeUnitAt(pos);
60 if (char == _LF) { 62 if (char == _LF) {
61 skip = 1; 63 skip = 1;
62 } else if (char == _CR) { 64 } else if (char == _CR) {
63 skip = 1; 65 skip = 1;
64 if (pos + 1 < end) { 66 if (pos + 1 < end) {
65 if (chunk.codeUnitAt(pos + 1) == _LF) { 67 if (chunk.codeUnitAt(pos + 1) == _LF) {
66 skip = 2; 68 skip = 2;
67 } 69 }
68 } else if (!isLast) { 70 } else if (!isLast) {
69 return chunk.substring(start, end); 71 return chunk.substring(start, end);
70 } 72 }
71 } 73 }
72 if (skip > 0) { 74 if (skip > 0) {
73 adder(chunk.substring(start, pos)); 75 adder(chunk.substring(start, pos));
74 start = pos = pos + skip; 76 start = pos = pos + skip;
75 } else { 77 } else {
76 pos++; 78 pos++;
77 } 79 }
78 } 80 }
79 if (pos != start) { 81 if (pos != start) {
80 var carry = chunk.substring(start, pos); 82 var carry = chunk.substring(start, pos);
81 if(isLast) { 83 if (isLast) {
82 // Add remaining 84 // Add remaining
83 adder(carry); 85 adder(carry);
84 } else { 86 } else {
85 return carry; 87 return carry;
86 } 88 }
87 } 89 }
88 return null; 90 return null;
89 } 91 }
90 } 92 }
OLDNEW
« no previous file with comments | « no previous file | tests/lib/convert/line_splitter_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698