meteor 0.9.30 → 0.9.32
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 +8 -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 +29 -35
- data/demo/xhtml4.rb +27 -33
- data/demo/xml.rb +20 -20
- data/lib/meteor/attribute.rb +1 -4
- data/lib/meteor/attribute_map.rb +21 -22
- data/lib/meteor/core/kernel.rb +604 -727
- data/lib/meteor/core/util/file_reader.rb +37 -0
- data/lib/meteor/core/util/pattern_cache.rb +7 -7
- data/lib/meteor/element.rb +48 -67
- data/lib/meteor/elements.rb +6 -6
- data/lib/meteor/exception/no_such_element_exception.rb +15 -15
- data/lib/meteor/ml/html/parser_impl.rb +69 -71
- data/lib/meteor/ml/html4/parser_impl.rb +129 -144
- data/lib/meteor/ml/xhtml/parser_impl.rb +44 -46
- data/lib/meteor/ml/xhtml4/parser_impl.rb +85 -87
- data/lib/meteor/ml/xml/parser_impl.rb +29 -29
- data/lib/meteor/parsers.rb +92 -100
- 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
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
elsif elm.kind_of?(Meteor::Element)
|
|
226
|
+
case elm
|
|
227
|
+
when String, Symbol
|
|
228
|
+
element_one(elm.to_s)
|
|
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
|
-
|
|
252
|
-
if @elm_
|
|
253
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
|
254
|
-
end
|
|
234
|
+
element_two(elm.keys[0].to_s, elm.values[0])
|
|
235
|
+
@element_cache.store(@elm_.object_id, @elm_) if @elm_
|
|
255
236
|
elsif elm.size == TWO
|
|
256
|
-
|
|
257
|
-
if @elm_
|
|
258
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
|
259
|
-
end
|
|
237
|
+
element_four(elm.keys[0].to_s, elm.values[0], elm.keys[1].to_s, elm.values[1])
|
|
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
|
-
|
|
269
|
-
if @elm_
|
|
270
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
|
271
|
-
end
|
|
247
|
+
element_three(elm.to_s, attrs.keys[0].to_s, attrs.values[0])
|
|
248
|
+
@element_cache.store(@elm_.object_id, @elm_) if @elm_
|
|
272
249
|
elsif attrs.size == TWO
|
|
273
|
-
|
|
274
|
-
if @elm_
|
|
275
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
|
276
|
-
end
|
|
250
|
+
element_five(elm.to_s, attrs.keys[0].to_s, attrs.values[0], attrs.keys[1].to_s, attrs.values[1])
|
|
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
|
-
|
|
285
|
-
if @elm_
|
|
286
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
|
287
|
-
end
|
|
259
|
+
element_two(elm.to_s, attrs.to_s)
|
|
260
|
+
@element_cache.store(@elm_.object_id, @elm_) if @elm_
|
|
288
261
|
|
|
289
262
|
when ONE
|
|
290
|
-
|
|
291
|
-
if @elm_
|
|
292
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
|
293
|
-
end
|
|
263
|
+
element_three(elm.to_s, attrs.to_s, args[0])
|
|
264
|
+
@element_cache.store(@elm_.object_id, @elm_) if @elm_
|
|
294
265
|
when TWO
|
|
295
|
-
|
|
296
|
-
if @elm_
|
|
297
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
|
298
|
-
end
|
|
266
|
+
element_four(elm.to_s, attrs.to_s, args[0].to_s, args[1])
|
|
267
|
+
@element_cache.store(@elm_.object_id, @elm_) if @elm_
|
|
299
268
|
when THREE
|
|
300
|
-
|
|
301
|
-
if @elm_
|
|
302
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
|
303
|
-
end
|
|
269
|
+
element_five(elm.to_s, attrs.to_s, args[0], args[1].to_s, args[2])
|
|
270
|
+
@element_cache.store(@elm_.object_id, @elm_) if @elm_
|
|
304
271
|
else
|
|
305
272
|
@elm_ = nil
|
|
306
273
|
raise ArgumentError
|
|
@@ -316,7 +283,7 @@ module Meteor
|
|
|
316
283
|
# @param [String,Symbol] name tag name (タグ名)
|
|
317
284
|
# @return [Meteor::Element] element(要素)
|
|
318
285
|
#
|
|
319
|
-
def
|
|
286
|
+
def element_one(name)
|
|
320
287
|
quote_name(name)
|
|
321
288
|
|
|
322
289
|
# element search pattern (要素検索用パターン)
|
|
@@ -328,10 +295,10 @@ module Meteor
|
|
|
328
295
|
|
|
329
296
|
if @res
|
|
330
297
|
if @res[1]
|
|
331
|
-
|
|
298
|
+
element_void_one(name)
|
|
332
299
|
else
|
|
333
300
|
# puts '---element_normal_1'
|
|
334
|
-
|
|
301
|
+
element_normal_one(name)
|
|
335
302
|
end
|
|
336
303
|
# else
|
|
337
304
|
end
|
|
@@ -339,29 +306,28 @@ module Meteor
|
|
|
339
306
|
@elm_
|
|
340
307
|
end
|
|
341
308
|
|
|
342
|
-
private :
|
|
309
|
+
private :element_one
|
|
343
310
|
|
|
344
|
-
def
|
|
311
|
+
def element_normal_one(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 << '>'
|
|
@@ -374,9 +340,9 @@ module Meteor
|
|
|
374
340
|
@elm_
|
|
375
341
|
end
|
|
376
342
|
|
|
377
|
-
private :
|
|
343
|
+
private :element_normal_one
|
|
378
344
|
|
|
379
|
-
def
|
|
345
|
+
def element_void_one(name)
|
|
380
346
|
# element (要素)
|
|
381
347
|
@elm_ = Meteor::Element.new(name)
|
|
382
348
|
# attribute (属性)
|
|
@@ -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
|
|
|
@@ -395,7 +361,7 @@ module Meteor
|
|
|
395
361
|
@elm_
|
|
396
362
|
end
|
|
397
363
|
|
|
398
|
-
private :
|
|
364
|
+
private :element_void_one
|
|
399
365
|
|
|
400
366
|
#
|
|
401
367
|
# get element using tag name and attribute(name="value") (要素のタグ名と属性(属性名="属性値")で検索し、要素を取得する)
|
|
@@ -404,20 +370,20 @@ module Meteor
|
|
|
404
370
|
# @param [String] attr_value attribute value (属性値)
|
|
405
371
|
# @param [true,false] quote flag (クオート・フラグ)
|
|
406
372
|
# @return [Meteor::Element] element (要素)
|
|
407
|
-
def
|
|
373
|
+
def element_three(name, attr_name, attr_value, quote = true)
|
|
408
374
|
if quote
|
|
409
|
-
|
|
375
|
+
quote_element_three(name, attr_name, attr_value)
|
|
410
376
|
else
|
|
411
377
|
quote_name(name)
|
|
412
378
|
end
|
|
413
379
|
|
|
414
|
-
@pattern_cc_1 =
|
|
380
|
+
@pattern_cc_1 = element_pattern_three
|
|
415
381
|
|
|
416
382
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc_1)
|
|
417
383
|
@res1 = @pattern.match(@root.document)
|
|
418
384
|
|
|
419
385
|
if @res1 && @res1[1] || !@res1
|
|
420
|
-
@res2 =
|
|
386
|
+
@res2 = element_normal_three_two
|
|
421
387
|
@pattern_cc_2 = @pattern_cc
|
|
422
388
|
|
|
423
389
|
# puts @res2.captures.length
|
|
@@ -429,31 +395,29 @@ module Meteor
|
|
|
429
395
|
@res = @res1
|
|
430
396
|
# @pattern_cc = @pattern_cc_1
|
|
431
397
|
if @res[1]
|
|
432
|
-
|
|
398
|
+
element_void_three(name)
|
|
433
399
|
else
|
|
434
|
-
|
|
400
|
+
element_normal_three_one(name)
|
|
435
401
|
end
|
|
436
402
|
elsif @res1.begin(0) > @res2.begin(0)
|
|
437
403
|
@res = @res2
|
|
438
404
|
# @pattern_cc = @pattern_cc_2
|
|
439
|
-
|
|
405
|
+
element_normal_three_one(name)
|
|
440
406
|
end
|
|
441
407
|
elsif @res1 && !@res2
|
|
442
408
|
@res = @res1
|
|
443
409
|
# @pattern_cc = @pattern_cc_1
|
|
444
410
|
if @res[1]
|
|
445
|
-
|
|
411
|
+
element_void_three(name)
|
|
446
412
|
else
|
|
447
|
-
|
|
413
|
+
element_normal_three_one(name)
|
|
448
414
|
end
|
|
449
415
|
elsif @res2 && !@res1
|
|
450
416
|
@res = @res2
|
|
451
417
|
# @pattern_cc = @pattern_cc_2
|
|
452
|
-
|
|
418
|
+
element_normal_three_one(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
|
|
@@ -461,22 +425,22 @@ module Meteor
|
|
|
461
425
|
@elm_
|
|
462
426
|
end
|
|
463
427
|
|
|
464
|
-
private :
|
|
428
|
+
private :element_three
|
|
465
429
|
|
|
466
|
-
def
|
|
430
|
+
def element_pattern_three
|
|
467
431
|
"<#{@_name}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*)\\/>|<#{@_name}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*)>(((?!(#{@_name}[^<>]*>)).)*)<\\/#{@_name}>"
|
|
468
432
|
end
|
|
469
433
|
|
|
470
|
-
private :
|
|
434
|
+
private :element_pattern_three
|
|
471
435
|
|
|
472
|
-
def
|
|
436
|
+
def quote_element_three(name, attr_name, attr_value)
|
|
473
437
|
quote_name(name)
|
|
474
438
|
quote_attribute(attr_name, attr_value)
|
|
475
439
|
end
|
|
476
440
|
|
|
477
|
-
private :
|
|
441
|
+
private :quote_element_three
|
|
478
442
|
|
|
479
|
-
def
|
|
443
|
+
def element_normal_three_one(name)
|
|
480
444
|
# puts @res.captures.length
|
|
481
445
|
case @res.captures.length
|
|
482
446
|
when FOUR
|
|
@@ -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
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
@elm_.mixed_content = @res[3]
|
|
536
|
-
end
|
|
490
|
+
@elm_.attributes = @res[1].chop
|
|
491
|
+
# if @on_search
|
|
492
|
+
# # attribute (属性)
|
|
493
|
+
# # content (内容)
|
|
494
|
+
# else
|
|
495
|
+
# # attribute (属性)
|
|
496
|
+
# # content (内容)
|
|
497
|
+
# end
|
|
498
|
+
@elm_.mixed_content = @res[3]
|
|
537
499
|
# document (全体)
|
|
538
500
|
@elm_.document = @res[0]
|
|
539
501
|
# normal element search pattern (内容あり要素検索用パターン)
|
|
@@ -547,14 +509,12 @@ module Meteor
|
|
|
547
509
|
@elm_
|
|
548
510
|
end
|
|
549
511
|
|
|
550
|
-
private :
|
|
512
|
+
private :element_normal_three_one
|
|
551
513
|
|
|
552
|
-
def
|
|
553
|
-
|
|
514
|
+
def element_normal_three_two
|
|
515
|
+
element_pattern_normal_three_two
|
|
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)
|
|
@@ -562,31 +522,31 @@ module Meteor
|
|
|
562
522
|
@res
|
|
563
523
|
end
|
|
564
524
|
|
|
565
|
-
private :
|
|
525
|
+
private :element_normal_three_two
|
|
566
526
|
|
|
567
|
-
def
|
|
527
|
+
def element_pattern_normal_three_two
|
|
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)
|
|
@@ -598,15 +558,15 @@ module Meteor
|
|
|
598
558
|
@pattern_cc = @sbuf
|
|
599
559
|
end
|
|
600
560
|
|
|
601
|
-
private :
|
|
561
|
+
private :element_pattern_normal_three_two
|
|
602
562
|
|
|
603
|
-
def
|
|
604
|
-
|
|
563
|
+
def element_void_three(name)
|
|
564
|
+
element_void_three_one(name, '"[^<>]*)\\/>')
|
|
605
565
|
end
|
|
606
566
|
|
|
607
|
-
private :
|
|
567
|
+
private :element_void_three
|
|
608
568
|
|
|
609
|
-
def
|
|
569
|
+
def element_void_three_one(name, closer)
|
|
610
570
|
# element (要素)
|
|
611
571
|
@elm_ = Meteor::Element.new(name)
|
|
612
572
|
# attribute (属性)
|
|
@@ -622,7 +582,7 @@ module Meteor
|
|
|
622
582
|
@elm_
|
|
623
583
|
end
|
|
624
584
|
|
|
625
|
-
private :
|
|
585
|
+
private :element_void_three_one
|
|
626
586
|
|
|
627
587
|
#
|
|
628
588
|
# get element using attribute(name="value") (属性(属性名="属性値")で検索し、要素を取得する)
|
|
@@ -630,76 +590,72 @@ module Meteor
|
|
|
630
590
|
# @param [String] attr_value attribute value (属性値)
|
|
631
591
|
# @return [Meteor::Element] element (要素)
|
|
632
592
|
#
|
|
633
|
-
def
|
|
593
|
+
def element_two(attr_name, attr_value)
|
|
634
594
|
quote_attribute(attr_name, attr_value)
|
|
635
595
|
|
|
636
|
-
|
|
596
|
+
element_pattern_two
|
|
637
597
|
|
|
638
598
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
|
639
599
|
@res = @pattern.match(@root.document)
|
|
640
600
|
|
|
641
601
|
if @res
|
|
642
|
-
|
|
602
|
+
element_three(@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_two_two
|
|
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_two
|
|
628
|
+
# else
|
|
629
|
+
# element_normal_two_one
|
|
630
|
+
# end
|
|
631
|
+
# elsif @res1.begin(0) > @res2.begin(0)
|
|
632
|
+
# @res = @res2
|
|
633
|
+
# # @pattern_cc = @pattern_cc_2
|
|
634
|
+
# element_normal_two_one
|
|
635
|
+
# end
|
|
636
|
+
# elsif @res1 && !@res2
|
|
637
|
+
# @res = @res1
|
|
638
|
+
# # @pattern_cc = @pattern_cc_1
|
|
639
|
+
# if @res[1]
|
|
640
|
+
# element_void_two
|
|
641
|
+
# else
|
|
642
|
+
# element_normal_two_one
|
|
643
|
+
# end
|
|
644
|
+
# elsif @res2 && !@res1
|
|
645
|
+
# @res = @res2
|
|
646
|
+
# # @pattern_cc = @pattern_cc_2
|
|
647
|
+
# element_normal_two_one
|
|
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
|
|
701
657
|
|
|
702
|
-
private :
|
|
658
|
+
private :element_two
|
|
703
659
|
|
|
704
660
|
def quote_name(name)
|
|
705
661
|
@_name = Regexp.quote(name)
|
|
@@ -714,142 +670,140 @@ module Meteor
|
|
|
714
670
|
|
|
715
671
|
private :quote_attribute
|
|
716
672
|
|
|
717
|
-
def
|
|
673
|
+
def element_pattern_two
|
|
718
674
|
# # @pattern_cc = String.new('') << '<([^<>"]*)\\s[^<>]*' << @_attr_name << '="' << @_attr_value << '(?:[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))'
|
|
719
675
|
# @pattern_cc = String.new('') << '<([^<>"]*)\\s[^<>]*' << @_attr_name << '="' << @_attr_value << '"'
|
|
720
676
|
@pattern_cc = "<([^<>\"]*)\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\""
|
|
721
677
|
end
|
|
722
678
|
|
|
723
|
-
private :
|
|
724
|
-
|
|
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
|
|
679
|
+
private :element_pattern_two
|
|
680
|
+
|
|
681
|
+
# def element_normal_two_one
|
|
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_two_one
|
|
744
|
+
#
|
|
745
|
+
# def element_normal_two_two
|
|
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_two(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_two_two
|
|
769
|
+
#
|
|
770
|
+
# def create_pattern_two(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_two
|
|
786
|
+
# element_void_two_one('"[^<>]*\\/>')
|
|
787
|
+
# end
|
|
788
|
+
#
|
|
789
|
+
# private :element_void_two
|
|
790
|
+
#
|
|
791
|
+
# def element_void_two_one(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_two_one
|
|
853
807
|
|
|
854
808
|
#
|
|
855
809
|
# get element using tag name and attribute1,2(name="value") (要素のタグ名と属性1・属性2(属性名="属性値")で検索し、要素を取得する)
|
|
@@ -860,8 +814,8 @@ module Meteor
|
|
|
860
814
|
# @param [String] attr_value2 attribute value2 (属性値2)
|
|
861
815
|
# @return [Meteor::Element] element (要素)
|
|
862
816
|
#
|
|
863
|
-
def
|
|
864
|
-
|
|
817
|
+
def element_five(name, attr_name1, attr_value1, attr_name2, attr_value2)
|
|
818
|
+
quote_element_five(name, attr_name1, attr_value1, attr_name2, attr_value2)
|
|
865
819
|
|
|
866
820
|
@pattern_cc_1 = "<#{@_name}(\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")[^<>]*)\\/>|<#{@_name}(\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")[^<>]*)>(((?!(#{@_name}[^<>]*>)).)*)<\\/#{@_name}>"
|
|
867
821
|
|
|
@@ -869,7 +823,7 @@ module Meteor
|
|
|
869
823
|
@res1 = @pattern.match(@root.document)
|
|
870
824
|
|
|
871
825
|
if @res1 && @res1[1] || !@res1
|
|
872
|
-
@res2 =
|
|
826
|
+
@res2 = element_normal_five_two
|
|
873
827
|
@pattern_cc_2 = @pattern_cc
|
|
874
828
|
|
|
875
829
|
# puts @res2.captures.length
|
|
@@ -881,31 +835,29 @@ module Meteor
|
|
|
881
835
|
@res = @res1
|
|
882
836
|
# @pattern_cc = @pattern_cc_1
|
|
883
837
|
if @res[1]
|
|
884
|
-
|
|
838
|
+
element_void_five(name)
|
|
885
839
|
else
|
|
886
|
-
|
|
840
|
+
element_normal_five_one(name)
|
|
887
841
|
end
|
|
888
842
|
elsif @res1.begin(0) > @res2.begin(0)
|
|
889
843
|
@res = @res2
|
|
890
844
|
# @pattern_cc = @pattern_cc_2
|
|
891
|
-
|
|
845
|
+
element_normal_five_one(name)
|
|
892
846
|
end
|
|
893
847
|
elsif @res1 && !@res2
|
|
894
848
|
@res = @res1
|
|
895
849
|
# @pattern_cc = @pattern_cc_1
|
|
896
850
|
if @res[1]
|
|
897
|
-
|
|
851
|
+
element_void_five(name)
|
|
898
852
|
else
|
|
899
|
-
|
|
853
|
+
element_normal_five_one(name)
|
|
900
854
|
end
|
|
901
855
|
elsif @res2 && !@res1
|
|
902
856
|
@res = @res2
|
|
903
857
|
# @pattern_cc = @pattern_cc_2
|
|
904
|
-
|
|
858
|
+
element_normal_five_one(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
|
|
@@ -913,9 +865,9 @@ module Meteor
|
|
|
913
865
|
@elm_
|
|
914
866
|
end
|
|
915
867
|
|
|
916
|
-
private :
|
|
868
|
+
private :element_five
|
|
917
869
|
|
|
918
|
-
def
|
|
870
|
+
def quote_element_five(name, attr_name1, attr_value1, attr_name2, attr_value2)
|
|
919
871
|
quote_name(name)
|
|
920
872
|
@_attr_name1 = Regexp.quote(attr_name1)
|
|
921
873
|
@_attr_name2 = Regexp.quote(attr_name2)
|
|
@@ -923,10 +875,9 @@ module Meteor
|
|
|
923
875
|
@_attr_value2 = Regexp.quote(attr_value2)
|
|
924
876
|
end
|
|
925
877
|
|
|
926
|
-
private :
|
|
927
|
-
|
|
928
|
-
def element_normal_5_1(name)
|
|
878
|
+
private :quote_element_five
|
|
929
879
|
|
|
880
|
+
def element_normal_five_one(name)
|
|
930
881
|
# puts @res.captures.length
|
|
931
882
|
case @res.captures.length
|
|
932
883
|
when FOUR
|
|
@@ -991,14 +942,12 @@ module Meteor
|
|
|
991
942
|
@elm_
|
|
992
943
|
end
|
|
993
944
|
|
|
994
|
-
private :
|
|
945
|
+
private :element_normal_five_one
|
|
995
946
|
|
|
996
|
-
def
|
|
997
|
-
|
|
947
|
+
def element_normal_five_two
|
|
948
|
+
element_pattern_normal_five_two
|
|
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)
|
|
@@ -1006,17 +955,16 @@ module Meteor
|
|
|
1006
955
|
@res
|
|
1007
956
|
end
|
|
1008
957
|
|
|
1009
|
-
private :
|
|
1010
|
-
|
|
1011
|
-
def element_pattern_normal_5_2
|
|
958
|
+
private :element_normal_five_two
|
|
1012
959
|
|
|
960
|
+
def element_pattern_normal_five_two
|
|
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)
|
|
@@ -1048,15 +996,15 @@ module Meteor
|
|
|
1048
996
|
@pattern_cc = @sbuf
|
|
1049
997
|
end
|
|
1050
998
|
|
|
1051
|
-
private :
|
|
999
|
+
private :element_pattern_normal_five_two
|
|
1052
1000
|
|
|
1053
|
-
def
|
|
1054
|
-
|
|
1001
|
+
def element_void_five(name)
|
|
1002
|
+
element_void_five_one(name, '")[^<>]*)\\/>')
|
|
1055
1003
|
end
|
|
1056
1004
|
|
|
1057
|
-
private :
|
|
1005
|
+
private :element_void_five
|
|
1058
1006
|
|
|
1059
|
-
def
|
|
1007
|
+
def element_void_five_one(name, closer)
|
|
1060
1008
|
# element (要素)
|
|
1061
1009
|
@elm_ = Meteor::Element.new(name)
|
|
1062
1010
|
# attribute (属性)
|
|
@@ -1076,7 +1024,7 @@ module Meteor
|
|
|
1076
1024
|
@elm_
|
|
1077
1025
|
end
|
|
1078
1026
|
|
|
1079
|
-
private :
|
|
1027
|
+
private :element_void_five_one
|
|
1080
1028
|
|
|
1081
1029
|
#
|
|
1082
1030
|
# get element using attribute1,2(name="value") (属性1・属性2(属性名="属性値")で検索し、要素を取得する)
|
|
@@ -1086,8 +1034,8 @@ module Meteor
|
|
|
1086
1034
|
# @param [String]attr_value2 attribute value2 (属性値2)
|
|
1087
1035
|
# @return [Meteor::Element] element (要素)
|
|
1088
1036
|
#
|
|
1089
|
-
def
|
|
1090
|
-
|
|
1037
|
+
def element_four(attr_name1, attr_value1, attr_name2, attr_value2)
|
|
1038
|
+
quote_element_four(attr_name1, attr_value1, attr_name2, attr_value2)
|
|
1091
1039
|
|
|
1092
1040
|
element_pattern_4
|
|
1093
1041
|
|
|
@@ -1095,8 +1043,8 @@ module Meteor
|
|
|
1095
1043
|
@res = @pattern.match(@root.document)
|
|
1096
1044
|
|
|
1097
1045
|
if @res
|
|
1098
|
-
# @elm_ =
|
|
1099
|
-
|
|
1046
|
+
# @elm_ = element_five(@res[1], attr_name1, attr_value1,attr_name2, attr_value2)
|
|
1047
|
+
element_five(@res[1], attr_name1, attr_value1, attr_name2, attr_value2)
|
|
1100
1048
|
else
|
|
1101
1049
|
if @error_check
|
|
1102
1050
|
puts(
|
|
@@ -1110,18 +1058,18 @@ module Meteor
|
|
|
1110
1058
|
@elm_
|
|
1111
1059
|
end
|
|
1112
1060
|
|
|
1113
|
-
private :
|
|
1061
|
+
private :element_four
|
|
1114
1062
|
|
|
1115
|
-
def
|
|
1063
|
+
def quote_element_four(attr_name1, attr_value1, attr_name2, attr_value2)
|
|
1116
1064
|
@_attr_name1 = Regexp.quote(attr_name1)
|
|
1117
1065
|
@_attr_name2 = Regexp.quote(attr_name2)
|
|
1118
1066
|
@_attr_value1 = Regexp.quote(attr_value1)
|
|
1119
1067
|
@_attr_value2 = Regexp.quote(attr_value2)
|
|
1120
1068
|
end
|
|
1121
1069
|
|
|
1122
|
-
private :
|
|
1070
|
+
private :quote_element_four
|
|
1123
1071
|
|
|
1124
|
-
def
|
|
1072
|
+
def element_pattern_four
|
|
1125
1073
|
# @pattern_cc = String.new('') << '<([^<>"]*)\\s([^<>]*(' << @_attr_name1 << '="'
|
|
1126
1074
|
# @pattern_cc << @_attr_value1 << '"[^<>]*' << @_attr_name2 << '="'
|
|
1127
1075
|
# @pattern_cc << @_attr_value2 << '"|' << @_attr_name2 << '="'
|
|
@@ -1130,7 +1078,7 @@ module Meteor
|
|
|
1130
1078
|
@pattern_cc = "<([^<>\"]*)\\s[^<>]*(#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")"
|
|
1131
1079
|
end
|
|
1132
1080
|
|
|
1133
|
-
private :
|
|
1081
|
+
private :element_pattern_four
|
|
1134
1082
|
|
|
1135
1083
|
def create_element_pattern
|
|
1136
1084
|
@position = 0
|
|
@@ -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
|
|
1180
|
-
|
|
1181
|
-
if @cnt != ZERO
|
|
1182
|
-
@sbuf << @pattern_cc_2_1
|
|
1183
|
-
else
|
|
1184
|
-
@sbuf << @pattern_cc_2_2
|
|
1185
|
-
break
|
|
1186
|
-
end
|
|
1187
|
-
|
|
1188
|
-
@position = @res.end(0)
|
|
1189
|
-
else
|
|
1190
|
-
break
|
|
1191
|
-
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
|
-
|
|
1210
|
-
if @res
|
|
1211
|
-
@position = @res.end(0)
|
|
1124
|
+
break unless @res
|
|
1212
1125
|
|
|
1213
|
-
|
|
1214
|
-
@sbuf << @pattern_cc_1_2
|
|
1215
|
-
@cnt += 1
|
|
1216
|
-
@position = @position2
|
|
1217
|
-
else
|
|
1218
|
-
@cnt -= ONE
|
|
1126
|
+
@cnt -= ONE
|
|
1219
1127
|
|
|
1220
|
-
|
|
1221
|
-
|
|
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
|
|
1128
|
+
if @cnt != ZERO
|
|
1129
|
+
@sbuf << @pattern_cc_2_1
|
|
1232
1130
|
else
|
|
1233
|
-
@
|
|
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
|
|
1131
|
+
@sbuf << @pattern_cc_2_2
|
|
1243
1132
|
break
|
|
1244
1133
|
end
|
|
1245
1134
|
|
|
1246
|
-
@
|
|
1135
|
+
@position = @res.end(0)
|
|
1247
1136
|
|
|
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_two(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_two(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,26 +1302,24 @@ 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
|
|
|
1366
1309
|
case args.size
|
|
1367
1310
|
when ONE
|
|
1368
|
-
@elm_ =
|
|
1311
|
+
@elm_ = element_one(*args)
|
|
1369
1312
|
when TWO
|
|
1370
|
-
@elm_ =
|
|
1313
|
+
@elm_ = element_two(*args)
|
|
1371
1314
|
when THREE
|
|
1372
|
-
@elm_ =
|
|
1315
|
+
@elm_ = element_three(*args)
|
|
1373
1316
|
when FOUR
|
|
1374
|
-
@elm_ =
|
|
1317
|
+
@elm_ = element_four(*args)
|
|
1375
1318
|
when FIVE
|
|
1376
|
-
@elm_ =
|
|
1319
|
+
@elm_ = element_five(*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
|
|
|
@@ -1395,23 +1336,23 @@ module Meteor
|
|
|
1395
1336
|
case args.size
|
|
1396
1337
|
when ONE
|
|
1397
1338
|
if @elm_.normal
|
|
1398
|
-
|
|
1339
|
+
element_normal_one(@elm_.name)
|
|
1399
1340
|
else
|
|
1400
|
-
|
|
1341
|
+
element_void_one(@elm_.name)
|
|
1401
1342
|
end
|
|
1402
1343
|
|
|
1403
1344
|
when TWO, THREE
|
|
1404
1345
|
if @elm_.normal
|
|
1405
|
-
|
|
1346
|
+
element_normal_three_one(@elm_.name)
|
|
1406
1347
|
else
|
|
1407
|
-
|
|
1348
|
+
element_void_three(@elm_.name)
|
|
1408
1349
|
end
|
|
1409
1350
|
|
|
1410
1351
|
when FOUR, FIVE
|
|
1411
1352
|
if @elm_.normal
|
|
1412
|
-
|
|
1353
|
+
element_normal_five_one(@elm_.name)
|
|
1413
1354
|
else
|
|
1414
|
-
|
|
1355
|
+
element_void_five(@elm_.name)
|
|
1415
1356
|
end
|
|
1416
1357
|
end
|
|
1417
1358
|
|
|
@@ -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,29 +1432,29 @@ 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_three(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_three(elm, attr.keys[0].to_s, attr.values[0])
|
|
1548
1451
|
else
|
|
1549
1452
|
remove_attr(elm, attr.keys[0].to_s)
|
|
1550
1453
|
end
|
|
1551
1454
|
# elsif attrs.kind_of?(Hash) && attrs.size >= 1
|
|
1552
1455
|
# elm.document_sync = true
|
|
1553
1456
|
# attrs.each{|name,value|
|
|
1554
|
-
#
|
|
1457
|
+
# set_attribute_three(elm,name,value)
|
|
1555
1458
|
# }
|
|
1556
1459
|
else
|
|
1557
1460
|
raise ArgumentError
|
|
@@ -1565,8 +1468,8 @@ module Meteor
|
|
|
1565
1468
|
# @param [String,true,false] attr_value attribute value (属性値)
|
|
1566
1469
|
# @return [Meteor::Element] element (要素)
|
|
1567
1470
|
#
|
|
1568
|
-
def
|
|
1569
|
-
|
|
1471
|
+
def set_attribute_three(elm, attr_name, attr_value)
|
|
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)
|
|
@@ -1575,33 +1478,32 @@ module Meteor
|
|
|
1575
1478
|
elm
|
|
1576
1479
|
end
|
|
1577
1480
|
|
|
1578
|
-
private :
|
|
1481
|
+
private :set_attribute_three
|
|
1579
1482
|
|
|
1580
1483
|
def edit_attrs_(elm, attr_name, attr_value)
|
|
1581
1484
|
# attribute search (属性検索)
|
|
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_three(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,10 +1589,10 @@ 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_three(elm, name.to_s, value)
|
|
1697
1596
|
end
|
|
1698
1597
|
end
|
|
1699
1598
|
|
|
@@ -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)
|
|
@@ -1790,20 +1689,20 @@ module Meteor
|
|
|
1790
1689
|
case args.length
|
|
1791
1690
|
when ONE
|
|
1792
1691
|
# if args[0].kind_of?(Meteor::Element)
|
|
1793
|
-
|
|
1692
|
+
get_content_one(args[0])
|
|
1794
1693
|
# else
|
|
1795
1694
|
# raise ArgumentError
|
|
1796
1695
|
# end
|
|
1797
1696
|
when TWO
|
|
1798
1697
|
# if args[0].kind_of?(Meteor::Element) && args[1].kind_of?(String)
|
|
1799
1698
|
args[0].document_sync = true
|
|
1800
|
-
|
|
1699
|
+
set_content_two(args[0], args[1].to_s)
|
|
1801
1700
|
# else
|
|
1802
1701
|
# raise ArgumentError
|
|
1803
1702
|
# end
|
|
1804
1703
|
when THREE
|
|
1805
1704
|
args[0].document_sync = true
|
|
1806
|
-
|
|
1705
|
+
set_content_three(args[0], args[1].to_s, args[2])
|
|
1807
1706
|
else
|
|
1808
1707
|
raise ArgumentError
|
|
1809
1708
|
end
|
|
@@ -1816,16 +1715,14 @@ module Meteor
|
|
|
1816
1715
|
# @param [true,false] entity_ref entity reference flag (エンティティ参照フラグ)
|
|
1817
1716
|
# @return [Meteor::Element] element (要素)
|
|
1818
1717
|
#
|
|
1819
|
-
def
|
|
1820
|
-
if entity_ref || !elm.raw_content
|
|
1821
|
-
escape_content(content, elm)
|
|
1822
|
-
end
|
|
1718
|
+
def set_content_three(elm, content, entity_ref = true)
|
|
1719
|
+
escape_content(content, elm) if entity_ref || !elm.raw_content
|
|
1823
1720
|
|
|
1824
1721
|
elm.mixed_content = content
|
|
1825
1722
|
elm
|
|
1826
1723
|
end
|
|
1827
1724
|
|
|
1828
|
-
private :
|
|
1725
|
+
private :set_content_three
|
|
1829
1726
|
|
|
1830
1727
|
#
|
|
1831
1728
|
# set content of element (要素の内容をセットする)
|
|
@@ -1833,36 +1730,30 @@ module Meteor
|
|
|
1833
1730
|
# @param [String] content content of element (要素の内容)
|
|
1834
1731
|
# @return [Meteor::Element] element (要素)
|
|
1835
1732
|
#
|
|
1836
|
-
def
|
|
1837
|
-
#
|
|
1838
|
-
unless elm.raw_content
|
|
1839
|
-
escape_content(content, elm)
|
|
1840
|
-
end
|
|
1733
|
+
def set_content_two(elm, content)
|
|
1734
|
+
# set_content_three(elm, content)
|
|
1735
|
+
escape_content(content, elm) unless elm.raw_content
|
|
1841
1736
|
|
|
1842
1737
|
elm.mixed_content = content
|
|
1843
1738
|
elm
|
|
1844
1739
|
end
|
|
1845
1740
|
|
|
1846
|
-
private :
|
|
1741
|
+
private :set_content_two
|
|
1847
1742
|
|
|
1848
1743
|
#
|
|
1849
1744
|
# get content of element (要素の内容を取得する)
|
|
1850
1745
|
# @param [Meteor::Element] elm element (要素)
|
|
1851
1746
|
# @return [String] content (内容)
|
|
1852
1747
|
#
|
|
1853
|
-
def
|
|
1748
|
+
def get_content_one(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
|
|
1863
1754
|
end
|
|
1864
1755
|
|
|
1865
|
-
private :
|
|
1756
|
+
private :get_content_one
|
|
1866
1757
|
|
|
1867
1758
|
#
|
|
1868
1759
|
# remove attribute of element (要素の属性を消す)
|
|
@@ -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_
|
|
@@ -1913,15 +1804,11 @@ module Meteor
|
|
|
1913
1804
|
def cxtag(*args)
|
|
1914
1805
|
case args.length
|
|
1915
1806
|
when ONE
|
|
1916
|
-
|
|
1917
|
-
if @elm_
|
|
1918
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
|
1919
|
-
end
|
|
1807
|
+
cxtag_one(args[0].to_s)
|
|
1808
|
+
@element_cache.store(@elm_.object_id, @elm_) if @elm_
|
|
1920
1809
|
when TWO
|
|
1921
|
-
|
|
1922
|
-
if @elm_
|
|
1923
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
|
1924
|
-
end
|
|
1810
|
+
cxtag_two(args[0].to_s, args[1].to_s)
|
|
1811
|
+
@element_cache.store(@elm_.object_id, @elm_) if @elm_
|
|
1925
1812
|
else
|
|
1926
1813
|
raise ArgumentError
|
|
1927
1814
|
end
|
|
@@ -1933,7 +1820,7 @@ module Meteor
|
|
|
1933
1820
|
# @param [String] id id attribute value (ID属性値)
|
|
1934
1821
|
# @return [Meteor::Element] element (要素)
|
|
1935
1822
|
#
|
|
1936
|
-
def
|
|
1823
|
+
def cxtag_two(name, id)
|
|
1937
1824
|
quote_name(name)
|
|
1938
1825
|
@_id = Regexp.quote(id)
|
|
1939
1826
|
|
|
@@ -1971,17 +1858,17 @@ module Meteor
|
|
|
1971
1858
|
@elm_
|
|
1972
1859
|
end
|
|
1973
1860
|
|
|
1974
|
-
private :
|
|
1861
|
+
private :cxtag_two
|
|
1975
1862
|
|
|
1976
1863
|
#
|
|
1977
1864
|
# get cx(comment extension) tag using id attribute (ID属性(id="ID属性値")で検索し、CX(コメント拡張)タグを取得する)
|
|
1978
1865
|
# @param [String] id id attribute value (ID属性値)
|
|
1979
1866
|
# @return [Meteor::Element] element (要素)
|
|
1980
1867
|
#
|
|
1981
|
-
def
|
|
1868
|
+
def cxtag_one(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)
|
|
@@ -1998,7 +1885,7 @@ module Meteor
|
|
|
1998
1885
|
@elm_
|
|
1999
1886
|
end
|
|
2000
1887
|
|
|
2001
|
-
private :
|
|
1888
|
+
private :cxtag_one
|
|
2002
1889
|
|
|
2003
1890
|
#
|
|
2004
1891
|
# replace element (要素を置換する)
|
|
@@ -2016,95 +1903,94 @@ 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_one(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
|
-
def
|
|
2044
|
-
|
|
1930
|
+
def edit_document_one(elm)
|
|
1931
|
+
edit_document_two(elm, '/>')
|
|
2045
1932
|
end
|
|
2046
1933
|
|
|
2047
|
-
private :
|
|
1934
|
+
private :edit_document_one
|
|
2048
1935
|
|
|
2049
|
-
def
|
|
1936
|
+
def edit_document_two(elm, _closer)
|
|
2050
1937
|
# replace tag (タグ置換)
|
|
2051
1938
|
@pattern = Meteor::Core::Util::PatternCache.get(elm.pattern)
|
|
2052
1939
|
@root.document.sub!(@pattern, elm.document)
|
|
2053
1940
|
end
|
|
2054
1941
|
|
|
2055
|
-
private :
|
|
1942
|
+
private :edit_document_two
|
|
2056
1943
|
|
|
2057
1944
|
#
|
|
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_)
|