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

Unified Diff: lib/src/span_with_context.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_mixin.dart ('k') | lib/src/utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/span_with_context.dart
diff --git a/lib/src/span_with_context.dart b/lib/src/span_with_context.dart
index edbb8b65ffe278f3084a4b8aa016c5b15df53a41..0012e3f3d706080c479d5d08a1d462441f713083 100644
--- a/lib/src/span_with_context.dart
+++ b/lib/src/span_with_context.dart
@@ -6,6 +6,7 @@ library source_span.span_with_context;
import 'location.dart';
import 'span.dart';
+import 'utils.dart';
/// A class that describes a segment of source text with additional context.
class SourceSpanWithContext extends SourceSpanBase {
@@ -23,14 +24,12 @@ class SourceSpanWithContext extends SourceSpanBase {
SourceSpanWithContext(
SourceLocation start, SourceLocation end, String text, this.context)
: super(start, end, text) {
- var index = context.indexOf(text);
- if (index == -1) {
+ if (!context.contains(text)) {
throw new ArgumentError(
'The context line "$context" must contain "$text".');
}
- var beginningOfLine = context.lastIndexOf('\n', index) + 1;
- if (start.column != index - beginningOfLine) {
+ if (findLineStart(context, text, start.column) == null) {
throw new ArgumentError('The span text "$text" must start at '
'column ${start.column + 1} in a line within "$context".');
}
« no previous file with comments | « lib/src/span_mixin.dart ('k') | lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698