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

Unified 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, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/task/html.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/utilities_string.dart
diff --git a/pkg/analyzer/lib/src/generated/utilities_string.dart b/pkg/analyzer/lib/src/generated/utilities_string.dart
new file mode 100644
index 0000000000000000000000000000000000000000..508a9a4b55e487c57904ac53d7f90b3c848f8961
--- /dev/null
+++ b/pkg/analyzer/lib/src/generated/utilities_string.dart
@@ -0,0 +1,32 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library engine.utilities.string;
+
+/**
+ * Compute line starts for the given [content].
+ * Lines end with `\r`, `\n` or `\r\n`.
+ */
+List<int> computeLineStarts(String content) {
Brian Wilkerson 2015/10/27 20:44:10 Could we add it to StringUtilities so that there's
+ List<int> lineStarts = <int>[0];
+ int length = content.length;
+ int unit;
+ for (int index = 0; index < length; index++) {
+ unit = content.codeUnitAt(index);
+ // Special-case \r\n.
+ if (unit == 0x0D /* \r */) {
+ // Peek ahead to detect a following \n.
+ if ((index + 1 < length) && content.codeUnitAt(index + 1) == 0x0A) {
+ // Line start will get registered at next index at the \n.
+ } else {
+ lineStarts.add(index + 1);
+ }
+ }
+ // \n
+ if (unit == 0x0A) {
+ lineStarts.add(index + 1);
+ }
+ }
+ return lineStarts;
+}
« 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