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,8 @@ 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
+ end_end = get_end_position (annotation_end , text , position )
204
+ if end_end == - 1 :
206
205
_range = SourceRange .from_absolute_position (
207
206
filename ,
208
207
AbsolutePosition (file , position ))
@@ -238,9 +237,8 @@ def get_singleline_strings(file,
238
237
A SourceRange object identifying the range of the single-line
239
238
string and the end_position of the string as an integer.
240
239
"""
241
- end_position = (text .find (string_end , position + 1 )
242
- + len (string_end ) - 1 )
243
- newline = text .find ("\n " , position + 1 )
240
+ end_position = get_end_position (string_end , text , position )
241
+ newline = get_end_position ("\n " , text , position )
244
242
if newline == - 1 :
245
243
newline = len (text )
246
244
if end_position == - 1 :
@@ -273,7 +271,7 @@ def get_singleline_comment(file, filename, text, comment, position):
273
271
A SourceRange object identifying the range of the single-line
274
272
comment and the end_position of the comment as an integer.
275
273
"""
276
- end_position = text . find ("\n " , position + 1 )
274
+ end_position = get_end_position ("\n " , text , position )
277
275
if end_position == - 1 :
278
276
end_position = len (text ) - 1
279
277
return (SourceRange .from_absolute_position (
@@ -283,6 +281,16 @@ def get_singleline_comment(file, filename, text, comment, position):
283
281
end_position )
284
282
285
283
284
+ def get_end_position (end_marker , text , position ):
285
+ try :
286
+ end_match = next (unescaped_search_for (end_marker , text [position + 1 :]))
287
+ end_position = position + end_match .span ()[1 ]
288
+ except StopIteration :
289
+ end_position = - 1
290
+
291
+ return end_position
292
+
293
+
286
294
class NoCloseError (Exception ):
287
295
288
296
def __init__ (self , annotation , code ):
0 commit comments