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; |
+} |