@@ -19,7 +19,24 @@ class AndroidDumbXml(DumbXml):
19
19
# def __init__(self, source, text_position=0):
20
20
# super().__init__(source, text_position)
21
21
# self.text_position = text_position
22
-
22
+ def _find_next_lt (self , start ):
23
+ in_cdata = False
24
+ for ptr in six .moves .xrange (start , len (self .source )):
25
+ candidate = self .source [ptr ]
26
+ if in_cdata :
27
+ if (candidate == ']' and
28
+ self .source [ptr :ptr + len ("]]>" )] == "]]>" ):
29
+ in_cdata = False
30
+ else :
31
+ if candidate == self .LESS_THAN :
32
+ # Check against CDATA
33
+ if self .source [ptr :ptr + len ("<![CDATA[" )] == "<![CDATA[" :
34
+ self ._text_position = ptr + len ("<![CDATA[" )
35
+ in_cdata = True
36
+ else :
37
+ return ptr
38
+ # We reached the end of the string, lets return accordingly
39
+ return len (self .source )
23
40
24
41
@property
25
42
def content (self ):
@@ -33,15 +50,10 @@ def content(self):
33
50
return self .text
34
51
if self .content_end is None :
35
52
return None
36
-
37
- pattern = re .compile (r'!\[CDATA' )
38
- match = pattern .search (self ._text )
39
-
40
- if match :
41
- self ._text_position = self ._text_position + match .start ()+ match .end ()
42
- return self .source [self .text_position :self .content_end - 3 ]
43
- else :
44
- return self .source [self .text_position :self .content_end ]
53
+ result = self .source [self .text_position :self .content_end ]
54
+ if result .endswith ("]]>" ):
55
+ result = self .source [self .text_position :self .content_end - len ("]]>" )]
56
+ return result
45
57
46
58
47
59
class AndroidHandler (Handler ):
@@ -159,16 +171,10 @@ def _handle_string(self, child):
159
171
product ,
160
172
child
161
173
)
162
- pattern = re .compile (r'!\[CDATA' )
163
- match = pattern .search (child .content )
174
+
164
175
if string is not None :
165
176
# <string>My Text</string>
166
177
# ^
167
-
168
-
169
- print (string .string )
170
- from ipdb import set_trace
171
- #set_trace()
172
178
self .transcriber .copy_until (child .text_position )
173
179
self .transcriber .add (string .template_replacement )
174
180
# <string>My Text</string>
@@ -399,12 +405,11 @@ def _get_child_attributes(self, child):
399
405
def compile (self , template , stringset , is_source = True , language_info = None ,
400
406
** kwargs ):
401
407
resources_tag_position = template .index (self .PARSE_START )
402
-
403
408
self .transcriber = Transcriber (template [resources_tag_position :])
404
409
source = self .transcriber .source
405
410
406
411
parsed = AndroidDumbXml (source )
407
-
412
+
408
413
# Check against 'tools:locale' attribute
409
414
if language_info is not None and 'tools:locale' in parsed .attrib :
410
415
value_position , value = next ((
@@ -464,10 +469,23 @@ def _compile_string(self, child):
464
469
It will compile the tag if matching string exists. Otherwise it will
465
470
skip it.
466
471
"""
472
+
473
+ def _search_for_cdata (_destination ):
474
+ result = False
475
+ if len (_destination ) > 1 :
476
+ _string = _destination [1 ]
477
+ pattern = re .compile (r'!\[CDATA' )
478
+ match = pattern .search (_string )
479
+ if match :
480
+ result = True
481
+ return result
467
482
if self ._should_compile (child ):
483
+
484
+
468
485
self .transcriber .copy_until (child .text_position )
469
486
self .transcriber .add (self .next_string .string )
470
- self .transcriber .skip_until (child .content_end )
487
+ ret = _search_for_cdata (self .transcriber .__dict__ ['destination' ])
488
+ self .transcriber .skip_until (child .content_end if not ret else child .content_end - len ("]]>" ))
471
489
self .transcriber .copy_until (child .tail_position )
472
490
self .transcriber .mark_section_start ()
473
491
self .transcriber .copy_until (child .end )
0 commit comments