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

Unified Diff: pkg/analyzer/lib/src/generated/java_engine.dart

Issue 1411253007: Extract 'computeLineStarts' utility. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Move into StringUtilities. 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/java_engine.dart
diff --git a/pkg/analyzer/lib/src/generated/java_engine.dart b/pkg/analyzer/lib/src/generated/java_engine.dart
index d0fb62bd8d8a87d260823f4098af53c312a787c7..8b10e718bca85283a249356b597f393dad88c88c 100644
--- a/pkg/analyzer/lib/src/generated/java_engine.dart
+++ b/pkg/analyzer/lib/src/generated/java_engine.dart
@@ -121,6 +121,33 @@ class StringUtilities {
static Interner INTERNER = new NullInterner();
+ /**
+ * Compute line starts for the given [content].
+ * Lines end with `\r`, `\n` or `\r\n`.
+ */
+ static List<int> computeLineStarts(String content) {
+ 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;
+ }
+
static endsWith3(String str, int c1, int c2, int c3) {
var length = str.length;
return length >= 3 &&
« 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