|
4 | 4 | from coalib.results.Result import Result, RESULT_SEVERITY
|
5 | 5 | from coalib.results.SourceRange import SourceRange
|
6 | 6 | from coalib.results.AbsolutePosition import AbsolutePosition
|
| 7 | +from coala_utils.string_processing.Core import unescaped_search_for |
7 | 8 |
|
8 | 9 |
|
9 | 10 | class AnnotationBear(LocalBear):
|
@@ -199,10 +200,14 @@ def get_multiline(file,
|
199 | 200 | A SourceRange object holding the range of the multi-line annotation
|
200 | 201 | and the end_position of the annotation as an integer.
|
201 | 202 | """
|
202 |
| - end_start = text.find(annotation_end, |
203 |
| - position + 1) |
204 |
| - end_end = end_start + len(annotation_end) - 1 |
205 |
| - if end_start == -1: |
| 203 | + try: |
| 204 | + end_match = next(unescaped_search_for(annotation_end, |
| 205 | + text[position + 1:])) |
| 206 | + except StopIteration: |
| 207 | + end_match = None |
| 208 | + print(end_match) |
| 209 | + end_end = position + end_match.span()[1] if end_match else -1 |
| 210 | + if end_end == -1: |
206 | 211 | _range = SourceRange.from_absolute_position(
|
207 | 212 | filename,
|
208 | 213 | AbsolutePosition(file, position))
|
@@ -238,9 +243,19 @@ def get_singleline_strings(file,
|
238 | 243 | A SourceRange object identifying the range of the single-line
|
239 | 244 | string and the end_position of the string as an integer.
|
240 | 245 | """
|
241 |
| - end_position = (text.find(string_end, position + 1) |
242 |
| - + len(string_end) - 1) |
243 |
| - newline = text.find("\n", position + 1) |
| 246 | + try: |
| 247 | + end_match = next(unescaped_search_for( |
| 248 | + string_end, text[position + 1:])) |
| 249 | + except StopIteration: |
| 250 | + end_match = None |
| 251 | + end_position = (position + end_match.span()[1] if end_match |
| 252 | + else -1) |
| 253 | + try: |
| 254 | + newline_match = next( |
| 255 | + unescaped_search_for("\n", text[position + 1:])) |
| 256 | + except StopIteration: |
| 257 | + newline_match = None |
| 258 | + newline = position + newline_match.span()[1] if newline_match else -1 |
244 | 259 | if newline == -1:
|
245 | 260 | newline = len(text)
|
246 | 261 | if end_position == -1:
|
@@ -273,7 +288,12 @@ def get_singleline_comment(file, filename, text, comment, position):
|
273 | 288 | A SourceRange object identifying the range of the single-line
|
274 | 289 | comment and the end_position of the comment as an integer.
|
275 | 290 | """
|
276 |
| - end_position = text.find("\n", position + 1) |
| 291 | + try: |
| 292 | + end_match = next(unescaped_search_for("\n", text[position + 1:])) |
| 293 | + except StopIteration: |
| 294 | + end_match = None |
| 295 | + end_position = (position + end_match.span()[1] if end_match |
| 296 | + else -1) |
277 | 297 | if end_position == -1:
|
278 | 298 | end_position = len(text) - 1
|
279 | 299 | return (SourceRange.from_absolute_position(
|
|
0 commit comments