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..0a24e7171627bda34b6b3d9d2992cc635685f3c0 100644 |
--- a/lib/src/span_with_context.dart |
+++ b/lib/src/span_with_context.dart |
@@ -29,10 +29,20 @@ class SourceSpanWithContext extends SourceSpanBase { |
'The context line "$context" must contain "$text".'); |
} |
- var beginningOfLine = context.lastIndexOf('\n', index) + 1; |
- if (start.column != index - beginningOfLine) { |
- throw new ArgumentError('The span text "$text" must start at ' |
- 'column ${start.column + 1} in a line within "$context".'); |
+ // Note: `text` can appear in multiple places within context, but we don't |
+ // know which occurrance of `text` is the one in the right location. |
+ while (index != -1) { |
+ var beginningOfLine = context.lastIndexOf('\n', index) + 1; |
+ |
+ // if the column matches, we are all set with validation. |
+ if (start.column == index - beginningOfLine) return; |
+ |
+ index = context.indexOf(text, index + 1); |
} |
nweiz
2015/03/30 23:45:51
Shouldn't you also do this logic when constructing
Siggi Cherem (dart-lang)
2015/03/31 01:07:49
good point - fixed too.
|
+ |
+ // No match was found, means that all occurrences of `text` were not in the |
+ // right place. |
+ throw new ArgumentError('The span text "$text" must start at ' |
+ 'column ${start.column + 1} in a line within "$context".'); |
} |
} |