oga 1.0.2-java → 1.0.3-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/ext/c/lexer.c +394 -312
- data/ext/c/lexer.rl +3 -3
- data/ext/java/org/liboga/xml/Lexer.java +216 -172
- data/ext/java/org/liboga/xml/Lexer.rl +1 -1
- data/ext/ragel/base_lexer.rl +30 -11
- data/lib/liboga.jar +0 -0
- data/lib/oga/blacklist.rb +2 -2
- data/lib/oga/css/parser.rb +26 -28
- data/lib/oga/entity_decoder.rb +2 -2
- data/lib/oga/html/entities.rb +1 -1
- data/lib/oga/lru.rb +6 -6
- data/lib/oga/oga.rb +14 -14
- data/lib/oga/version.rb +1 -1
- data/lib/oga/whitelist.rb +2 -2
- data/lib/oga/xml/attribute.rb +16 -18
- data/lib/oga/xml/cdata.rb +1 -1
- data/lib/oga/xml/character_node.rb +3 -5
- data/lib/oga/xml/comment.rb +1 -1
- data/lib/oga/xml/doctype.rb +21 -23
- data/lib/oga/xml/document.rb +11 -17
- data/lib/oga/xml/element.rb +19 -29
- data/lib/oga/xml/entities.rb +3 -3
- data/lib/oga/xml/lexer.rb +34 -15
- data/lib/oga/xml/namespace.rb +8 -10
- data/lib/oga/xml/node.rb +8 -10
- data/lib/oga/xml/node_set.rb +16 -18
- data/lib/oga/xml/parser.rb +1 -1
- data/lib/oga/xml/processing_instruction.rb +3 -5
- data/lib/oga/xml/pull_parser.rb +6 -9
- data/lib/oga/xml/querying.rb +4 -4
- data/lib/oga/xml/sax_parser.rb +4 -4
- data/lib/oga/xml/text.rb +4 -4
- data/lib/oga/xml/xml_declaration.rb +11 -15
- data/lib/oga/xpath/evaluator.rb +81 -81
- metadata +66 -66
data/lib/oga/xml/sax_parser.rb
CHANGED
@@ -99,7 +99,7 @@ module Oga
|
|
99
99
|
def on_element(namespace, name, attrs = [])
|
100
100
|
run_callback(:on_element, namespace, name, attrs)
|
101
101
|
|
102
|
-
|
102
|
+
[namespace, name]
|
103
103
|
end
|
104
104
|
|
105
105
|
##
|
@@ -132,7 +132,7 @@ module Oga
|
|
132
132
|
value = EntityDecoder.try_decode(value, @lexer.html?)
|
133
133
|
end
|
134
134
|
|
135
|
-
|
135
|
+
{key => value}
|
136
136
|
end
|
137
137
|
|
138
138
|
##
|
@@ -153,7 +153,7 @@ module Oga
|
|
153
153
|
pair.each { |key, value| merged[key] = value }
|
154
154
|
end
|
155
155
|
|
156
|
-
|
156
|
+
merged
|
157
157
|
end
|
158
158
|
|
159
159
|
##
|
@@ -177,7 +177,7 @@ module Oga
|
|
177
177
|
# @return [TrueClass|FalseClass]
|
178
178
|
#
|
179
179
|
def inside_literal_html?
|
180
|
-
|
180
|
+
@lexer.html_script? || @lexer.html_style?
|
181
181
|
end
|
182
182
|
|
183
183
|
##
|
data/lib/oga/xml/text.rb
CHANGED
@@ -31,7 +31,7 @@ module Oga
|
|
31
31
|
@decoded = true
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
@text
|
35
35
|
end
|
36
36
|
|
37
37
|
##
|
@@ -40,7 +40,7 @@ module Oga
|
|
40
40
|
def to_xml
|
41
41
|
return super if inside_literal_html?
|
42
42
|
|
43
|
-
|
43
|
+
Entities.encode(super)
|
44
44
|
end
|
45
45
|
|
46
46
|
private
|
@@ -49,7 +49,7 @@ module Oga
|
|
49
49
|
# @return [TrueClass|FalseClass]
|
50
50
|
#
|
51
51
|
def decode_entities?
|
52
|
-
|
52
|
+
!@decoded && !inside_literal_html?
|
53
53
|
end
|
54
54
|
|
55
55
|
##
|
@@ -58,7 +58,7 @@ module Oga
|
|
58
58
|
def inside_literal_html?
|
59
59
|
node = parent
|
60
60
|
|
61
|
-
|
61
|
+
node.is_a?(Element) && html? &&
|
62
62
|
Lexer::LITERAL_HTML_ELEMENTS.allow?(node.name)
|
63
63
|
end
|
64
64
|
end # Text
|
@@ -3,20 +3,16 @@ module Oga
|
|
3
3
|
##
|
4
4
|
# Class containing information about an XML declaration tag.
|
5
5
|
#
|
6
|
-
# @!attribute [rw] version
|
7
|
-
# The XML version.
|
8
|
-
# @return [String]
|
9
|
-
#
|
10
|
-
# @!attribute [rw] encoding
|
11
|
-
# The XML document's encoding.
|
12
|
-
# @return [String]
|
13
|
-
#
|
14
|
-
# @!attribute [rw] standalone
|
15
|
-
# Whether or not the document is a standalone document.
|
16
|
-
# @return [String]
|
17
|
-
#
|
18
6
|
class XmlDeclaration
|
19
|
-
|
7
|
+
# @return [String]
|
8
|
+
attr_accessor :version
|
9
|
+
|
10
|
+
# @return [String]
|
11
|
+
attr_accessor :encoding
|
12
|
+
|
13
|
+
# Whether or not the document is a standalone document.
|
14
|
+
# @return [String]
|
15
|
+
attr_accessor :standalone
|
20
16
|
|
21
17
|
##
|
22
18
|
# @param [Hash] options
|
@@ -45,7 +41,7 @@ module Oga
|
|
45
41
|
pairs << %Q{#{getter}="#{value}"} if value
|
46
42
|
end
|
47
43
|
|
48
|
-
|
44
|
+
"<?xml #{pairs.join(' ')} ?>"
|
49
45
|
end
|
50
46
|
|
51
47
|
##
|
@@ -62,7 +58,7 @@ module Oga
|
|
62
58
|
end
|
63
59
|
end
|
64
60
|
|
65
|
-
|
61
|
+
"XmlDeclaration(#{segments.join(' ')})"
|
66
62
|
end
|
67
63
|
end # XmlDeclaration
|
68
64
|
end # XML
|
data/lib/oga/xpath/evaluator.rb
CHANGED
@@ -89,7 +89,7 @@ module Oga
|
|
89
89
|
def evaluate(string)
|
90
90
|
ast = Parser.parse_with_cache(string)
|
91
91
|
|
92
|
-
|
92
|
+
evaluate_ast(ast)
|
93
93
|
end
|
94
94
|
|
95
95
|
##
|
@@ -101,7 +101,7 @@ module Oga
|
|
101
101
|
def evaluate_ast(ast)
|
102
102
|
context = XML::NodeSet.new([@document])
|
103
103
|
|
104
|
-
|
104
|
+
process(ast, context)
|
105
105
|
end
|
106
106
|
|
107
107
|
##
|
@@ -119,7 +119,7 @@ module Oga
|
|
119
119
|
def process(ast_node, context)
|
120
120
|
handler = "on_#{ast_node.type}"
|
121
121
|
|
122
|
-
|
122
|
+
send(handler, ast_node, context)
|
123
123
|
end
|
124
124
|
|
125
125
|
##
|
@@ -137,7 +137,7 @@ module Oga
|
|
137
137
|
end
|
138
138
|
|
139
139
|
# If the expression is just "/" we'll just return the current context.
|
140
|
-
|
140
|
+
ast_node.children.empty? ? context : on_path(ast_node, context)
|
141
141
|
end
|
142
142
|
|
143
143
|
##
|
@@ -164,7 +164,7 @@ module Oga
|
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
167
|
-
|
167
|
+
nodes
|
168
168
|
end
|
169
169
|
|
170
170
|
##
|
@@ -181,7 +181,7 @@ module Oga
|
|
181
181
|
nodes << xml_node if node_matches?(xml_node, ast_node)
|
182
182
|
end
|
183
183
|
|
184
|
-
|
184
|
+
nodes
|
185
185
|
end
|
186
186
|
|
187
187
|
##
|
@@ -221,7 +221,7 @@ module Oga
|
|
221
221
|
end
|
222
222
|
end
|
223
223
|
|
224
|
-
|
224
|
+
final_nodes
|
225
225
|
end
|
226
226
|
|
227
227
|
##
|
@@ -238,7 +238,7 @@ module Oga
|
|
238
238
|
|
239
239
|
handler = name.gsub('-', '_')
|
240
240
|
|
241
|
-
|
241
|
+
send("on_axis_#{handler}", test, context)
|
242
242
|
end
|
243
243
|
|
244
244
|
##
|
@@ -266,7 +266,7 @@ module Oga
|
|
266
266
|
end
|
267
267
|
end
|
268
268
|
|
269
|
-
|
269
|
+
nodes
|
270
270
|
end
|
271
271
|
|
272
272
|
##
|
@@ -288,7 +288,7 @@ module Oga
|
|
288
288
|
end
|
289
289
|
end
|
290
290
|
|
291
|
-
|
291
|
+
nodes
|
292
292
|
end
|
293
293
|
|
294
294
|
##
|
@@ -312,7 +312,7 @@ module Oga
|
|
312
312
|
nodes += on_test(ast_node, xml_node.attributes)
|
313
313
|
end
|
314
314
|
|
315
|
-
|
315
|
+
nodes
|
316
316
|
end
|
317
317
|
|
318
318
|
##
|
@@ -324,7 +324,7 @@ module Oga
|
|
324
324
|
# @return [Oga::XML::NodeSet]
|
325
325
|
#
|
326
326
|
def on_axis_child(ast_node, context)
|
327
|
-
|
327
|
+
process(ast_node, child_nodes(context))
|
328
328
|
end
|
329
329
|
|
330
330
|
##
|
@@ -344,7 +344,7 @@ module Oga
|
|
344
344
|
end
|
345
345
|
end
|
346
346
|
|
347
|
-
|
347
|
+
nodes
|
348
348
|
end
|
349
349
|
|
350
350
|
##
|
@@ -359,7 +359,7 @@ module Oga
|
|
359
359
|
|
360
360
|
nodes.concat(on_axis_descendant(ast_node, context))
|
361
361
|
|
362
|
-
|
362
|
+
nodes
|
363
363
|
end
|
364
364
|
|
365
365
|
##
|
@@ -390,7 +390,7 @@ module Oga
|
|
390
390
|
end
|
391
391
|
end
|
392
392
|
|
393
|
-
|
393
|
+
nodes
|
394
394
|
end
|
395
395
|
|
396
396
|
##
|
@@ -428,7 +428,7 @@ module Oga
|
|
428
428
|
end
|
429
429
|
end
|
430
430
|
|
431
|
-
|
431
|
+
nodes
|
432
432
|
end
|
433
433
|
|
434
434
|
##
|
@@ -449,7 +449,7 @@ module Oga
|
|
449
449
|
nodes << parent if node_matches?(parent, ast_node)
|
450
450
|
end
|
451
451
|
|
452
|
-
|
452
|
+
nodes
|
453
453
|
end
|
454
454
|
|
455
455
|
##
|
@@ -476,7 +476,7 @@ module Oga
|
|
476
476
|
end
|
477
477
|
end
|
478
478
|
|
479
|
-
|
479
|
+
nodes
|
480
480
|
end
|
481
481
|
|
482
482
|
##
|
@@ -504,7 +504,7 @@ module Oga
|
|
504
504
|
end
|
505
505
|
end
|
506
506
|
|
507
|
-
|
507
|
+
nodes
|
508
508
|
end
|
509
509
|
|
510
510
|
##
|
@@ -521,7 +521,7 @@ module Oga
|
|
521
521
|
nodes << context_node if node_matches?(context_node, ast_node)
|
522
522
|
end
|
523
523
|
|
524
|
-
|
524
|
+
nodes
|
525
525
|
end
|
526
526
|
|
527
527
|
##
|
@@ -545,7 +545,7 @@ module Oga
|
|
545
545
|
end
|
546
546
|
end
|
547
547
|
|
548
|
-
|
548
|
+
nodes
|
549
549
|
end
|
550
550
|
|
551
551
|
##
|
@@ -560,7 +560,7 @@ module Oga
|
|
560
560
|
|
561
561
|
handler = name.gsub('-', '_')
|
562
562
|
|
563
|
-
|
563
|
+
send("on_type_test_#{handler}", test, context)
|
564
564
|
end
|
565
565
|
|
566
566
|
##
|
@@ -579,7 +579,7 @@ module Oga
|
|
579
579
|
end
|
580
580
|
end
|
581
581
|
|
582
|
-
|
582
|
+
nodes
|
583
583
|
end
|
584
584
|
|
585
585
|
##
|
@@ -596,7 +596,7 @@ module Oga
|
|
596
596
|
nodes << node if node.is_a?(XML::Text)
|
597
597
|
end
|
598
598
|
|
599
|
-
|
599
|
+
nodes
|
600
600
|
end
|
601
601
|
|
602
602
|
##
|
@@ -613,7 +613,7 @@ module Oga
|
|
613
613
|
nodes << node if node.is_a?(XML::Comment)
|
614
614
|
end
|
615
615
|
|
616
|
-
|
616
|
+
nodes
|
617
617
|
end
|
618
618
|
|
619
619
|
##
|
@@ -631,7 +631,7 @@ module Oga
|
|
631
631
|
nodes << node if node.is_a?(XML::ProcessingInstruction)
|
632
632
|
end
|
633
633
|
|
634
|
-
|
634
|
+
nodes
|
635
635
|
end
|
636
636
|
|
637
637
|
##
|
@@ -645,7 +645,7 @@ module Oga
|
|
645
645
|
def on_pipe(ast_node, context)
|
646
646
|
left, right = *ast_node.children
|
647
647
|
|
648
|
-
|
648
|
+
process(left, context) + process(right, context)
|
649
649
|
end
|
650
650
|
|
651
651
|
##
|
@@ -662,7 +662,7 @@ module Oga
|
|
662
662
|
def on_and(ast_node, context)
|
663
663
|
left, right = *ast_node.children
|
664
664
|
|
665
|
-
|
665
|
+
on_call_boolean(context, left) && on_call_boolean(context, right)
|
666
666
|
end
|
667
667
|
|
668
668
|
##
|
@@ -679,7 +679,7 @@ module Oga
|
|
679
679
|
def on_or(ast_node, context)
|
680
680
|
left, right = *ast_node.children
|
681
681
|
|
682
|
-
|
682
|
+
on_call_boolean(context, left) || on_call_boolean(context, right)
|
683
683
|
end
|
684
684
|
|
685
685
|
##
|
@@ -695,7 +695,7 @@ module Oga
|
|
695
695
|
def on_add(ast_node, context)
|
696
696
|
left, right = *ast_node.children
|
697
697
|
|
698
|
-
|
698
|
+
on_call_number(context, left) + on_call_number(context, right)
|
699
699
|
end
|
700
700
|
|
701
701
|
##
|
@@ -711,7 +711,7 @@ module Oga
|
|
711
711
|
def on_div(ast_node, context)
|
712
712
|
left, right = *ast_node.children
|
713
713
|
|
714
|
-
|
714
|
+
on_call_number(context, left) / on_call_number(context, right)
|
715
715
|
end
|
716
716
|
|
717
717
|
##
|
@@ -727,7 +727,7 @@ module Oga
|
|
727
727
|
def on_mod(ast_node, context)
|
728
728
|
left, right = *ast_node.children
|
729
729
|
|
730
|
-
|
730
|
+
on_call_number(context, left) % on_call_number(context, right)
|
731
731
|
end
|
732
732
|
|
733
733
|
##
|
@@ -743,7 +743,7 @@ module Oga
|
|
743
743
|
def on_mul(ast_node, context)
|
744
744
|
left, right = *ast_node.children
|
745
745
|
|
746
|
-
|
746
|
+
on_call_number(context, left) * on_call_number(context, right)
|
747
747
|
end
|
748
748
|
|
749
749
|
##
|
@@ -759,7 +759,7 @@ module Oga
|
|
759
759
|
def on_sub(ast_node, context)
|
760
760
|
left, right = *ast_node.children
|
761
761
|
|
762
|
-
|
762
|
+
on_call_number(context, left) - on_call_number(context, right)
|
763
763
|
end
|
764
764
|
|
765
765
|
##
|
@@ -795,7 +795,7 @@ module Oga
|
|
795
795
|
right = to_string(right)
|
796
796
|
end
|
797
797
|
|
798
|
-
|
798
|
+
left == right
|
799
799
|
end
|
800
800
|
|
801
801
|
##
|
@@ -807,7 +807,7 @@ module Oga
|
|
807
807
|
# @see [#on_eq]
|
808
808
|
#
|
809
809
|
def on_neq(ast_node, context)
|
810
|
-
|
810
|
+
!on_eq(ast_node, context)
|
811
811
|
end
|
812
812
|
|
813
813
|
##
|
@@ -823,7 +823,7 @@ module Oga
|
|
823
823
|
def on_lt(ast_node, context)
|
824
824
|
left, right = *ast_node.children
|
825
825
|
|
826
|
-
|
826
|
+
on_call_number(context, left) < on_call_number(context, right)
|
827
827
|
end
|
828
828
|
|
829
829
|
##
|
@@ -839,7 +839,7 @@ module Oga
|
|
839
839
|
def on_gt(ast_node, context)
|
840
840
|
left, right = *ast_node.children
|
841
841
|
|
842
|
-
|
842
|
+
on_call_number(context, left) > on_call_number(context, right)
|
843
843
|
end
|
844
844
|
|
845
845
|
##
|
@@ -856,7 +856,7 @@ module Oga
|
|
856
856
|
def on_lte(ast_node, context)
|
857
857
|
left, right = *ast_node.children
|
858
858
|
|
859
|
-
|
859
|
+
on_call_number(context, left) <= on_call_number(context, right)
|
860
860
|
end
|
861
861
|
|
862
862
|
##
|
@@ -873,7 +873,7 @@ module Oga
|
|
873
873
|
def on_gte(ast_node, context)
|
874
874
|
left, right = *ast_node.children
|
875
875
|
|
876
|
-
|
876
|
+
on_call_number(context, left) >= on_call_number(context, right)
|
877
877
|
end
|
878
878
|
|
879
879
|
##
|
@@ -894,7 +894,7 @@ module Oga
|
|
894
894
|
|
895
895
|
handler = name.gsub('-', '_')
|
896
896
|
|
897
|
-
|
897
|
+
send("on_call_#{handler}", context, *args)
|
898
898
|
end
|
899
899
|
|
900
900
|
##
|
@@ -906,7 +906,7 @@ module Oga
|
|
906
906
|
#
|
907
907
|
def on_call_last(context)
|
908
908
|
# XPath uses indexes 1 to N instead of 0 to N.
|
909
|
-
|
909
|
+
current_node_set.length.to_f
|
910
910
|
end
|
911
911
|
|
912
912
|
##
|
@@ -919,7 +919,7 @@ module Oga
|
|
919
919
|
def on_call_position(context)
|
920
920
|
index = current_node_set.index(context.first) + 1
|
921
921
|
|
922
|
-
|
922
|
+
index.to_f
|
923
923
|
end
|
924
924
|
|
925
925
|
##
|
@@ -937,7 +937,7 @@ module Oga
|
|
937
937
|
raise TypeError, 'count() can only operate on NodeSet instances'
|
938
938
|
end
|
939
939
|
|
940
|
-
|
940
|
+
retval.length.to_f
|
941
941
|
end
|
942
942
|
|
943
943
|
##
|
@@ -977,7 +977,7 @@ module Oga
|
|
977
977
|
end
|
978
978
|
end
|
979
979
|
|
980
|
-
|
980
|
+
nodes
|
981
981
|
end
|
982
982
|
|
983
983
|
##
|
@@ -995,7 +995,7 @@ module Oga
|
|
995
995
|
def on_call_local_name(context, expression = nil)
|
996
996
|
node = function_node(context, expression)
|
997
997
|
|
998
|
-
|
998
|
+
node.respond_to?(:name) ? node.name : ''
|
999
999
|
end
|
1000
1000
|
|
1001
1001
|
##
|
@@ -1113,7 +1113,7 @@ module Oga
|
|
1113
1113
|
convert = context.first.text
|
1114
1114
|
end
|
1115
1115
|
|
1116
|
-
|
1116
|
+
to_float(convert)
|
1117
1117
|
end
|
1118
1118
|
|
1119
1119
|
##
|
@@ -1135,7 +1135,7 @@ module Oga
|
|
1135
1135
|
retval << on_call_string(context, arg)
|
1136
1136
|
end
|
1137
1137
|
|
1138
|
-
|
1138
|
+
retval
|
1139
1139
|
end
|
1140
1140
|
|
1141
1141
|
##
|
@@ -1157,7 +1157,7 @@ module Oga
|
|
1157
1157
|
needle_str = on_call_string(context, needle)
|
1158
1158
|
|
1159
1159
|
# https://github.com/jruby/jruby/issues/1923
|
1160
|
-
|
1160
|
+
needle_str.empty? || haystack_str.start_with?(needle_str)
|
1161
1161
|
end
|
1162
1162
|
|
1163
1163
|
##
|
@@ -1178,7 +1178,7 @@ module Oga
|
|
1178
1178
|
haystack_str = on_call_string(context, haystack)
|
1179
1179
|
needle_str = on_call_string(context, needle)
|
1180
1180
|
|
1181
|
-
|
1181
|
+
haystack_str.include?(needle_str)
|
1182
1182
|
end
|
1183
1183
|
|
1184
1184
|
##
|
@@ -1202,7 +1202,7 @@ module Oga
|
|
1202
1202
|
|
1203
1203
|
before, sep, after = haystack_str.partition(needle_str)
|
1204
1204
|
|
1205
|
-
|
1205
|
+
sep.empty? ? sep : before
|
1206
1206
|
end
|
1207
1207
|
|
1208
1208
|
##
|
@@ -1226,7 +1226,7 @@ module Oga
|
|
1226
1226
|
|
1227
1227
|
before, sep, after = haystack_str.partition(needle_str)
|
1228
1228
|
|
1229
|
-
|
1229
|
+
sep.empty? ? sep : after
|
1230
1230
|
end
|
1231
1231
|
|
1232
1232
|
##
|
@@ -1265,7 +1265,7 @@ module Oga
|
|
1265
1265
|
stop_index = -1
|
1266
1266
|
end
|
1267
1267
|
|
1268
|
-
|
1268
|
+
haystack_str[start_index..stop_index]
|
1269
1269
|
end
|
1270
1270
|
|
1271
1271
|
##
|
@@ -1281,7 +1281,7 @@ module Oga
|
|
1281
1281
|
# @return [Float]
|
1282
1282
|
#
|
1283
1283
|
def on_call_string_length(context, expression = nil)
|
1284
|
-
|
1284
|
+
on_call_string(context, expression).length.to_f
|
1285
1285
|
end
|
1286
1286
|
|
1287
1287
|
##
|
@@ -1301,7 +1301,7 @@ module Oga
|
|
1301
1301
|
def on_call_normalize_space(context, expression = nil)
|
1302
1302
|
str = on_call_string(context, expression)
|
1303
1303
|
|
1304
|
-
|
1304
|
+
str.strip.gsub(/\s+/, ' ')
|
1305
1305
|
end
|
1306
1306
|
|
1307
1307
|
##
|
@@ -1330,7 +1330,7 @@ module Oga
|
|
1330
1330
|
replaced = replaced.gsub(char, replace_with)
|
1331
1331
|
end
|
1332
1332
|
|
1333
|
-
|
1333
|
+
replaced
|
1334
1334
|
end
|
1335
1335
|
|
1336
1336
|
##
|
@@ -1360,7 +1360,7 @@ module Oga
|
|
1360
1360
|
bool = !retval.respond_to?(:empty?) || !retval.empty?
|
1361
1361
|
end
|
1362
1362
|
|
1363
|
-
|
1363
|
+
bool
|
1364
1364
|
end
|
1365
1365
|
|
1366
1366
|
##
|
@@ -1375,7 +1375,7 @@ module Oga
|
|
1375
1375
|
# @return [TrueClass|FalseClass]
|
1376
1376
|
#
|
1377
1377
|
def on_call_not(context, expression)
|
1378
|
-
|
1378
|
+
!on_call_boolean(context, expression)
|
1379
1379
|
end
|
1380
1380
|
|
1381
1381
|
##
|
@@ -1387,7 +1387,7 @@ module Oga
|
|
1387
1387
|
# @return [TrueClass]
|
1388
1388
|
#
|
1389
1389
|
def on_call_true(context)
|
1390
|
-
|
1390
|
+
true
|
1391
1391
|
end
|
1392
1392
|
|
1393
1393
|
##
|
@@ -1399,7 +1399,7 @@ module Oga
|
|
1399
1399
|
# @return [FalseClass]
|
1400
1400
|
#
|
1401
1401
|
def on_call_false(context)
|
1402
|
-
|
1402
|
+
false
|
1403
1403
|
end
|
1404
1404
|
|
1405
1405
|
##
|
@@ -1428,7 +1428,7 @@ module Oga
|
|
1428
1428
|
node = node.parent
|
1429
1429
|
end
|
1430
1430
|
|
1431
|
-
|
1431
|
+
false
|
1432
1432
|
end
|
1433
1433
|
|
1434
1434
|
##
|
@@ -1462,7 +1462,7 @@ module Oga
|
|
1462
1462
|
sum += node.text.to_f
|
1463
1463
|
end
|
1464
1464
|
|
1465
|
-
|
1465
|
+
sum
|
1466
1466
|
end
|
1467
1467
|
|
1468
1468
|
##
|
@@ -1478,7 +1478,7 @@ module Oga
|
|
1478
1478
|
def on_call_floor(context, expression)
|
1479
1479
|
number = on_call_number(context, expression)
|
1480
1480
|
|
1481
|
-
|
1481
|
+
number.nan? ? number : number.floor.to_f
|
1482
1482
|
end
|
1483
1483
|
|
1484
1484
|
##
|
@@ -1494,7 +1494,7 @@ module Oga
|
|
1494
1494
|
def on_call_ceiling(context, expression)
|
1495
1495
|
number = on_call_number(context, expression)
|
1496
1496
|
|
1497
|
-
|
1497
|
+
number.nan? ? number : number.ceil.to_f
|
1498
1498
|
end
|
1499
1499
|
|
1500
1500
|
##
|
@@ -1510,7 +1510,7 @@ module Oga
|
|
1510
1510
|
def on_call_round(context, expression)
|
1511
1511
|
number = on_call_number(context, expression)
|
1512
1512
|
|
1513
|
-
|
1513
|
+
number.nan? ? number : number.round.to_f
|
1514
1514
|
end
|
1515
1515
|
|
1516
1516
|
##
|
@@ -1521,7 +1521,7 @@ module Oga
|
|
1521
1521
|
# @return [Float]
|
1522
1522
|
#
|
1523
1523
|
def on_int(ast_node, context)
|
1524
|
-
|
1524
|
+
ast_node.children[0].to_f
|
1525
1525
|
end
|
1526
1526
|
|
1527
1527
|
##
|
@@ -1532,7 +1532,7 @@ module Oga
|
|
1532
1532
|
# @return [Float]
|
1533
1533
|
#
|
1534
1534
|
def on_float(ast_node, context)
|
1535
|
-
|
1535
|
+
ast_node.children[0]
|
1536
1536
|
end
|
1537
1537
|
|
1538
1538
|
##
|
@@ -1543,7 +1543,7 @@ module Oga
|
|
1543
1543
|
# @return [String]
|
1544
1544
|
#
|
1545
1545
|
def on_string(ast_node, context)
|
1546
|
-
|
1546
|
+
ast_node.children[0]
|
1547
1547
|
end
|
1548
1548
|
|
1549
1549
|
##
|
@@ -1586,7 +1586,7 @@ module Oga
|
|
1586
1586
|
node = context.first
|
1587
1587
|
end
|
1588
1588
|
|
1589
|
-
|
1589
|
+
node
|
1590
1590
|
end
|
1591
1591
|
|
1592
1592
|
##
|
@@ -1597,7 +1597,7 @@ module Oga
|
|
1597
1597
|
# @return [String]
|
1598
1598
|
#
|
1599
1599
|
def first_node_text(set)
|
1600
|
-
|
1600
|
+
set[0].respond_to?(:text) ? set[0].text : ''
|
1601
1601
|
end
|
1602
1602
|
|
1603
1603
|
##
|
@@ -1614,7 +1614,7 @@ module Oga
|
|
1614
1614
|
children.concat(xml_node.children)
|
1615
1615
|
end
|
1616
1616
|
|
1617
|
-
|
1617
|
+
children
|
1618
1618
|
end
|
1619
1619
|
|
1620
1620
|
##
|
@@ -1667,7 +1667,7 @@ module Oga
|
|
1667
1667
|
xml_node.default_namespace?
|
1668
1668
|
end
|
1669
1669
|
|
1670
|
-
|
1670
|
+
name_matches && ns_matches
|
1671
1671
|
end
|
1672
1672
|
|
1673
1673
|
##
|
@@ -1678,7 +1678,7 @@ module Oga
|
|
1678
1678
|
def type_matches?(xml_node, ast_node)
|
1679
1679
|
context = XML::NodeSet.new([xml_node])
|
1680
1680
|
|
1681
|
-
|
1681
|
+
process(ast_node, context).length > 0
|
1682
1682
|
end
|
1683
1683
|
|
1684
1684
|
##
|
@@ -1691,7 +1691,7 @@ module Oga
|
|
1691
1691
|
def name_matches?(xml_node, name)
|
1692
1692
|
return false unless xml_node.respond_to?(:name)
|
1693
1693
|
|
1694
|
-
|
1694
|
+
name == STAR ? true : xml_node.name == name
|
1695
1695
|
end
|
1696
1696
|
|
1697
1697
|
##
|
@@ -1706,7 +1706,7 @@ module Oga
|
|
1706
1706
|
|
1707
1707
|
return true if ns == STAR
|
1708
1708
|
|
1709
|
-
|
1709
|
+
xml_node.namespace && xml_node.namespace.name == ns
|
1710
1710
|
end
|
1711
1711
|
|
1712
1712
|
##
|
@@ -1714,7 +1714,7 @@ module Oga
|
|
1714
1714
|
# @return [TrueClass|FalseClass]
|
1715
1715
|
#
|
1716
1716
|
def has_parent?(ast_node)
|
1717
|
-
|
1717
|
+
ast_node.respond_to?(:parent) && !!ast_node.parent
|
1718
1718
|
end
|
1719
1719
|
|
1720
1720
|
##
|
@@ -1743,7 +1743,7 @@ module Oga
|
|
1743
1743
|
value = value.to_i
|
1744
1744
|
end
|
1745
1745
|
|
1746
|
-
|
1746
|
+
value.to_s
|
1747
1747
|
end
|
1748
1748
|
|
1749
1749
|
##
|
@@ -1764,14 +1764,14 @@ module Oga
|
|
1764
1764
|
|
1765
1765
|
@node_sets.pop
|
1766
1766
|
|
1767
|
-
|
1767
|
+
retval
|
1768
1768
|
end
|
1769
1769
|
|
1770
1770
|
##
|
1771
1771
|
# @return [Oga::XML::NodeSet]
|
1772
1772
|
#
|
1773
1773
|
def current_node_set
|
1774
|
-
|
1774
|
+
@node_sets.last
|
1775
1775
|
end
|
1776
1776
|
|
1777
1777
|
##
|
@@ -1781,7 +1781,7 @@ module Oga
|
|
1781
1781
|
# @return [Oga::XML::Node|Oga::XML::Document]
|
1782
1782
|
#
|
1783
1783
|
def root_node(node)
|
1784
|
-
|
1784
|
+
node.respond_to?(:root_node) ? node.root_node : node
|
1785
1785
|
end
|
1786
1786
|
|
1787
1787
|
##
|
@@ -1791,7 +1791,7 @@ module Oga
|
|
1791
1791
|
# @return [Oga::XML::Node|Oga::XML::Document]
|
1792
1792
|
#
|
1793
1793
|
def parent_node(node)
|
1794
|
-
|
1794
|
+
node.respond_to?(:parent) ? node.parent : node
|
1795
1795
|
end
|
1796
1796
|
end # Evaluator
|
1797
1797
|
end # XPath
|