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,13 @@ 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
+ end_end = position + end_match .span ()[1 ]
207
+ except StopIteration :
208
+ end_end = - 1
209
+ if end_end == - 1 :
206
210
_range = SourceRange .from_absolute_position (
207
211
filename ,
208
212
AbsolutePosition (file , position ))
@@ -238,9 +242,18 @@ def get_singleline_strings(file,
238
242
A SourceRange object identifying the range of the single-line
239
243
string and the end_position of the string as an integer.
240
244
"""
241
- end_position = (text .find (string_end , position + 1 )
242
- + len (string_end ) - 1 )
243
- newline = text .find ("\n " , position + 1 )
245
+ try :
246
+ end_match = next (unescaped_search_for (
247
+ string_end , text [position + 1 :]))
248
+ end_position = (position + end_match .span ()[1 ])
249
+ except StopIteration :
250
+ end_position = - 1
251
+ try :
252
+ newline_match = next (
253
+ unescaped_search_for ("\n " , text [position + 1 :]))
254
+ newline = position + newline_match .span ()[1 ]
255
+ except StopIteration :
256
+ newline = - 1
244
257
if newline == - 1 :
245
258
newline = len (text )
246
259
if end_position == - 1 :
@@ -273,7 +286,11 @@ def get_singleline_comment(file, filename, text, comment, position):
273
286
A SourceRange object identifying the range of the single-line
274
287
comment and the end_position of the comment as an integer.
275
288
"""
276
- end_position = text .find ("\n " , position + 1 )
289
+ try :
290
+ end_match = next (unescaped_search_for ("\n " , text [position + 1 :]))
291
+ end_position = position + end_match .span ()[1 ]
292
+ except StopIteration :
293
+ end_position = - 1
277
294
if end_position == - 1 :
278
295
end_position = len (text ) - 1
279
296
return (SourceRange .from_absolute_position (
@@ -287,4 +304,4 @@ class NoCloseError(Exception):
287
304
288
305
def __init__ (self , annotation , code ):
289
306
Exception .__init__ (self , annotation + " has no closure" )
290
- self .code = code
307
+ self .code = code
0 commit comments