meteor 0.9.30 → 0.9.31
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/ChangeLog +4 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +34 -3
- data/demo/html.rb +32 -38
- data/demo/html4.rb +27 -33
- data/demo/xhtml.rb +27 -33
- data/demo/xhtml4.rb +25 -31
- data/demo/xml.rb +20 -20
- data/lib/meteor/attribute.rb +1 -4
- data/lib/meteor/attribute_map.rb +15 -16
- data/lib/meteor/core/kernel.rb +482 -605
- data/lib/meteor/core/util/file_reader.rb +37 -0
- data/lib/meteor/core/util/pattern_cache.rb +1 -1
- data/lib/meteor/element.rb +38 -57
- data/lib/meteor/elements.rb +6 -6
- data/lib/meteor/ml/html/parser_impl.rb +57 -59
- data/lib/meteor/ml/html4/parser_impl.rb +87 -102
- data/lib/meteor/ml/xhtml/parser_impl.rb +32 -34
- data/lib/meteor/ml/xhtml4/parser_impl.rb +72 -74
- data/lib/meteor/ml/xml/parser_impl.rb +23 -23
- data/lib/meteor/parsers.rb +54 -62
- data/lib/meteor/root_element.rb +5 -8
- data/lib/meteor.rb +62 -61
- data/meteor.gemspec +14 -13
- data/test/meteor_test.rb +4 -2
- data/test/test_helper.rb +3 -2
- metadata +4 -4
- data/Rakefile +0 -144
data/lib/meteor/core/kernel.rb
CHANGED
|
@@ -17,23 +17,23 @@ module Meteor
|
|
|
17
17
|
class Kernel < Meteor::Parser
|
|
18
18
|
# find
|
|
19
19
|
# E
|
|
20
|
-
PATTERN_FIND_1 =
|
|
20
|
+
PATTERN_FIND_1 = '^([^,\\[\\]#\\.]+)$'
|
|
21
21
|
# # id_attribute_value
|
|
22
|
-
PATTERN_FIND_2_1 =
|
|
22
|
+
PATTERN_FIND_2_1 = '^#([^\\.,\\[\\]#][^,\\[\\]#]*)$'
|
|
23
23
|
# .class_attribute_value
|
|
24
|
-
PATTERN_FIND_2_2 =
|
|
24
|
+
PATTERN_FIND_2_2 = '^\\.([^\\.,\\[\\]#][^,\\[\\]#]*)$'
|
|
25
25
|
# [attribute_name=attribute_value]
|
|
26
|
-
PATTERN_FIND_2_3 =
|
|
26
|
+
PATTERN_FIND_2_3 = '^\\[([^\\[\\],]+)=([^\\[\\],]+)\\]$'
|
|
27
27
|
# E[attribute_name=attribute_value]
|
|
28
|
-
PATTERN_FIND_3_1 =
|
|
28
|
+
PATTERN_FIND_3_1 = '^([^\\.,\\[\\]#][^,\\[\\]#]+)\\[([^,\\[\\]]+)=([^,\\[\\]]+)\\]$'
|
|
29
29
|
# E# id_attribute_value
|
|
30
|
-
PATTERN_FIND_3_2 =
|
|
30
|
+
PATTERN_FIND_3_2 = '^([^\\.,\\[\\]#][^,\\[\\]#]+)#([^\\.,\\[\\]#][^,\\[\\]#]*)$'
|
|
31
31
|
# E.class_attribute_value
|
|
32
|
-
PATTERN_FIND_3_3 =
|
|
32
|
+
PATTERN_FIND_3_3 = '^([^\\.,\\[\\]#][^,\\[\\]#]+)\\.([^\\.,\\[\\]#][^,\\[\\]#]*)$'
|
|
33
33
|
# [attribute_name1=attribute_value1][attribute_name2=attribute_value2]
|
|
34
|
-
PATTERN_FIND_4 =
|
|
34
|
+
PATTERN_FIND_4 = '^\\[([^,]+)=([^,]+)\\]\\[([^,]+)=([^,]+)\\]$'
|
|
35
35
|
# E[attribute_name1=attribute_value1][attribute_name2=attribute_value2]
|
|
36
|
-
PATTERN_FIND_5 =
|
|
36
|
+
PATTERN_FIND_5 = '^([^\\.,\\[\\]#][^,\\[\\]#]+)\\[([^,]+)=([^,]+)\\]\\[([^,]+)=([^,]+)\\]$'
|
|
37
37
|
|
|
38
38
|
@@pattern_find_1 = Regexp.new(PATTERN_FIND_1)
|
|
39
39
|
@@pattern_find_2_1 = Regexp.new(PATTERN_FIND_2_1)
|
|
@@ -45,50 +45,47 @@ module Meteor
|
|
|
45
45
|
@@pattern_find_4 = Regexp.new(PATTERN_FIND_4)
|
|
46
46
|
@@pattern_find_5 = Regexp.new(PATTERN_FIND_5)
|
|
47
47
|
|
|
48
|
-
@@pattern_set_mono1 = Regexp.new(
|
|
48
|
+
@@pattern_set_mono1 = Regexp.new('\\A[^<>]*\\Z')
|
|
49
49
|
|
|
50
|
-
@@pattern_get_attrs_map = Regexp.new(
|
|
50
|
+
@@pattern_get_attrs_map = Regexp.new('([^\\s]*)="([^\"]*)"')
|
|
51
51
|
|
|
52
|
-
@@pattern_clean1 = Regexp.new(
|
|
53
|
-
@@pattern_clean2 = Regexp.new(
|
|
52
|
+
@@pattern_clean1 = Regexp.new('<!--\\s@[^<>]*\\s[^<>]*(\\s)*-->')
|
|
53
|
+
@@pattern_clean2 = Regexp.new('<!--\\s\\/@[^<>]*(\\s)*-->')
|
|
54
54
|
|
|
55
|
-
BR =
|
|
55
|
+
BR = '<br>'
|
|
56
56
|
BR_RE = BR
|
|
57
57
|
|
|
58
58
|
TABLE_FOR_ESCAPE_ = {
|
|
59
|
-
|
|
60
|
-
"
|
|
61
|
-
"'" =>
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
59
|
+
'&' => '&',
|
|
60
|
+
'"' => '"',
|
|
61
|
+
"'" => ''',
|
|
62
|
+
'<' => '<',
|
|
63
|
+
'>' => '>',
|
|
64
|
+
' ' => ' '
|
|
65
|
+
}.freeze
|
|
66
66
|
|
|
67
67
|
TABLE_FOR_ESCAPE_CONTENT_ = {
|
|
68
|
-
|
|
69
|
-
"
|
|
70
|
-
"'" =>
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
'&' => '&',
|
|
69
|
+
'"' => '"',
|
|
70
|
+
"'" => ''',
|
|
71
|
+
'<' => '<',
|
|
72
|
+
'>' => '>',
|
|
73
|
+
' ' => ' ',
|
|
74
74
|
"\r\n" => BR,
|
|
75
75
|
"\r" => BR,
|
|
76
76
|
"\n" => BR
|
|
77
|
-
}
|
|
77
|
+
}.freeze
|
|
78
78
|
|
|
79
79
|
PATTERN_ESCAPE = "[&\"'<> ]"
|
|
80
80
|
PATTERN_ESCAPE_CONTENT = "[&\"'<> \\n]"
|
|
81
81
|
@@pattern_escape = Regexp.new(PATTERN_ESCAPE)
|
|
82
82
|
@@pattern_escape_content = Regexp.new(PATTERN_ESCAPE_CONTENT)
|
|
83
83
|
|
|
84
|
-
PATTERN_UNESCAPE =
|
|
84
|
+
PATTERN_UNESCAPE = '&(amp|quot|apos|gt|lt|nbsp);'
|
|
85
85
|
@@pattern_unescape = Regexp.new(PATTERN_UNESCAPE)
|
|
86
86
|
@@pattern_br_2 = Regexp.new(BR_RE)
|
|
87
87
|
|
|
88
|
-
attr_accessor :element_cache
|
|
89
|
-
attr_accessor :doc_type
|
|
90
|
-
attr_accessor :document_hook
|
|
91
|
-
attr_accessor :element_hook
|
|
88
|
+
attr_accessor :element_cache, :doc_type, :document_hook, :element_hook
|
|
92
89
|
|
|
93
90
|
#
|
|
94
91
|
# set document (ドキュメントをセットする)
|
|
@@ -97,6 +94,8 @@ module Meteor
|
|
|
97
94
|
#
|
|
98
95
|
def document=(doc)
|
|
99
96
|
@root.document = doc
|
|
97
|
+
|
|
98
|
+
parse
|
|
100
99
|
end
|
|
101
100
|
|
|
102
101
|
#
|
|
@@ -115,7 +114,7 @@ module Meteor
|
|
|
115
114
|
@root.enc = enc
|
|
116
115
|
end
|
|
117
116
|
|
|
118
|
-
|
|
117
|
+
alias character_encoding= enc=
|
|
119
118
|
|
|
120
119
|
#
|
|
121
120
|
# get character encoding (文字エンコーディングを取得する)
|
|
@@ -125,7 +124,7 @@ module Meteor
|
|
|
125
124
|
@root.enc
|
|
126
125
|
end
|
|
127
126
|
|
|
128
|
-
|
|
127
|
+
alias character_encoding enc
|
|
129
128
|
|
|
130
129
|
#
|
|
131
130
|
# get root element (ルート要素を取得する)
|
|
@@ -148,9 +147,9 @@ module Meteor
|
|
|
148
147
|
@root = RootElement.new
|
|
149
148
|
@root.parser = self
|
|
150
149
|
# element cache (要素キャッシュ)
|
|
151
|
-
@element_cache =
|
|
150
|
+
@element_cache = {}
|
|
152
151
|
# document hook (フック・ドキュメント)
|
|
153
|
-
@document_hook = String.new(
|
|
152
|
+
@document_hook = String.new('')
|
|
154
153
|
|
|
155
154
|
@error_check = true
|
|
156
155
|
end
|
|
@@ -161,35 +160,20 @@ module Meteor
|
|
|
161
160
|
# @param [String] enc character encoding of input file (入力ファイルの文字コード)
|
|
162
161
|
#
|
|
163
162
|
def read(file_path, enc)
|
|
164
|
-
# try {
|
|
165
163
|
self.enc = enc
|
|
166
|
-
mode = if enc == "UTF-8"
|
|
167
|
-
# String.new("") << "r:" << enc
|
|
168
|
-
"r:UTF-8"
|
|
169
|
-
else
|
|
170
|
-
String.new("") << "r:" << enc << ":utf-8"
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
# open file (ファイルのオープン)
|
|
174
|
-
io = File.open(file_path, mode)
|
|
175
164
|
|
|
176
|
-
|
|
177
|
-
@root.document = io.read
|
|
165
|
+
self.document = Meteor::Core::Util::FileReader.read(file_path, enc)
|
|
178
166
|
|
|
179
|
-
|
|
180
|
-
io.close
|
|
181
|
-
|
|
182
|
-
parse
|
|
183
|
-
|
|
184
|
-
return @root.document
|
|
167
|
+
@root.document
|
|
185
168
|
end
|
|
186
169
|
|
|
187
170
|
#
|
|
188
171
|
# psrse document (ドキュメントを解析する)
|
|
189
172
|
# @param [String] document document (ドキュメント)
|
|
190
173
|
#
|
|
191
|
-
def parse
|
|
192
|
-
|
|
174
|
+
def parse; end
|
|
175
|
+
|
|
176
|
+
protected :parse
|
|
193
177
|
|
|
194
178
|
#
|
|
195
179
|
# get element (要素を取得する)
|
|
@@ -239,68 +223,51 @@ module Meteor
|
|
|
239
223
|
#
|
|
240
224
|
def element(elm, attrs = nil, *args)
|
|
241
225
|
if !attrs
|
|
242
|
-
|
|
226
|
+
case elm
|
|
227
|
+
when String, Symbol
|
|
243
228
|
element_1(elm.to_s)
|
|
244
|
-
if @elm_
|
|
245
|
-
|
|
246
|
-
end
|
|
247
|
-
elsif elm.kind_of?(Meteor::Element)
|
|
229
|
+
@element_cache.store(@elm_.object_id, @elm_) if @elm_
|
|
230
|
+
when Meteor::Element
|
|
248
231
|
shadow(elm)
|
|
249
|
-
|
|
232
|
+
when Hash
|
|
250
233
|
if elm.size == ONE
|
|
251
234
|
element_2(elm.keys[0].to_s, elm.values[0])
|
|
252
|
-
if @elm_
|
|
253
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
|
254
|
-
end
|
|
235
|
+
@element_cache.store(@elm_.object_id, @elm_) if @elm_
|
|
255
236
|
elsif elm.size == TWO
|
|
256
237
|
element_4(elm.keys[0].to_s, elm.values[0], elm.keys[1].to_s, elm.values[1])
|
|
257
|
-
if @elm_
|
|
258
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
|
259
|
-
end
|
|
238
|
+
@element_cache.store(@elm_.object_id, @elm_) if @elm_
|
|
260
239
|
else
|
|
261
240
|
raise ArgumentError
|
|
262
241
|
end
|
|
263
242
|
else
|
|
264
243
|
raise ArgumentError
|
|
265
244
|
end
|
|
266
|
-
elsif attrs.
|
|
245
|
+
elsif attrs.is_a?(Hash)
|
|
267
246
|
if attrs.size == ONE
|
|
268
247
|
element_3(elm.to_s, attrs.keys[0].to_s, attrs.values[0])
|
|
269
|
-
if @elm_
|
|
270
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
|
271
|
-
end
|
|
248
|
+
@element_cache.store(@elm_.object_id, @elm_) if @elm_
|
|
272
249
|
elsif attrs.size == TWO
|
|
273
250
|
element_5(elm.to_s, attrs.keys[0].to_s, attrs.values[0], attrs.keys[1].to_s, attrs.values[1])
|
|
274
|
-
if @elm_
|
|
275
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
|
276
|
-
end
|
|
251
|
+
@element_cache.store(@elm_.object_id, @elm_) if @elm_
|
|
277
252
|
else
|
|
278
253
|
@elm_ = nil
|
|
279
254
|
raise ArgumentError
|
|
280
255
|
end
|
|
281
|
-
elsif attrs.
|
|
256
|
+
elsif attrs.is_a?(String) || attrs.is_a?(Symbol)
|
|
282
257
|
case args.length
|
|
283
258
|
when ZERO
|
|
284
259
|
element_2(elm.to_s, attrs.to_s)
|
|
285
|
-
if @elm_
|
|
286
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
|
287
|
-
end
|
|
260
|
+
@element_cache.store(@elm_.object_id, @elm_) if @elm_
|
|
288
261
|
|
|
289
262
|
when ONE
|
|
290
263
|
element_3(elm.to_s, attrs.to_s, args[0])
|
|
291
|
-
if @elm_
|
|
292
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
|
293
|
-
end
|
|
264
|
+
@element_cache.store(@elm_.object_id, @elm_) if @elm_
|
|
294
265
|
when TWO
|
|
295
266
|
element_4(elm.to_s, attrs.to_s, args[0].to_s, args[1])
|
|
296
|
-
if @elm_
|
|
297
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
|
298
|
-
end
|
|
267
|
+
@element_cache.store(@elm_.object_id, @elm_) if @elm_
|
|
299
268
|
when THREE
|
|
300
269
|
element_5(elm.to_s, attrs.to_s, args[0], args[1].to_s, args[2])
|
|
301
|
-
if @elm_
|
|
302
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
|
303
|
-
end
|
|
270
|
+
@element_cache.store(@elm_.object_id, @elm_) if @elm_
|
|
304
271
|
else
|
|
305
272
|
@elm_ = nil
|
|
306
273
|
raise ArgumentError
|
|
@@ -344,24 +311,23 @@ module Meteor
|
|
|
344
311
|
def element_normal_1(name)
|
|
345
312
|
@elm_ = Meteor::Element.new(name)
|
|
346
313
|
|
|
347
|
-
|
|
348
|
-
# puts '--on_search=
|
|
349
|
-
# puts @res.to_a
|
|
314
|
+
if @on_search
|
|
315
|
+
# puts '--on_search=true'
|
|
350
316
|
# attribute (属性)
|
|
351
|
-
@elm_.attributes = @res[
|
|
317
|
+
@elm_.attributes = @res[1]
|
|
352
318
|
# content (内容)
|
|
353
|
-
@elm_.mixed_content = @res[
|
|
319
|
+
@elm_.mixed_content = @res[2]
|
|
354
320
|
# document (全体)
|
|
355
|
-
@elm_.document = @res[0]
|
|
356
321
|
else
|
|
357
|
-
# puts '--on_search=
|
|
322
|
+
# puts '--on_search=false'
|
|
323
|
+
# puts @res.to_a
|
|
358
324
|
# attribute (属性)
|
|
359
|
-
@elm_.attributes = @res[
|
|
325
|
+
@elm_.attributes = @res[2]
|
|
360
326
|
# content (内容)
|
|
361
|
-
@elm_.mixed_content = @res[
|
|
327
|
+
@elm_.mixed_content = @res[3]
|
|
362
328
|
# document (全体)
|
|
363
|
-
@elm_.document = @res[0]
|
|
364
329
|
end
|
|
330
|
+
@elm_.document = @res[0]
|
|
365
331
|
# normal element search pattern (内容あり要素検索用パターン)
|
|
366
332
|
# @pattern_cc = String.new('') << "<" << @_name << '(?:|\\s[^<>]*)>((?!(' << @_name
|
|
367
333
|
# @pattern_cc << '[^<>]*>)).)*<\\/' << @_name << '>'
|
|
@@ -384,7 +350,7 @@ module Meteor
|
|
|
384
350
|
# document (全体)
|
|
385
351
|
@elm_.document = @res[0]
|
|
386
352
|
# void element search pattern (空要素検索用パターン)
|
|
387
|
-
@pattern_cc = String.new(
|
|
353
|
+
@pattern_cc = String.new('') << '<' << @_name << '(|\\s[^<>]*)\\/>'
|
|
388
354
|
# @pattern_cc = "<#{@_name}(|\\s[^<>]*)\\/>"
|
|
389
355
|
@elm_.pattern = @pattern_cc
|
|
390
356
|
|
|
@@ -451,9 +417,7 @@ module Meteor
|
|
|
451
417
|
# @pattern_cc = @pattern_cc_2
|
|
452
418
|
element_normal_3_1(name)
|
|
453
419
|
else
|
|
454
|
-
if @error_check
|
|
455
|
-
puts(Meteor::Exception::NoSuchElementException.new(name, attr_name, attr_value).message)
|
|
456
|
-
end
|
|
420
|
+
puts(Meteor::Exception::NoSuchElementException.new(name, attr_name, attr_value).message) if @error_check
|
|
457
421
|
|
|
458
422
|
@elm_ = nil
|
|
459
423
|
end
|
|
@@ -523,17 +487,15 @@ module Meteor
|
|
|
523
487
|
when THREE, SIX
|
|
524
488
|
# element (要素)
|
|
525
489
|
@elm_ = Meteor::Element.new(name)
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
@elm_.mixed_content = @res[3]
|
|
490
|
+
@elm_.attributes = @res[1].chop
|
|
491
|
+
if @on_search
|
|
492
|
+
# attribute (属性)
|
|
493
|
+
# content (内容)
|
|
531
494
|
else
|
|
532
495
|
# attribute (属性)
|
|
533
|
-
@elm_.attributes = @res[1].chop
|
|
534
496
|
# content (内容)
|
|
535
|
-
@elm_.mixed_content = @res[3]
|
|
536
497
|
end
|
|
498
|
+
@elm_.mixed_content = @res[3]
|
|
537
499
|
# document (全体)
|
|
538
500
|
@elm_.document = @res[0]
|
|
539
501
|
# normal element search pattern (内容あり要素検索用パターン)
|
|
@@ -552,9 +514,7 @@ module Meteor
|
|
|
552
514
|
def element_normal_3_2
|
|
553
515
|
element_pattern_normal_3_2
|
|
554
516
|
|
|
555
|
-
if @sbuf.length == ZERO || @cnt != ZERO
|
|
556
|
-
return nil
|
|
557
|
-
end
|
|
517
|
+
return nil if @sbuf.length == ZERO || @cnt != ZERO
|
|
558
518
|
|
|
559
519
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
|
560
520
|
@res = @pattern.match(@root.document)
|
|
@@ -568,25 +528,25 @@ module Meteor
|
|
|
568
528
|
# @pattern_cc_1 = String.new('') << "<" << @_name << '(\\s[^<>]*' << @_attr_name << '="'
|
|
569
529
|
# @pattern_cc_1 << @_attr_value << '(?:[^<>\\/]*>|(?:(?!([^<>]*\\/>))[^<>]*>)))'
|
|
570
530
|
@pattern_cc_1 = "<#{@_name}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}(?:[^<>\\/]*>|(?:(?!([^<>]*\\/>))[^<>]*>)))"
|
|
571
|
-
@pattern_cc_1b = String.new(
|
|
531
|
+
@pattern_cc_1b = String.new('') << '<' << @_name << '(\\s[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))'
|
|
572
532
|
# @pattern_cc_1b = "<#{@_name}(\\s[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))"
|
|
573
533
|
# @pattern_cc_1_1 = String.new('') << "<" << @_name << '(\\s[^<>]*' << @_attr_name << '="'
|
|
574
534
|
# @pattern_cc_1_1 << @_attr_value << '"(?:[^<>\\/]*>|(?!([^<>]*\\/>))[^<>]*>))('
|
|
575
535
|
@pattern_cc_1_1 = "<#{@_name}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"(?:[^<>\\/]*>|(?!([^<>]*\\/>))[^<>]*>))("
|
|
576
|
-
@pattern_cc_1_2 = String.new(
|
|
536
|
+
@pattern_cc_1_2 = String.new('') << '.*?<' << @_name << '(\\s[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))'
|
|
577
537
|
# @pattern_cc_1_2 = ".*?<#{@_name}(\\s[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))"
|
|
578
538
|
|
|
579
|
-
@pattern_cc_2 = String.new(
|
|
539
|
+
@pattern_cc_2 = String.new('') << '<\\/' << @_name << '>'
|
|
580
540
|
# @pattern_cc_2 = String.new('') << "<\\/#{@_name}>"
|
|
581
|
-
@pattern_cc_2_1 = String.new(
|
|
541
|
+
@pattern_cc_2_1 = String.new('') << '.*?<\\/' << @_name << '>'
|
|
582
542
|
# @pattern_cc_2_1 = ".*?<\\/#{@_name}>"
|
|
583
|
-
@pattern_cc_2_2 = String.new(
|
|
543
|
+
@pattern_cc_2_2 = String.new('') << '.*?)<\\/' << @_name << '>'
|
|
584
544
|
# @pattern_cc_2_2 = ".*?)<\\/#{@_name}>"
|
|
585
545
|
|
|
586
546
|
# search of normal element (内容あり要素検索)
|
|
587
547
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc_1)
|
|
588
548
|
|
|
589
|
-
@sbuf = String.new(
|
|
549
|
+
@sbuf = String.new('')
|
|
590
550
|
|
|
591
551
|
@pattern_2 = Meteor::Core::Util::PatternCache.get(@pattern_cc_2)
|
|
592
552
|
@pattern_1b = Meteor::Core::Util::PatternCache.get(@pattern_cc_1b)
|
|
@@ -601,7 +561,7 @@ module Meteor
|
|
|
601
561
|
private :element_pattern_normal_3_2
|
|
602
562
|
|
|
603
563
|
def element_void_3(name)
|
|
604
|
-
element_void_3_1(name, "
|
|
564
|
+
element_void_3_1(name, '"[^<>]*)\\/>')
|
|
605
565
|
end
|
|
606
566
|
|
|
607
567
|
private :element_void_3
|
|
@@ -641,60 +601,56 @@ module Meteor
|
|
|
641
601
|
if @res
|
|
642
602
|
element_3(@res[1], attr_name, attr_value)
|
|
643
603
|
else
|
|
644
|
-
if @error_check
|
|
645
|
-
puts(Meteor::Exception::NoSuchElementException.new(attr_name, attr_value).message)
|
|
646
|
-
end
|
|
604
|
+
puts(Meteor::Exception::NoSuchElementException.new(attr_name, attr_value).message) if @error_check
|
|
647
605
|
|
|
648
606
|
@elm_ = nil
|
|
649
607
|
end
|
|
650
608
|
|
|
651
|
-
=
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
@
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
if @res1
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
end
|
|
697
|
-
=end
|
|
609
|
+
# @pattern_cc_1 = "<([^<>\"]*)(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*)\\/>|<([^<>\"]*)(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*)>(((?!(\\3[^<>]*>)).)*)<\\/\\3>"
|
|
610
|
+
#
|
|
611
|
+
# @pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc_1)
|
|
612
|
+
# @res1 = @pattern.match(@root.document)
|
|
613
|
+
#
|
|
614
|
+
# if @res1 && @res1[1] || !@res1
|
|
615
|
+
# @res2 = element_normal_2_2
|
|
616
|
+
# @pattern_cc_2 = @pattern_cc
|
|
617
|
+
#
|
|
618
|
+
# # puts @res2.captures.length
|
|
619
|
+
# # puts @res2.regexp.to_s
|
|
620
|
+
# end
|
|
621
|
+
#
|
|
622
|
+
# if @res1 && @res2
|
|
623
|
+
# if @res1.begin(0) < @res2.begin(0)
|
|
624
|
+
# @res = @res1
|
|
625
|
+
# # @pattern_cc = @pattern_cc_1
|
|
626
|
+
# if @res[1]
|
|
627
|
+
# element_void_2
|
|
628
|
+
# else
|
|
629
|
+
# element_normal_2_1
|
|
630
|
+
# end
|
|
631
|
+
# elsif @res1.begin(0) > @res2.begin(0)
|
|
632
|
+
# @res = @res2
|
|
633
|
+
# # @pattern_cc = @pattern_cc_2
|
|
634
|
+
# element_normal_2_1
|
|
635
|
+
# end
|
|
636
|
+
# elsif @res1 && !@res2
|
|
637
|
+
# @res = @res1
|
|
638
|
+
# # @pattern_cc = @pattern_cc_1
|
|
639
|
+
# if @res[1]
|
|
640
|
+
# element_void_2
|
|
641
|
+
# else
|
|
642
|
+
# element_normal_2_1
|
|
643
|
+
# end
|
|
644
|
+
# elsif @res2 && !@res1
|
|
645
|
+
# @res = @res2
|
|
646
|
+
# # @pattern_cc = @pattern_cc_2
|
|
647
|
+
# element_normal_2_1
|
|
648
|
+
# else
|
|
649
|
+
# if @error_check
|
|
650
|
+
# puts Meteor::Exception::NoSuchElementException.new(attr_name, attr_value).message
|
|
651
|
+
# end
|
|
652
|
+
# @elm_ = nil
|
|
653
|
+
# end
|
|
698
654
|
|
|
699
655
|
@elm_
|
|
700
656
|
end
|
|
@@ -722,134 +678,132 @@ module Meteor
|
|
|
722
678
|
|
|
723
679
|
private :element_pattern_2
|
|
724
680
|
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
private :element_void_2_1
|
|
852
|
-
=end
|
|
681
|
+
# def element_normal_2_1
|
|
682
|
+
# # puts @res.captures.length
|
|
683
|
+
# case @res.captures.length
|
|
684
|
+
# when FOUR
|
|
685
|
+
# @_name = @res[1]
|
|
686
|
+
# # eleement (要素)
|
|
687
|
+
# @elm_ = Element.new(@_name)
|
|
688
|
+
# # attribute (属性)
|
|
689
|
+
# @elm_.attributes = @res[2]
|
|
690
|
+
# # content (内容)
|
|
691
|
+
# @elm_.mixed_content = @res[3]
|
|
692
|
+
# # document (全体)
|
|
693
|
+
# @elm_.document = @res[0]
|
|
694
|
+
# # pattern (内容あり要素検索用パターン)
|
|
695
|
+
# # @pattern_cc = String.new('') << "<" << @_name << '\\s[^<>]*' << @_attr_name << '="'
|
|
696
|
+
# # @pattern_cc << @_attr_value << '"[^<>]*>((?!(' << @_name
|
|
697
|
+
# # @pattern_cc << '[^<>]*>)).)*<\\/' << @_name << '>'
|
|
698
|
+
# @ pattern_cc = "<#{@_name}\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*>((?!(#{@_name}[^<>]*>)).)*<\\/#{@_name}>"
|
|
699
|
+
#
|
|
700
|
+
# @elm_.pattern = @pattern_cc
|
|
701
|
+
# @elm_.normal = true
|
|
702
|
+
# @elm_.parser = self
|
|
703
|
+
# when FIVE,SEVEN
|
|
704
|
+
# @_name = @res[3]
|
|
705
|
+
# # element (要素)
|
|
706
|
+
# @elm_ = Element.new(@_name)
|
|
707
|
+
# # attribute (属性)
|
|
708
|
+
# @elm_.attributes = @res[4]
|
|
709
|
+
# # content (内容)
|
|
710
|
+
# @elm_.mixed_content = @res[5]
|
|
711
|
+
# # document (全体)
|
|
712
|
+
# @elm_.document = @res[0]
|
|
713
|
+
# # pattern (内容あり要素検索用パターン)
|
|
714
|
+
# # @pattern_cc = String.new()<< "<" << @_name << '\\s[^<>]*' << @_attr_name << '="'
|
|
715
|
+
# # @pattern_cc << @_attr_value << '"[^<>]*>((?!(' << @_name
|
|
716
|
+
# # @pattern_cc << '[^<>]*>)).)*<\\/' << @_name << '>'
|
|
717
|
+
# @pattern_cc = "<#{@_name}\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*>((?!(#{@_name}[^<>]*>)).)*<\\/#{@_name}>"
|
|
718
|
+
#
|
|
719
|
+
# @elm_.pattern = @pattern_cc
|
|
720
|
+
# @elm_.normal = true
|
|
721
|
+
# @elm_.parser = self
|
|
722
|
+
# when THREE,SIX
|
|
723
|
+
# # puts @res[1]
|
|
724
|
+
# # puts @res[3]
|
|
725
|
+
# # @_name = @res[1]
|
|
726
|
+
# # element (要素)
|
|
727
|
+
# @elm_ = Element.new(@_name)
|
|
728
|
+
# # attribute (属性)
|
|
729
|
+
# @elm_.attributes = @res[1].chop
|
|
730
|
+
# # content (内容)
|
|
731
|
+
# @elm_.mixed_content = @res[3]
|
|
732
|
+
# # document (全体)
|
|
733
|
+
# @elm_.document = @res[0]
|
|
734
|
+
# # pattern (内容あり要素検索用パターン)
|
|
735
|
+
# @elm_.pattern = @pattern_cc
|
|
736
|
+
#
|
|
737
|
+
# @elm_.normal = true
|
|
738
|
+
# @elm_.parser = self
|
|
739
|
+
# end
|
|
740
|
+
# @elm_
|
|
741
|
+
# end
|
|
742
|
+
#
|
|
743
|
+
# private :element_normal_2_1
|
|
744
|
+
#
|
|
745
|
+
# def element_normal_2_2
|
|
746
|
+
# # @pattern_cc_1 = String.new('') << "<" << @_name << '(\\s[^<>]*' << @_attr_name << '="'
|
|
747
|
+
# # @pattern_cc_1 << @_attr_value << '(?:[^<>\\/]*>|(?:(?!([^<>]*\\/>))[^<>]*>)))'
|
|
748
|
+
# @pattern_cc_1 = "<([^<>\"]*)(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}(?:[^<>\\/]*>|(?:(?!([^<>]*\\/>))[^<>]*>)))"
|
|
749
|
+
#
|
|
750
|
+
# # search of normal element (内容あり要素検索)
|
|
751
|
+
# @pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc_1)
|
|
752
|
+
# @sbuf = String.new('')
|
|
753
|
+
#
|
|
754
|
+
# @cnt = 0
|
|
755
|
+
#
|
|
756
|
+
# create_element_pattern_2(2)
|
|
757
|
+
#
|
|
758
|
+
# @pattern_cc = @sbuf
|
|
759
|
+
#
|
|
760
|
+
# if @sbuf.length == ZERO || @cnt != ZERO
|
|
761
|
+
# return nil
|
|
762
|
+
# end
|
|
763
|
+
#
|
|
764
|
+
# @pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
|
765
|
+
# @res = @pattern.match(@root.document)
|
|
766
|
+
# end
|
|
767
|
+
#
|
|
768
|
+
# private :element_normal_2_2
|
|
769
|
+
#
|
|
770
|
+
# def create_pattern_2(args_cnt)
|
|
771
|
+
# @pattern_cc_1b = String.new('') << "<" << @_name << '(\\s[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))'
|
|
772
|
+
#
|
|
773
|
+
# # @pattern_cc_1_1 = String.new('') << "<" << @_name << '(\\s[^<>]*' << @_attr_name << '="'
|
|
774
|
+
# # @pattern_cc_1_1 << @_attr_value << '"(?:[^<>\\/]*>|(?!([^<>]*\\/>))[^<>]*>))('
|
|
775
|
+
# @pattern_cc_1_1 = "<#{@_name}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"(?:[^<>\\/]*>|(?!([^<>]*\\/>))[^<>]*>))("
|
|
776
|
+
# @pattern_cc_1_2 = String.new('') << '.*?<' << @_name << '(\\s[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))'
|
|
777
|
+
# @pattern_cc_2 = String.new('') << '<\\/' << @_name << '>'
|
|
778
|
+
# @pattern_cc_2_1 = String.new('') << '.*?<\/' << @_name << '>'
|
|
779
|
+
# @pattern_cc_2_2 = String.new('') << '.*?)<\/' << @_name << '>'
|
|
780
|
+
#
|
|
781
|
+
# @pattern_2 = Meteor::Core::Util::PatternCache.get(@pattern_cc_2)
|
|
782
|
+
# @pattern_1b = Meteor::Core::Util::PatternCache.get(@pattern_cc_1b)
|
|
783
|
+
# end
|
|
784
|
+
#
|
|
785
|
+
# def element_void_2
|
|
786
|
+
# element_void_2_1('"[^<>]*\\/>')
|
|
787
|
+
# end
|
|
788
|
+
#
|
|
789
|
+
# private :element_void_2
|
|
790
|
+
#
|
|
791
|
+
# def element_void_2_1(closer)
|
|
792
|
+
# # element (要素)
|
|
793
|
+
# @elm_ = Element.new(@res[1])
|
|
794
|
+
# # attribute (属性)
|
|
795
|
+
# @elm_.attributes = @res[2]
|
|
796
|
+
# # document (全体)
|
|
797
|
+
# @elm_.document = @res[0]
|
|
798
|
+
# # void element search pattern (空要素検索用パターン)
|
|
799
|
+
# @pattern_cc = String.new('') << "<" << @_name << '\\s[^<>]*' << @_attr_name << '="' << @_attr_value << closer
|
|
800
|
+
# @elm_.pattern = @pattern_cc
|
|
801
|
+
# @elm_.parser = self
|
|
802
|
+
#
|
|
803
|
+
# @elm_
|
|
804
|
+
# end
|
|
805
|
+
#
|
|
806
|
+
# private :element_void_2_1
|
|
853
807
|
|
|
854
808
|
#
|
|
855
809
|
# get element using tag name and attribute1,2(name="value") (要素のタグ名と属性1・属性2(属性名="属性値")で検索し、要素を取得する)
|
|
@@ -903,9 +857,7 @@ module Meteor
|
|
|
903
857
|
# @pattern_cc = @pattern_cc_2
|
|
904
858
|
element_normal_5_1(name)
|
|
905
859
|
else
|
|
906
|
-
if @error_check
|
|
907
|
-
puts(Meteor::Exception::NoSuchElementException.new(name, attr_name, attr_value).message)
|
|
908
|
-
end
|
|
860
|
+
puts(Meteor::Exception::NoSuchElementException.new(name, attr_name, attr_value).message) if @error_check
|
|
909
861
|
|
|
910
862
|
@elm_ = nil
|
|
911
863
|
end
|
|
@@ -926,7 +878,6 @@ module Meteor
|
|
|
926
878
|
private :quote_element_5
|
|
927
879
|
|
|
928
880
|
def element_normal_5_1(name)
|
|
929
|
-
|
|
930
881
|
# puts @res.captures.length
|
|
931
882
|
case @res.captures.length
|
|
932
883
|
when FOUR
|
|
@@ -996,9 +947,7 @@ module Meteor
|
|
|
996
947
|
def element_normal_5_2
|
|
997
948
|
element_pattern_normal_5_2
|
|
998
949
|
|
|
999
|
-
if @sbuf.length == ZERO || @cnt != ZERO
|
|
1000
|
-
return nil
|
|
1001
|
-
end
|
|
950
|
+
return nil if @sbuf.length == ZERO || @cnt != ZERO
|
|
1002
951
|
|
|
1003
952
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
|
1004
953
|
@res = @pattern.match(@root.document)
|
|
@@ -1009,14 +958,13 @@ module Meteor
|
|
|
1009
958
|
private :element_normal_5_2
|
|
1010
959
|
|
|
1011
960
|
def element_pattern_normal_5_2
|
|
1012
|
-
|
|
1013
961
|
# @pattern_cc_1 = String.new('') << "<" << @_name << '(\\s[^<>]*(?:' << @_attr_name1 << '="'
|
|
1014
962
|
# @pattern_cc_1 << @_attr_value1 << '"[^<>]*' << @_attr_name2 << '="'
|
|
1015
963
|
# @pattern_cc_1 << @_attr_value2 << '"|' << @_attr_name2 << '="'
|
|
1016
964
|
# @pattern_cc_1 << @_attr_value2 << '"[^<>]*' << @_attr_name1 << '="'
|
|
1017
965
|
# @pattern_cc_1 << @_attr_value1 << '")([^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>)))'
|
|
1018
966
|
@pattern_cc_1 = "<#{@_name}(\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")([^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>)))"
|
|
1019
|
-
@pattern_cc_1b = String.new(
|
|
967
|
+
@pattern_cc_1b = String.new('') << '<' << @_name << '(\\s[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))'
|
|
1020
968
|
# @pattern_cc_1b = "<#{@_name}(\\s[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))"
|
|
1021
969
|
|
|
1022
970
|
# @pattern_cc_1_1 = String.new('') << "<" << @_name << '(\\s[^<>]*(?:' << @_attr_name1 << '="'
|
|
@@ -1025,10 +973,10 @@ module Meteor
|
|
|
1025
973
|
# @pattern_cc_1_1 << @_attr_value2 << '"[^<>]*' << @_attr_name1 << '="'
|
|
1026
974
|
# @pattern_cc_1_1 << @_attr_value1 << '")(?:[^<>\\/]*>|(?!([^<>]*\\/>))[^<>]*>))('
|
|
1027
975
|
@pattern_cc_1_1 = "<#{@_name}(\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")(?:[^<>\\/]*>|(?!([^<>]*\\/>))[^<>]*>))("
|
|
1028
|
-
@pattern_cc_1_2 = String.new(
|
|
1029
|
-
@pattern_cc_2 = String.new(
|
|
1030
|
-
@pattern_cc_2_1 = String.new(
|
|
1031
|
-
@pattern_cc_2_2 = String.new(
|
|
976
|
+
@pattern_cc_1_2 = String.new('') << '.*?<' << @_name << '(\\s[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))'
|
|
977
|
+
@pattern_cc_2 = String.new('') << '<\\/' << @_name << '>'
|
|
978
|
+
@pattern_cc_2_1 = String.new('') << '.*?<\\/' << @_name << '>'
|
|
979
|
+
@pattern_cc_2_2 = String.new('') << '.*?)<\\/' << @_name << '>'
|
|
1032
980
|
|
|
1033
981
|
# @pattern_cc_1_2 = ".*?<#{@_name}(\\s[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))"
|
|
1034
982
|
# @pattern_cc_2 = String.new('') << "<\\/#{@_name}>"
|
|
@@ -1038,7 +986,7 @@ module Meteor
|
|
|
1038
986
|
# search of normal element (内容あり要素検索)
|
|
1039
987
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc_1)
|
|
1040
988
|
|
|
1041
|
-
@sbuf = String.new(
|
|
989
|
+
@sbuf = String.new('')
|
|
1042
990
|
|
|
1043
991
|
@pattern_2 = Meteor::Core::Util::PatternCache.get(@pattern_cc_2)
|
|
1044
992
|
@pattern_1b = Meteor::Core::Util::PatternCache.get(@pattern_cc_1b)
|
|
@@ -1051,7 +999,7 @@ module Meteor
|
|
|
1051
999
|
private :element_pattern_normal_5_2
|
|
1052
1000
|
|
|
1053
1001
|
def element_void_5(name)
|
|
1054
|
-
element_void_5_1(name, "
|
|
1002
|
+
element_void_5_1(name, '")[^<>]*)\\/>')
|
|
1055
1003
|
end
|
|
1056
1004
|
|
|
1057
1005
|
private :element_void_5
|
|
@@ -1169,109 +1117,104 @@ module Meteor
|
|
|
1169
1117
|
@cnt += ONE
|
|
1170
1118
|
end
|
|
1171
1119
|
else
|
|
1172
|
-
if @cnt == ZERO
|
|
1173
|
-
break
|
|
1174
|
-
end
|
|
1120
|
+
break if @cnt == ZERO
|
|
1175
1121
|
|
|
1176
1122
|
@res = @pattern_2.match(@root.document, @position)
|
|
1177
1123
|
|
|
1178
|
-
|
|
1179
|
-
@cnt -= ONE
|
|
1124
|
+
break unless @res
|
|
1180
1125
|
|
|
1181
|
-
|
|
1182
|
-
@sbuf << @pattern_cc_2_1
|
|
1183
|
-
else
|
|
1184
|
-
@sbuf << @pattern_cc_2_2
|
|
1185
|
-
break
|
|
1186
|
-
end
|
|
1126
|
+
@cnt -= ONE
|
|
1187
1127
|
|
|
1188
|
-
|
|
1128
|
+
if @cnt != ZERO
|
|
1129
|
+
@sbuf << @pattern_cc_2_1
|
|
1189
1130
|
else
|
|
1131
|
+
@sbuf << @pattern_cc_2_2
|
|
1190
1132
|
break
|
|
1191
1133
|
end
|
|
1192
|
-
end
|
|
1193
|
-
|
|
1194
|
-
@pattern = @pattern_1b
|
|
1195
|
-
end
|
|
1196
|
-
end
|
|
1197
|
-
|
|
1198
|
-
private :create_element_pattern
|
|
1199
|
-
|
|
1200
|
-
=begin
|
|
1201
|
-
def create_element_pattern_2(args_cnt)
|
|
1202
|
-
@position = 0
|
|
1203
|
-
|
|
1204
|
-
while (@res = @pattern.match(@root.document, @position)) || @cnt > ZERO
|
|
1205
|
-
if @res
|
|
1206
|
-
if @cnt > ZERO
|
|
1207
|
-
@position2 = @res.end(0)
|
|
1208
|
-
@res = @pattern_2.match(@root.document, @position)
|
|
1209
1134
|
|
|
1210
|
-
|
|
1211
|
-
@position = @res.end(0)
|
|
1135
|
+
@position = @res.end(0)
|
|
1212
1136
|
|
|
1213
|
-
if @position > @position2
|
|
1214
|
-
@sbuf << @pattern_cc_1_2
|
|
1215
|
-
@cnt += 1
|
|
1216
|
-
@position = @position2
|
|
1217
|
-
else
|
|
1218
|
-
@cnt -= ONE
|
|
1219
|
-
|
|
1220
|
-
if @cnt != ZERO
|
|
1221
|
-
@sbuf << @pattern_cc_2_1
|
|
1222
|
-
else
|
|
1223
|
-
@sbuf << @pattern_cc_2_2
|
|
1224
|
-
break
|
|
1225
|
-
end
|
|
1226
|
-
end
|
|
1227
|
-
else
|
|
1228
|
-
@sbuf << @pattern_cc_1_2
|
|
1229
|
-
@cnt += 1
|
|
1230
|
-
@position = @position2
|
|
1231
|
-
end
|
|
1232
|
-
else
|
|
1233
|
-
@position = @res.end(0)
|
|
1234
|
-
@_name = @res[1]
|
|
1235
|
-
|
|
1236
|
-
create_pattern_2(args_cnt)
|
|
1237
|
-
|
|
1238
|
-
@sbuf << @pattern_cc_1_1
|
|
1239
|
-
@cnt += ONE
|
|
1240
|
-
end
|
|
1241
|
-
else
|
|
1242
|
-
if @cnt == ZERO
|
|
1243
|
-
break
|
|
1244
|
-
end
|
|
1245
|
-
|
|
1246
|
-
@res = @pattern_2.match(@root.document, @position)
|
|
1247
|
-
|
|
1248
|
-
if @res
|
|
1249
|
-
@cnt -= ONE
|
|
1250
|
-
|
|
1251
|
-
if @cnt != ZERO
|
|
1252
|
-
@sbuf << @pattern_cc_2_1
|
|
1253
|
-
else
|
|
1254
|
-
@sbuf << @pattern_cc_2_2
|
|
1255
|
-
break
|
|
1256
|
-
end
|
|
1257
|
-
|
|
1258
|
-
@position = @res.end(0)
|
|
1259
|
-
else
|
|
1260
|
-
break
|
|
1261
|
-
end
|
|
1262
1137
|
end
|
|
1263
1138
|
|
|
1264
1139
|
@pattern = @pattern_1b
|
|
1265
1140
|
end
|
|
1266
1141
|
end
|
|
1267
1142
|
|
|
1268
|
-
private :
|
|
1269
|
-
|
|
1270
|
-
# def create_pattern_2
|
|
1271
|
-
# end
|
|
1143
|
+
private :create_element_pattern
|
|
1272
1144
|
|
|
1273
|
-
#
|
|
1274
|
-
=
|
|
1145
|
+
# def create_element_pattern_2(args_cnt)
|
|
1146
|
+
# @position = 0
|
|
1147
|
+
#
|
|
1148
|
+
# while (@res = @pattern.match(@root.document, @position)) || @cnt > ZERO
|
|
1149
|
+
# if @res
|
|
1150
|
+
# if @cnt > ZERO
|
|
1151
|
+
# @position2 = @res.end(0)
|
|
1152
|
+
# @res = @pattern_2.match(@root.document, @position)
|
|
1153
|
+
#
|
|
1154
|
+
# if @res
|
|
1155
|
+
# @position = @res.end(0)
|
|
1156
|
+
#
|
|
1157
|
+
# if @position > @position2
|
|
1158
|
+
# @sbuf << @pattern_cc_1_2
|
|
1159
|
+
# @cnt += 1
|
|
1160
|
+
# @position = @position2
|
|
1161
|
+
# else
|
|
1162
|
+
# @cnt -= ONE
|
|
1163
|
+
#
|
|
1164
|
+
# if @cnt != ZERO
|
|
1165
|
+
# @sbuf << @pattern_cc_2_1
|
|
1166
|
+
# else
|
|
1167
|
+
# @sbuf << @pattern_cc_2_2
|
|
1168
|
+
# break
|
|
1169
|
+
# end
|
|
1170
|
+
# end
|
|
1171
|
+
# else
|
|
1172
|
+
# @sbuf << @pattern_cc_1_2
|
|
1173
|
+
# @cnt += 1
|
|
1174
|
+
# @position = @position2
|
|
1175
|
+
# end
|
|
1176
|
+
# else
|
|
1177
|
+
# @position = @res.end(0)
|
|
1178
|
+
# @_name = @res[1]
|
|
1179
|
+
#
|
|
1180
|
+
# create_pattern_2(args_cnt)
|
|
1181
|
+
#
|
|
1182
|
+
# @sbuf << @pattern_cc_1_1
|
|
1183
|
+
# @cnt += ONE
|
|
1184
|
+
# end
|
|
1185
|
+
# else
|
|
1186
|
+
# if @cnt == ZERO
|
|
1187
|
+
# break
|
|
1188
|
+
# end
|
|
1189
|
+
#
|
|
1190
|
+
# @res = @pattern_2.match(@root.document, @position)
|
|
1191
|
+
#
|
|
1192
|
+
# if @res
|
|
1193
|
+
# @cnt -= ONE
|
|
1194
|
+
#
|
|
1195
|
+
# if @cnt != ZERO
|
|
1196
|
+
# @sbuf << @pattern_cc_2_1
|
|
1197
|
+
# else
|
|
1198
|
+
# @sbuf << @pattern_cc_2_2
|
|
1199
|
+
# break
|
|
1200
|
+
# end
|
|
1201
|
+
#
|
|
1202
|
+
# @position = @res.end(0)
|
|
1203
|
+
# else
|
|
1204
|
+
# break
|
|
1205
|
+
# end
|
|
1206
|
+
# end
|
|
1207
|
+
#
|
|
1208
|
+
# @pattern = @pattern_1b
|
|
1209
|
+
# end
|
|
1210
|
+
# end
|
|
1211
|
+
#
|
|
1212
|
+
# private :create_element_pattern_2
|
|
1213
|
+
#
|
|
1214
|
+
# # def create_pattern_2
|
|
1215
|
+
# # end
|
|
1216
|
+
#
|
|
1217
|
+
# # private :create_pattern_2
|
|
1275
1218
|
|
|
1276
1219
|
# get elements (要素を取得する)
|
|
1277
1220
|
# @overload elements(name)
|
|
@@ -1316,9 +1259,9 @@ module Meteor
|
|
|
1316
1259
|
#
|
|
1317
1260
|
def elements(elm, attrs = nil, *args)
|
|
1318
1261
|
if !attrs
|
|
1319
|
-
if elm.
|
|
1262
|
+
if elm.is_a?(String)
|
|
1320
1263
|
elements_(elm)
|
|
1321
|
-
elsif elm.
|
|
1264
|
+
elsif elm.is_a?(Hash)
|
|
1322
1265
|
if elm.size == ONE
|
|
1323
1266
|
elements_(elm.keys[0], elm.values[0])
|
|
1324
1267
|
elsif elm.size == TWO
|
|
@@ -1329,7 +1272,7 @@ module Meteor
|
|
|
1329
1272
|
else
|
|
1330
1273
|
raise ArgumentError
|
|
1331
1274
|
end
|
|
1332
|
-
elsif attrs.
|
|
1275
|
+
elsif attrs.is_a?(Hash)
|
|
1333
1276
|
if attrs.size == ONE
|
|
1334
1277
|
elements_(elm, attrs.keys[0], attrs.values[0])
|
|
1335
1278
|
elsif attrs.size == TWO
|
|
@@ -1338,7 +1281,7 @@ module Meteor
|
|
|
1338
1281
|
@elm_ = nil
|
|
1339
1282
|
raise ArgumentError
|
|
1340
1283
|
end
|
|
1341
|
-
elsif attrs.
|
|
1284
|
+
elsif attrs.is_a?(String)
|
|
1342
1285
|
case args.length
|
|
1343
1286
|
when ZERO
|
|
1344
1287
|
elements_(elm, attrs)
|
|
@@ -1359,7 +1302,7 @@ module Meteor
|
|
|
1359
1302
|
end
|
|
1360
1303
|
|
|
1361
1304
|
def elements_(*args)
|
|
1362
|
-
elm_arr =
|
|
1305
|
+
elm_arr = []
|
|
1363
1306
|
|
|
1364
1307
|
@on_search = true
|
|
1365
1308
|
|
|
@@ -1376,9 +1319,7 @@ module Meteor
|
|
|
1376
1319
|
@elm_ = element_5(*args)
|
|
1377
1320
|
end
|
|
1378
1321
|
|
|
1379
|
-
|
|
1380
|
-
return elm_arr
|
|
1381
|
-
end
|
|
1322
|
+
return elm_arr unless @elm_
|
|
1382
1323
|
|
|
1383
1324
|
@pattern_cc = @elm_.pattern
|
|
1384
1325
|
|
|
@@ -1437,76 +1378,38 @@ module Meteor
|
|
|
1437
1378
|
# @return [Array<Meteor::Element>] element array (要素配列)
|
|
1438
1379
|
#
|
|
1439
1380
|
def find(selector)
|
|
1440
|
-
open_count = selector.count(
|
|
1381
|
+
open_count = selector.count('[')
|
|
1441
1382
|
|
|
1442
1383
|
case open_count
|
|
1443
1384
|
when ZERO
|
|
1444
|
-
if selector.count(
|
|
1445
|
-
if @res = @@pattern_find_1.match(selector)
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
if selector[0] == "#"
|
|
1452
|
-
if @res = @@pattern_find_2_1.match(selector)
|
|
1453
|
-
elements_("id", @res[1])
|
|
1454
|
-
else
|
|
1455
|
-
nil
|
|
1456
|
-
end
|
|
1457
|
-
else
|
|
1458
|
-
if @res = @@pattern_find_3_2.match(selector)
|
|
1459
|
-
elements_(@res[1], "id", @res[2])
|
|
1460
|
-
else
|
|
1461
|
-
nil
|
|
1462
|
-
end
|
|
1385
|
+
if selector.count('#.').zero?
|
|
1386
|
+
elements_(@res[1]) if (@res = @@pattern_find_1.match(selector))
|
|
1387
|
+
elsif selector.count('#') == 1
|
|
1388
|
+
if selector[0] == '#'
|
|
1389
|
+
elements_('id', @res[1]) if (@res = @@pattern_find_2_1.match(selector))
|
|
1390
|
+
elsif (@res = @@pattern_find_3_2.match(selector))
|
|
1391
|
+
elements_(@res[1], 'id', @res[2])
|
|
1463
1392
|
end
|
|
1464
|
-
elsif selector.count(
|
|
1465
|
-
if selector[0] ==
|
|
1466
|
-
if @res = @@pattern_find_2_2.match(selector)
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
nil
|
|
1470
|
-
end
|
|
1471
|
-
else
|
|
1472
|
-
if @res = @@pattern_find_3_3.match(selector)
|
|
1473
|
-
elements_(@res[1], "class", @res[2])
|
|
1474
|
-
else
|
|
1475
|
-
nil
|
|
1476
|
-
end
|
|
1393
|
+
elsif selector.count('.') == 1
|
|
1394
|
+
if selector[0] == '.'
|
|
1395
|
+
elements_('class', @res[1]) if (@res = @@pattern_find_2_2.match(selector))
|
|
1396
|
+
elsif (@res = @@pattern_find_3_3.match(selector))
|
|
1397
|
+
elements_(@res[1], 'class', @res[2])
|
|
1477
1398
|
end
|
|
1478
1399
|
end
|
|
1479
1400
|
|
|
1480
1401
|
when ONE
|
|
1481
|
-
if selector[0] ==
|
|
1482
|
-
if @res = @@pattern_find_2_3.match(selector)
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
nil
|
|
1486
|
-
end
|
|
1487
|
-
else
|
|
1488
|
-
if @res = @@pattern_find_3_1.match(selector)
|
|
1489
|
-
elements_(@res[1], @res[2], @res[3])
|
|
1490
|
-
else
|
|
1491
|
-
nil
|
|
1492
|
-
end
|
|
1402
|
+
if selector[0] == '['
|
|
1403
|
+
elements_(@res[1], @res[2]) if (@res = @@pattern_find_2_3.match(selector))
|
|
1404
|
+
elsif (@res = @@pattern_find_3_1.match(selector))
|
|
1405
|
+
elements_(@res[1], @res[2], @res[3])
|
|
1493
1406
|
end
|
|
1494
1407
|
when 2
|
|
1495
|
-
if selector[0] ==
|
|
1496
|
-
if @res = @@pattern_find_4.match(selector)
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
nil
|
|
1500
|
-
end
|
|
1501
|
-
else
|
|
1502
|
-
if @res = @@pattern_find_5.match(selector)
|
|
1503
|
-
elements_(@res[1], @res[2], @res[3], @res[4], @res[5])
|
|
1504
|
-
else
|
|
1505
|
-
nil
|
|
1506
|
-
end
|
|
1408
|
+
if selector[0] == '['
|
|
1409
|
+
elements_(@res[1], @res[2], @res[3], @res[4]) if (@res = @@pattern_find_4.match(selector))
|
|
1410
|
+
elsif (@res = @@pattern_find_5.match(selector))
|
|
1411
|
+
elements_(@res[1], @res[2], @res[3], @res[4], @res[5])
|
|
1507
1412
|
end
|
|
1508
|
-
else
|
|
1509
|
-
nil
|
|
1510
1413
|
end
|
|
1511
1414
|
end
|
|
1512
1415
|
|
|
@@ -1529,20 +1432,20 @@ module Meteor
|
|
|
1529
1432
|
# @return [String] attribute value (属性値)
|
|
1530
1433
|
#
|
|
1531
1434
|
def attr(elm, attr, *args)
|
|
1532
|
-
if attr.
|
|
1435
|
+
if attr.is_a?(String) || attr.is_a?(Symbol)
|
|
1533
1436
|
case args.length
|
|
1534
1437
|
when ZERO
|
|
1535
1438
|
get_attr_value(elm, attr.to_s)
|
|
1536
1439
|
when ONE
|
|
1537
|
-
if args[0]
|
|
1440
|
+
if !args[0].nil?
|
|
1538
1441
|
elm.document_sync = true
|
|
1539
1442
|
set_attribute_3(elm, attr.to_s, args[0])
|
|
1540
1443
|
else
|
|
1541
1444
|
remove_attr(elm, attr.to_s)
|
|
1542
1445
|
end
|
|
1543
1446
|
end
|
|
1544
|
-
elsif attr.
|
|
1545
|
-
if attr.values[0]
|
|
1447
|
+
elsif attr.is_a?(Hash) && attr.size == 1
|
|
1448
|
+
if !attr.values[0].nil?
|
|
1546
1449
|
elm.document_sync = true
|
|
1547
1450
|
set_attribute_3(elm, attr.keys[0].to_s, attr.values[0])
|
|
1548
1451
|
else
|
|
@@ -1566,7 +1469,7 @@ module Meteor
|
|
|
1566
1469
|
# @return [Meteor::Element] element (要素)
|
|
1567
1470
|
#
|
|
1568
1471
|
def set_attribute_3(elm, attr_name, attr_value)
|
|
1569
|
-
|
|
1472
|
+
unless elm.cx
|
|
1570
1473
|
attr_value = escape(attr_value.to_s)
|
|
1571
1474
|
# update attributes (属性群の更新)
|
|
1572
1475
|
edit_attrs_(elm, attr_name, attr_value)
|
|
@@ -1582,26 +1485,25 @@ module Meteor
|
|
|
1582
1485
|
# @res = @pattern.match(elm.attributes)
|
|
1583
1486
|
|
|
1584
1487
|
# Attribute existence check (属性の存在判定)
|
|
1585
|
-
|
|
1586
|
-
|
|
1488
|
+
@_attr_value = attr_value
|
|
1489
|
+
if elm.attributes.include?(String.new(' ') << attr_name << '="')
|
|
1587
1490
|
|
|
1588
1491
|
# replace attribute (属性の置換)
|
|
1589
|
-
@pattern = Meteor::Core::Util::PatternCache.get(String.new(
|
|
1492
|
+
@pattern = Meteor::Core::Util::PatternCache.get(String.new('') << attr_name << '="[^"]*"')
|
|
1590
1493
|
# @pattern = Meteor::Core::Util::PatternCache.get("#{attr_name}=\"[^\"]*\"")
|
|
1591
1494
|
|
|
1592
|
-
elm.attributes.sub!(@pattern, String.new(
|
|
1593
|
-
|
|
1495
|
+
elm.attributes.sub!(@pattern, String.new('') << attr_name << '="' << @_attr_value << '"')
|
|
1496
|
+
# elm.attributes.sub!(@pattern, "#{attr_name}=\"#{@_attr_value}\"")
|
|
1594
1497
|
else
|
|
1595
1498
|
# add an attribute to attrubutes (属性文字列の最後に新規の属性を追加する)
|
|
1596
|
-
@_attr_value = attr_value
|
|
1597
1499
|
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1500
|
+
elm.attributes = if elm.attributes != '' && elm.attributes.strip != ''
|
|
1501
|
+
String.new('') << ' ' << elm.attributes.strip
|
|
1502
|
+
else
|
|
1503
|
+
String.new('')
|
|
1504
|
+
end
|
|
1603
1505
|
|
|
1604
|
-
elm.attributes <<
|
|
1506
|
+
elm.attributes << ' ' << attr_name << '="' << @_attr_value << '"'
|
|
1605
1507
|
# elm.attributes << " #{attr_name}=\"#{@_attr_value}\""
|
|
1606
1508
|
end
|
|
1607
1509
|
end
|
|
@@ -1622,16 +1524,14 @@ module Meteor
|
|
|
1622
1524
|
|
|
1623
1525
|
def get_attr_value_(elm, attr_name)
|
|
1624
1526
|
# attribute search pattern (属性検索用パターン)
|
|
1625
|
-
@pattern = Meteor::Core::Util::PatternCache.get(String.new(
|
|
1527
|
+
@pattern = Meteor::Core::Util::PatternCache.get(String.new('') << attr_name << '="([^"]*)"')
|
|
1626
1528
|
# @pattern = Meteor::Core::Util::PatternCache.get("#{attr_name}=\"([^\"]*)\"")
|
|
1627
1529
|
|
|
1628
1530
|
@res = @pattern.match(elm.attributes)
|
|
1629
1531
|
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
nil
|
|
1634
|
-
end
|
|
1532
|
+
return unless @res
|
|
1533
|
+
|
|
1534
|
+
unescape(@res[1])
|
|
1635
1535
|
end
|
|
1636
1536
|
|
|
1637
1537
|
private :get_attr_value_
|
|
@@ -1649,18 +1549,17 @@ module Meteor
|
|
|
1649
1549
|
when ZERO
|
|
1650
1550
|
get_attrs(elm)
|
|
1651
1551
|
when ONE
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
raise ArgumentError
|
|
1660
|
-
end
|
|
1552
|
+
raise ArgumentError unless args[0].is_a?(Hash)
|
|
1553
|
+
|
|
1554
|
+
if args[0].size == 1
|
|
1555
|
+
elm.document_sync = true
|
|
1556
|
+
set_attribute_3(elm, args[0].keys[0].to_s, args[0].values[0])
|
|
1557
|
+
elsif args[0].size >= 1
|
|
1558
|
+
set_attrs(elm, args[0])
|
|
1661
1559
|
else
|
|
1662
1560
|
raise ArgumentError
|
|
1663
1561
|
end
|
|
1562
|
+
|
|
1664
1563
|
else
|
|
1665
1564
|
raise ArgumentError
|
|
1666
1565
|
end
|
|
@@ -1672,7 +1571,7 @@ module Meteor
|
|
|
1672
1571
|
# @return [Hash<String,String>] attribute map (属性マップ)
|
|
1673
1572
|
#
|
|
1674
1573
|
def get_attrs(elm)
|
|
1675
|
-
attrs =
|
|
1574
|
+
attrs = {}
|
|
1676
1575
|
|
|
1677
1576
|
elm.attributes.scan(@@pattern_get_attrs_map) do |a, b|
|
|
1678
1577
|
attrs.store(a, unescape(b))
|
|
@@ -1690,7 +1589,7 @@ module Meteor
|
|
|
1690
1589
|
# @return [Meteor::Element] element (要素)
|
|
1691
1590
|
#
|
|
1692
1591
|
def set_attrs(elm, attr_map)
|
|
1693
|
-
|
|
1592
|
+
unless elm.cx
|
|
1694
1593
|
elm.document_sync = true
|
|
1695
1594
|
attr_map.each do |name, value|
|
|
1696
1595
|
set_attribute_3(elm, name.to_s, value)
|
|
@@ -1753,7 +1652,7 @@ module Meteor
|
|
|
1753
1652
|
# @return [Meteor::Element] element (要素)
|
|
1754
1653
|
#
|
|
1755
1654
|
def set_attr_map(elm, attr_map)
|
|
1756
|
-
|
|
1655
|
+
unless elm.cx
|
|
1757
1656
|
attr_map.map.each do |name, attr|
|
|
1758
1657
|
if attr_map.changed(name)
|
|
1759
1658
|
edit_attrs_(elm, name.to_s, attr.value)
|
|
@@ -1817,9 +1716,7 @@ module Meteor
|
|
|
1817
1716
|
# @return [Meteor::Element] element (要素)
|
|
1818
1717
|
#
|
|
1819
1718
|
def set_content_3(elm, content, entity_ref = true)
|
|
1820
|
-
if entity_ref || !elm.raw_content
|
|
1821
|
-
escape_content(content, elm)
|
|
1822
|
-
end
|
|
1719
|
+
escape_content(content, elm) if entity_ref || !elm.raw_content
|
|
1823
1720
|
|
|
1824
1721
|
elm.mixed_content = content
|
|
1825
1722
|
elm
|
|
@@ -1835,9 +1732,7 @@ module Meteor
|
|
|
1835
1732
|
#
|
|
1836
1733
|
def set_content_2(elm, content)
|
|
1837
1734
|
# set_content_3(elm, content)
|
|
1838
|
-
unless elm.raw_content
|
|
1839
|
-
escape_content(content, elm)
|
|
1840
|
-
end
|
|
1735
|
+
escape_content(content, elm) unless elm.raw_content
|
|
1841
1736
|
|
|
1842
1737
|
elm.mixed_content = content
|
|
1843
1738
|
elm
|
|
@@ -1852,11 +1747,7 @@ module Meteor
|
|
|
1852
1747
|
#
|
|
1853
1748
|
def get_content_1(elm)
|
|
1854
1749
|
if !elm.cx
|
|
1855
|
-
if elm.normal
|
|
1856
|
-
unescape_content(elm.mixed_content, elm)
|
|
1857
|
-
else
|
|
1858
|
-
nil
|
|
1859
|
-
end
|
|
1750
|
+
unescape_content(elm.mixed_content, elm) if elm.normal
|
|
1860
1751
|
else
|
|
1861
1752
|
unescape_content(elm.mixed_content, elm)
|
|
1862
1753
|
end
|
|
@@ -1871,7 +1762,7 @@ module Meteor
|
|
|
1871
1762
|
# @return [Meteor::Element] element (要素)
|
|
1872
1763
|
#
|
|
1873
1764
|
def remove_attr(elm, attr_name)
|
|
1874
|
-
|
|
1765
|
+
unless elm.cx
|
|
1875
1766
|
elm.document_sync = true
|
|
1876
1767
|
remove_attrs_(elm, attr_name.to_s)
|
|
1877
1768
|
end
|
|
@@ -1881,10 +1772,10 @@ module Meteor
|
|
|
1881
1772
|
|
|
1882
1773
|
def remove_attrs_(elm, attr_name)
|
|
1883
1774
|
# attribute search pattern (属性検索用パターン)
|
|
1884
|
-
@pattern = Meteor::Core::Util::PatternCache.get(String.new(
|
|
1775
|
+
@pattern = Meteor::Core::Util::PatternCache.get(String.new('') << attr_name << '="[^"]*"\\s?')
|
|
1885
1776
|
# @pattern = Meteor::Core::Util::PatternCache.get("#{attr_name}=\"[^\"]*\"\\s?")
|
|
1886
1777
|
# replace attrubute (属性の置換)
|
|
1887
|
-
elm.attributes.sub!(@pattern,
|
|
1778
|
+
elm.attributes.sub!(@pattern, '')
|
|
1888
1779
|
end
|
|
1889
1780
|
|
|
1890
1781
|
private :remove_attrs_
|
|
@@ -1914,14 +1805,10 @@ module Meteor
|
|
|
1914
1805
|
case args.length
|
|
1915
1806
|
when ONE
|
|
1916
1807
|
cxtag_1(args[0].to_s)
|
|
1917
|
-
if @elm_
|
|
1918
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
|
1919
|
-
end
|
|
1808
|
+
@element_cache.store(@elm_.object_id, @elm_) if @elm_
|
|
1920
1809
|
when TWO
|
|
1921
1810
|
cxtag_2(args[0].to_s, args[1].to_s)
|
|
1922
|
-
if @elm_
|
|
1923
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
|
1924
|
-
end
|
|
1811
|
+
@element_cache.store(@elm_.object_id, @elm_) if @elm_
|
|
1925
1812
|
else
|
|
1926
1813
|
raise ArgumentError
|
|
1927
1814
|
end
|
|
@@ -1981,7 +1868,7 @@ module Meteor
|
|
|
1981
1868
|
def cxtag_1(id)
|
|
1982
1869
|
@_id = Regexp.quote(id)
|
|
1983
1870
|
|
|
1984
|
-
@pattern_cc = String.new(
|
|
1871
|
+
@pattern_cc = String.new('') << '<!--\\s@([^<>]*)\\s[^<>]*id="' << @_id << '"'
|
|
1985
1872
|
# @pattern_cc = "<!--\\s@([^<>]*)\\s[^<>]*id=\"#{@_id}\""
|
|
1986
1873
|
|
|
1987
1874
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
|
@@ -2016,37 +1903,37 @@ module Meteor
|
|
|
2016
1903
|
|
|
2017
1904
|
def reflect
|
|
2018
1905
|
# puts @element_cache.size.to_s
|
|
2019
|
-
@element_cache.
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
edit_document_1(item)
|
|
2030
|
-
# edit_pattern_(item)
|
|
2031
|
-
end
|
|
1906
|
+
@element_cache.each_value do |item|
|
|
1907
|
+
next unless item.usable
|
|
1908
|
+
|
|
1909
|
+
# puts "#{item.name}:#{item.document}"
|
|
1910
|
+
if !item.removed
|
|
1911
|
+
if item.copy
|
|
1912
|
+
@pattern = Meteor::Core::Util::PatternCache.get(item.pattern)
|
|
1913
|
+
@root.document.sub!(@pattern, item.copy.parser.document_hook)
|
|
1914
|
+
# item.copy.parser.element_cache.clear
|
|
1915
|
+
item.copy = nil
|
|
2032
1916
|
else
|
|
2033
|
-
|
|
1917
|
+
edit_document_1(item)
|
|
1918
|
+
# edit_pattern_(item)
|
|
2034
1919
|
end
|
|
2035
|
-
|
|
2036
|
-
item
|
|
1920
|
+
else
|
|
1921
|
+
replace(item, '')
|
|
2037
1922
|
end
|
|
1923
|
+
|
|
1924
|
+
item.usable = false
|
|
2038
1925
|
end
|
|
2039
1926
|
end
|
|
2040
1927
|
|
|
2041
1928
|
protected :reflect
|
|
2042
1929
|
|
|
2043
1930
|
def edit_document_1(elm)
|
|
2044
|
-
edit_document_2(elm,
|
|
1931
|
+
edit_document_2(elm, '/>')
|
|
2045
1932
|
end
|
|
2046
1933
|
|
|
2047
1934
|
private :edit_document_1
|
|
2048
1935
|
|
|
2049
|
-
def edit_document_2(elm,
|
|
1936
|
+
def edit_document_2(elm, _closer)
|
|
2050
1937
|
# replace tag (タグ置換)
|
|
2051
1938
|
@pattern = Meteor::Core::Util::PatternCache.get(elm.pattern)
|
|
2052
1939
|
@root.document.sub!(@pattern, elm.document)
|
|
@@ -2058,53 +1945,52 @@ module Meteor
|
|
|
2058
1945
|
# reflect (反映する)
|
|
2059
1946
|
#
|
|
2060
1947
|
def flash
|
|
2061
|
-
if
|
|
2062
|
-
if
|
|
2063
|
-
if
|
|
1948
|
+
if element_hook
|
|
1949
|
+
if element_hook.origin.mono
|
|
1950
|
+
if element_hook.origin.cx
|
|
2064
1951
|
# @root.hookDocument << '<!-- @' << @root.element.name << ' '
|
|
2065
1952
|
# @root.hookDocument << @root.element.attributes << '-->'
|
|
2066
1953
|
# @root.hookDocument << @root.element.mixed_content << '<!-- /@'
|
|
2067
1954
|
# @root.hookDocument << @root.element.name << ' -->'
|
|
2068
|
-
|
|
2069
|
-
"<!-- @#{
|
|
1955
|
+
document_hook <<
|
|
1956
|
+
"<!-- @#{element_hook.name} #{element_hook.attributes}-->#{element_hook.mixed_content}<!-- /@#{element_hook.name} -->"
|
|
2070
1957
|
|
|
2071
1958
|
# self.document_hook << @root.newline << "<!-- @#{self.element_hook.name} #{self.element_hook.attributes}-->#{self.element_hook.mixed_content}<!-- /@#{self.element_hook.name} -->"
|
|
2072
1959
|
else
|
|
2073
1960
|
# @root.hookDocument << "<" << @root.element.name
|
|
2074
1961
|
# @root.hookDocument << @root.element.attributes << '>' << @root.element.mixed_content
|
|
2075
1962
|
# @root.hookDocument << '</' << @root.element.name << '>'
|
|
2076
|
-
|
|
2077
|
-
"<#{
|
|
1963
|
+
document_hook <<
|
|
1964
|
+
"<#{element_hook.name}#{element_hook.attributes}>#{element_hook.mixed_content}</#{element_hook.name}>"
|
|
2078
1965
|
|
|
2079
1966
|
# self.document_hook << @root.newline << "<#{self.element_hook.name}#{self.element_hook.attributes}>#{self.element_hook.mixed_content}</#{self.element_hook.name}>"
|
|
2080
1967
|
end
|
|
2081
1968
|
|
|
2082
|
-
self.element_hook = self.element_hook.origin.clone(self)
|
|
2083
1969
|
else
|
|
2084
1970
|
reflect
|
|
2085
|
-
@_attributes =
|
|
1971
|
+
@_attributes = element_hook.attributes
|
|
2086
1972
|
|
|
2087
|
-
if
|
|
1973
|
+
if element_hook.origin.cx
|
|
2088
1974
|
# @root.hookDocument << '<!-- @' << @root.element.name << ' '
|
|
2089
1975
|
# @root.hookDocument << @_attributes << '-->'
|
|
2090
1976
|
# @root.hookDocument << @root.document << '<!-- /@'
|
|
2091
1977
|
# @root.hookDocument << @root.element.name << ' -->'
|
|
2092
|
-
|
|
2093
|
-
"<!-- @#{
|
|
1978
|
+
document_hook <<
|
|
1979
|
+
"<!-- @#{element_hook.name} #{@_attributes}-->#{@root.document}<!-- /@#{element_hook.name} -->"
|
|
2094
1980
|
|
|
2095
1981
|
# self.document_hook << @root.newline << "<!-- @#{self.element_hook.name} #{@_attributes}-->#{@root.document}<!-- /@#{self.element_hook.name} -->"
|
|
2096
1982
|
else
|
|
2097
1983
|
# @root.hookDocument << "<" << @root.element.name
|
|
2098
1984
|
# @root.hookDocument << @_attributes << '>' << @root.document
|
|
2099
1985
|
# @root.hookDocument << '</' << @root.element.name << '>'
|
|
2100
|
-
|
|
2101
|
-
"<#{
|
|
1986
|
+
document_hook <<
|
|
1987
|
+
"<#{element_hook.name}#{@_attributes}>#{@root.document}</#{element_hook.name}>"
|
|
2102
1988
|
|
|
2103
1989
|
# self.document_hook << @root.newline << "<#{self.element_hook.name}#{@_attributes}>#{@root.document}</#{self.element_hook.name}>"
|
|
2104
1990
|
end
|
|
2105
1991
|
|
|
2106
|
-
self.element_hook = self.element_hook.origin.clone(self)
|
|
2107
1992
|
end
|
|
1993
|
+
self.element_hook = element_hook.origin.clone(self)
|
|
2108
1994
|
else
|
|
2109
1995
|
reflect
|
|
2110
1996
|
@element_cache.clear
|
|
@@ -2115,10 +2001,10 @@ module Meteor
|
|
|
2115
2001
|
def clean
|
|
2116
2002
|
# replace CX start tag (CX開始タグ置換)
|
|
2117
2003
|
@pattern = @@pattern_clean1
|
|
2118
|
-
@root.document.gsub!(@pattern,
|
|
2004
|
+
@root.document.gsub!(@pattern, '')
|
|
2119
2005
|
# rplace CX end tag (CX終了タグ置換)
|
|
2120
2006
|
@pattern = @@pattern_clean2
|
|
2121
|
-
@root.document.gsub!(@pattern,
|
|
2007
|
+
@root.document.gsub!(@pattern, '')
|
|
2122
2008
|
# @root.document << "<!-- Powered by Meteor (C)Yasumasa Ashida -->"
|
|
2123
2009
|
end
|
|
2124
2010
|
|
|
@@ -2131,24 +2017,24 @@ module Meteor
|
|
|
2131
2017
|
# @return [Meteor::Element] element (要素)
|
|
2132
2018
|
#
|
|
2133
2019
|
def shadow(elm)
|
|
2134
|
-
|
|
2135
|
-
# case of normal element (内容あり要素の場合)
|
|
2136
|
-
set_mono_info(elm)
|
|
2020
|
+
return unless elm.normal
|
|
2137
2021
|
|
|
2138
|
-
|
|
2022
|
+
# case of normal element (内容あり要素の場合)
|
|
2023
|
+
set_mono_info(elm)
|
|
2139
2024
|
|
|
2140
|
-
|
|
2025
|
+
pif2 = self.class.new(self)
|
|
2141
2026
|
|
|
2142
|
-
|
|
2143
|
-
pif2.root_element.document = String.new(elm.mixed_content)
|
|
2144
|
-
else
|
|
2145
|
-
pif2.root_element.document = String.new(elm.document)
|
|
2146
|
-
end
|
|
2027
|
+
@elm_ = elm.clone(pif2)
|
|
2147
2028
|
|
|
2148
|
-
|
|
2029
|
+
pif2.root_element.document = if !elm.mono
|
|
2030
|
+
String.new(elm.mixed_content)
|
|
2031
|
+
else
|
|
2032
|
+
String.new(elm.document)
|
|
2033
|
+
end
|
|
2149
2034
|
|
|
2150
|
-
|
|
2151
|
-
|
|
2035
|
+
pif2.root_element.newline = elm.parser.root_element.newline
|
|
2036
|
+
|
|
2037
|
+
@elm_
|
|
2152
2038
|
end
|
|
2153
2039
|
|
|
2154
2040
|
# private :shadow
|
|
@@ -2156,24 +2042,19 @@ module Meteor
|
|
|
2156
2042
|
def set_mono_info(elm)
|
|
2157
2043
|
@res = @@pattern_set_mono1.match(elm.mixed_content)
|
|
2158
2044
|
|
|
2159
|
-
if @res
|
|
2160
|
-
elm.mono = true
|
|
2161
|
-
end
|
|
2045
|
+
elm.mono = true if @res
|
|
2162
2046
|
end
|
|
2163
2047
|
|
|
2164
2048
|
private :set_mono_info
|
|
2165
2049
|
|
|
2166
2050
|
def is_match(regex, str)
|
|
2167
|
-
|
|
2051
|
+
case regex
|
|
2052
|
+
when Regexp
|
|
2168
2053
|
is_match_r(regex, str)
|
|
2169
|
-
|
|
2054
|
+
when Array
|
|
2170
2055
|
is_match_a(regex, str)
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
true
|
|
2174
|
-
else
|
|
2175
|
-
false
|
|
2176
|
-
end
|
|
2056
|
+
when String
|
|
2057
|
+
regex == str.downcase
|
|
2177
2058
|
else
|
|
2178
2059
|
raise ArgumentError
|
|
2179
2060
|
end
|
|
@@ -2214,16 +2095,12 @@ module Meteor
|
|
|
2214
2095
|
|
|
2215
2096
|
def escape(content)
|
|
2216
2097
|
# replace special character (特殊文字の置換)
|
|
2217
|
-
content
|
|
2218
|
-
|
|
2219
|
-
content
|
|
2098
|
+
content.gsub(@@pattern_escape, TABLE_FOR_ESCAPE_)
|
|
2220
2099
|
end
|
|
2221
2100
|
|
|
2222
|
-
def escape_content(content,
|
|
2101
|
+
def escape_content(content, _elm)
|
|
2223
2102
|
# replace special character (特殊文字の置換)
|
|
2224
|
-
content
|
|
2225
|
-
|
|
2226
|
-
content
|
|
2103
|
+
content.gsub(@@pattern_escape_content, TABLE_FOR_ESCAPE_CONTENT_)
|
|
2227
2104
|
end
|
|
2228
2105
|
|
|
2229
2106
|
private :escape
|
|
@@ -2237,19 +2114,19 @@ module Meteor
|
|
|
2237
2114
|
# 「 」<-「 」
|
|
2238
2115
|
# 「&」<-「&」
|
|
2239
2116
|
content.gsub(@@pattern_unescape) do
|
|
2240
|
-
case
|
|
2241
|
-
when
|
|
2242
|
-
|
|
2243
|
-
when
|
|
2244
|
-
"
|
|
2245
|
-
when
|
|
2117
|
+
case ::Regexp.last_match(1)
|
|
2118
|
+
when 'amp'
|
|
2119
|
+
'&'
|
|
2120
|
+
when 'quot'
|
|
2121
|
+
'"'
|
|
2122
|
+
when 'apos'
|
|
2246
2123
|
"'"
|
|
2247
|
-
when
|
|
2248
|
-
|
|
2249
|
-
when
|
|
2250
|
-
|
|
2251
|
-
when
|
|
2252
|
-
|
|
2124
|
+
when 'gt'
|
|
2125
|
+
'>'
|
|
2126
|
+
when 'lt'
|
|
2127
|
+
'<'
|
|
2128
|
+
when 'nbsp'
|
|
2129
|
+
' '
|
|
2253
2130
|
end
|
|
2254
2131
|
end
|
|
2255
2132
|
|
|
@@ -2259,15 +2136,15 @@ module Meteor
|
|
|
2259
2136
|
private :unescape
|
|
2260
2137
|
|
|
2261
2138
|
def br_to_newline(content)
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2139
|
+
return unless (elm.cx || !is_match(@@match_tag_2, elm.name)) && content.include?(BR)
|
|
2140
|
+
|
|
2141
|
+
# 「<br>」->「¥r?¥n」
|
|
2142
|
+
content.gsub!(@@pattern_br_2, @root.newline)
|
|
2266
2143
|
end
|
|
2267
2144
|
|
|
2268
2145
|
private :br_to_newline
|
|
2269
2146
|
|
|
2270
|
-
def unescape_content(content,
|
|
2147
|
+
def unescape_content(content, _elm)
|
|
2271
2148
|
content_ = unescape(content)
|
|
2272
2149
|
|
|
2273
2150
|
br_to_newline(content_)
|