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

Side by Side Diff: pkg/analyzer/lib/src/generated/utilities_string.dart

Issue 1411253007: Extract 'computeLineStarts' utility. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/task/html.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
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.
4
5 library engine.utilities.string;
6
7 /**
8 * Compute line starts for the given [content].
9 * Lines end with `\r`, `\n` or `\r\n`.
10 */
11 List<int> computeLineStarts(String content) {
Brian Wilkerson 2015/10/27 20:44:10 Could we add it to StringUtilities so that there's
12 List<int> lineStarts = <int>[0];
13 int length = content.length;
14 int unit;
15 for (int index = 0; index < length; index++) {
16 unit = content.codeUnitAt(index);
17 // Special-case \r\n.
18 if (unit == 0x0D /* \r */) {
19 // Peek ahead to detect a following \n.
20 if ((index + 1 < length) && content.codeUnitAt(index + 1) == 0x0A) {
21 // Line start will get registered at next index at the \n.
22 } else {
23 lineStarts.add(index + 1);
24 }
25 }
26 // \n
27 if (unit == 0x0A) {
28 lineStarts.add(index + 1);
29 }
30 }
31 return lineStarts;
32 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/task/html.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698