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

Unified Diff: lib/src/utils.dart

Issue 1041163005: Support multiple occurrences of text in context (Closed) Base URL: git@github.com:dart-lang/source_span.git@master
Patch Set: Created 5 years, 9 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 | « lib/src/span_with_context.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/utils.dart
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index 4a8eb551e5ca09a67c078a4e34a44719eb27bc64..2d3386542dceb182631363fe3e4041deacb92bee 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -37,3 +37,20 @@ 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 null if none
+/// exists.
+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 null;
+}
« no previous file with comments | « lib/src/span_with_context.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698