Index: lib/src/utils.dart |
diff --git a/lib/src/utils.dart b/lib/src/utils.dart |
index 4a8eb551e5ca09a67c078a4e34a44719eb27bc64..d905188429474ee20bf627ed2dee696de7a88a47 100644 |
--- a/lib/src/utils.dart |
+++ b/lib/src/utils.dart |
@@ -37,3 +37,19 @@ int binarySearch(List list, bool matches(item)) { |
return max; |
} |
+/// Finds a line in [context] containing [text] at the specified [column]. |
+/// |
+/// Returns the index in [context] where that line begins, or -1 if none exists. |
nweiz
2015/03/31 19:22:10
Nit: I really like using "null" as a signal for "n
Siggi Cherem (dart-lang)
2015/03/31 19:51:21
Done.
|
+int findLineStart(String context, String text, int column) { |
+ var isEmpty = text == ''; |
+ var index = context.indexOf(text); |
+ while (index != -1) { |
+ var lineStart = context.lastIndexOf('\n', index) + 1; |
+ var textColumn = index - lineStart; |
+ if (column == textColumn || (isEmpty && column == textColumn + 1)) { |
+ return lineStart; |
+ } |
+ index = context.indexOf(text, index + 1); |
+ } |
+ return -1; |
+} |