meteor 0.9.7.5 → 0.9.8
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 +7 -0
- data/.gitignore +7 -0
- data/ChangeLog +4 -0
- data/Gemfile +4 -0
- data/README.md +37 -0
- data/Rakefile +4 -4
- data/demo/demo_html.rb +133 -0
- data/demo/demo_html5.rb +102 -0
- data/demo/demo_xhtml.rb +102 -0
- data/demo/demo_xhtml5.rb +107 -0
- data/demo/demo_xml.rb +123 -0
- data/demo/sample.html +40 -0
- data/demo/sample.xml +50 -0
- data/demo/sample_5.html +32 -0
- data/demo/sample_x.html +33 -0
- data/demo/sample_x5.html +33 -0
- data/lib/meteor.rb +1207 -1407
- data/meteor.gemspec +25 -0
- metadata +52 -30
- data/README +0 -30
data/demo/demo_xhtml5.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
#!bin ruby
|
2
|
+
# -* coding: UTF-8 -*-
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'meteor'
|
6
|
+
|
7
|
+
#pf = Meteor::ParserFactory.new
|
8
|
+
#pf.bind(Meteor::Parser::XHTML5,"sample_x5.html", "UTF-8")
|
9
|
+
|
10
|
+
#root = pf.element('sample_x5')
|
11
|
+
|
12
|
+
Meteor::ElementFactory.bind(Meteor::Parser::XHTML5,'sample_x5.html', 'UTF-8')
|
13
|
+
root = Meteor::ElementFactory.element('sample_x5')
|
14
|
+
|
15
|
+
startTime = Time.new.to_f
|
16
|
+
|
17
|
+
elm_hello = root.element("id","hello")
|
18
|
+
#elm_hello.attr("color"=>"red")
|
19
|
+
elm_hello['color'] = 'red'
|
20
|
+
#elm_hello.remove_attr('color')
|
21
|
+
|
22
|
+
elm_hello2 = root.element("id"=>"hello2")
|
23
|
+
#elm_hello2.content("Hello,Tester")
|
24
|
+
elm_hello2.content = "Hello,Tester"
|
25
|
+
|
26
|
+
#elm_hello2.remove
|
27
|
+
#elm_hello3 = root.cxtag("hello3")
|
28
|
+
##elm_hello3.content("Hello,Hello\ntt")
|
29
|
+
#elm_hello3.content = "Hello,Hello\ntt"
|
30
|
+
#puts elm_hello3.content
|
31
|
+
#puts elm_hello3.mixed_content
|
32
|
+
|
33
|
+
elm_text1 = root.element('id'=>'text1')
|
34
|
+
#elm_text1.attr("value","めも")
|
35
|
+
elm_text1['value'] = 'めも'
|
36
|
+
#elm_text1.attr("disabled"=>true)
|
37
|
+
elm_text1['disabled'] = true
|
38
|
+
#elm_text1.attr('required'=>true)
|
39
|
+
elm_text1['required'] = true
|
40
|
+
#map = elm_text1.attr_map
|
41
|
+
#map.names.each { |item|
|
42
|
+
# puts item
|
43
|
+
# puts map.fetch(item)
|
44
|
+
#}
|
45
|
+
|
46
|
+
#elm_radio1 = root.element("input","id"=>"radio1","type"=>"radio")
|
47
|
+
##elm_radio1.attr("checked"=>"true")
|
48
|
+
#elm_radio1['checked'] = true
|
49
|
+
|
50
|
+
#elm_select1 = root.element("select","id"=>"select1")
|
51
|
+
#elm_select1 = root.element("select")
|
52
|
+
##elm_select1.attr("multiple"=>true)
|
53
|
+
#elm_select1['multiple'] = true
|
54
|
+
##puts elm_select1.attr("multiple")
|
55
|
+
#puts elm_select1['multiple']
|
56
|
+
#elm_option1 = root.element("option","id"=>"option1")
|
57
|
+
##elm_option1.attr("selected"=>"true")
|
58
|
+
#elm_option1['selected'] = true
|
59
|
+
##puts elm_option1.attr("selected")
|
60
|
+
#puts elm_option1['selected']
|
61
|
+
##puts elm_text1.attr("readonly")
|
62
|
+
#puts elm_text1['readonly']
|
63
|
+
|
64
|
+
#elm_select2 = root.element("select","id"=>"select2")
|
65
|
+
#elm_select2["multiple"] = "true"
|
66
|
+
#elm_option2 = root.element("option","id"=>"option2")
|
67
|
+
#co_ps = elm_option2.element()
|
68
|
+
#10.times { |i|
|
69
|
+
# if i == 1 then
|
70
|
+
# #co_ps.attr("selected"=>"true")
|
71
|
+
# co_ps['selected'] = true
|
72
|
+
# else
|
73
|
+
# #co_ps.attr("selected"=>"false")
|
74
|
+
# co_ps['selected'] = false
|
75
|
+
# end
|
76
|
+
# #co_ps.attr("value"=>i.to_s)
|
77
|
+
# co_ps['value'] = i.to_s
|
78
|
+
# co_ps.remove_attr("id")
|
79
|
+
# #co_ps.content(i.to_s)
|
80
|
+
# co_ps.content = i.to_s
|
81
|
+
# co_ps.flush
|
82
|
+
#}
|
83
|
+
|
84
|
+
elm_tr1 = root.element('tr','id'=>'loop')
|
85
|
+
elm_ = elm_tr1.element
|
86
|
+
elm_dt1_ = elm_.element('id'=>'aa')
|
87
|
+
elm_dt2_ = elm_.element('id'=>'bb')
|
88
|
+
elm_dt3_ = elm_.element('id'=>'cc')
|
89
|
+
10.times { |i|
|
90
|
+
elm_['loop'] = i.to_s
|
91
|
+
elm_dt1 = elm_dt1_.clone
|
92
|
+
elm_dt2 = elm_dt2_.clone
|
93
|
+
elm_dt3 = elm_dt3_.clone
|
94
|
+
#elm_dt1.content("<>\"' \n" << i.to_s)
|
95
|
+
elm_dt1.content=i.to_s
|
96
|
+
elm_dt2.content=i.to_s
|
97
|
+
elm_dt3.content=i.to_s
|
98
|
+
elm_.flush
|
99
|
+
}
|
100
|
+
|
101
|
+
root.flush
|
102
|
+
|
103
|
+
endTime = Time.new.to_f
|
104
|
+
|
105
|
+
puts root.document
|
106
|
+
|
107
|
+
puts '' + (endTime - startTime).to_s + ' sec'
|
data/demo/demo_xml.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
#!bin ruby
|
2
|
+
# -* coding: UTF-8 -*-
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'meteor'
|
6
|
+
|
7
|
+
#pf = Meteor::ParserFactory.new
|
8
|
+
#pf.parser(Meteor::Parser::XML,'sample.xml', 'UTF-8')
|
9
|
+
#pf.bind(Meteor::Parser::XML,'sample.xml')
|
10
|
+
|
11
|
+
#root = pf.element('sample')
|
12
|
+
|
13
|
+
Meteor::ElementFactory.bind(Meteor::XML,'sample.xml', 'UTF-8')
|
14
|
+
root = Meteor::ElementFactory.element('sample')
|
15
|
+
|
16
|
+
start_time = Time.new.to_f
|
17
|
+
|
18
|
+
#elm_ = root.element('test1')
|
19
|
+
#puts elm_.name
|
20
|
+
#puts elm_.attributes
|
21
|
+
#puts elm_.mixed_content
|
22
|
+
|
23
|
+
#elm_ = root.element('test')
|
24
|
+
#puts elm_.name
|
25
|
+
#puts elm_.attributes
|
26
|
+
#puts elm_.mixed_content
|
27
|
+
|
28
|
+
elm1 = root.element('test','manbo'=>'manbo')
|
29
|
+
#elm1 = root.element("manbo"=>"manbo")
|
30
|
+
#elm2 = root.element("id"=>"aa","id2"=>"bb")
|
31
|
+
#elm2 = root.element("id"=>"aa")
|
32
|
+
#elm3 = root.element("potato","id"=>"aa")
|
33
|
+
#elm4 = root.element("potato","id"=>"aa","id2"=>"bb")
|
34
|
+
#elm4 = root.element("potato","id2"=>"bb")
|
35
|
+
elm7 = root.element("kobe")
|
36
|
+
#elm7 = root.element("momo"=>"mono")
|
37
|
+
#elm8 = root.element("manbo"=>"mango")
|
38
|
+
#elm8 = root.element("momo"=>"momo")
|
39
|
+
|
40
|
+
#elm9 = root.element("hamachi","id"=>"aa",'id2'=>'bb')
|
41
|
+
#elm_c1 = root.cxtag("cs")
|
42
|
+
|
43
|
+
#elm8.attr("manbo"=>"mangoo")
|
44
|
+
|
45
|
+
#puts elm8.name
|
46
|
+
#puts elm8.attributes
|
47
|
+
#puts elm8.mixed_content
|
48
|
+
|
49
|
+
#elm1.attr("id2"=>"cc")
|
50
|
+
#elm1["id2"]="cc"
|
51
|
+
|
52
|
+
#elm8.attr("manbo"=>"mangoo")
|
53
|
+
##elm9.content("\\1")
|
54
|
+
#elm9.content = "\\1"
|
55
|
+
|
56
|
+
#elm2.attr('id3'=>'cc')
|
57
|
+
#elm3.attr('id3'=>'cc')
|
58
|
+
#elm3['id3'] = 'cc'
|
59
|
+
#elm4.attr('id3'=>'cc')
|
60
|
+
#elm9.attr('id3'=>'cc')
|
61
|
+
|
62
|
+
#co_ps = elm1.element()
|
63
|
+
#map = co_ps.attr_map
|
64
|
+
#map.names.each { |item|
|
65
|
+
# puts item
|
66
|
+
# puts map.fetch(item)
|
67
|
+
#}
|
68
|
+
|
69
|
+
elm_ = root.element(elm1)
|
70
|
+
elm5_ = elm_.element('tech')
|
71
|
+
10.times do |i|
|
72
|
+
elm_['manbo'] = i.to_s
|
73
|
+
elm5 = elm5_.clone
|
74
|
+
elm5['mono'] = i.to_s
|
75
|
+
elm5.content = i.to_s
|
76
|
+
elm_.flush
|
77
|
+
end
|
78
|
+
|
79
|
+
#am3 = elm3.attr_map
|
80
|
+
#am3.names.each { |item|
|
81
|
+
# puts item
|
82
|
+
# puts am3.fetch(item)
|
83
|
+
#}
|
84
|
+
|
85
|
+
elm_ = root.element(elm7)
|
86
|
+
|
87
|
+
10.times { |i|
|
88
|
+
elm_["momo"]= i.to_s
|
89
|
+
elm_["eco"] = "えま"
|
90
|
+
elm_.content = i.to_s
|
91
|
+
#elm_["content"] = i.to_s
|
92
|
+
elm_.flush
|
93
|
+
}
|
94
|
+
|
95
|
+
#co_ps = root.element(elm_c1)
|
96
|
+
#
|
97
|
+
#10.times { |i|
|
98
|
+
# #co_ps.content(i.to_s)
|
99
|
+
# co_ps[":content"]=i.to_s
|
100
|
+
# co_ps.flush
|
101
|
+
#}
|
102
|
+
|
103
|
+
root.flush
|
104
|
+
|
105
|
+
#elm3.attr('id3'=>'dd')
|
106
|
+
|
107
|
+
end_time = Time.new.to_f
|
108
|
+
|
109
|
+
puts root.document
|
110
|
+
|
111
|
+
puts '' + (end_time - start_time).to_s + ' sec'
|
112
|
+
|
113
|
+
#start_time = Time.new.to_f
|
114
|
+
#obj = eval("\"#{elm3.name}\"")
|
115
|
+
#end_time = Time.new.to_f
|
116
|
+
#puts '' + (end_time - start_time).to_s + ' sec'
|
117
|
+
#puts obj
|
118
|
+
|
119
|
+
#start_time = Time.new.to_f
|
120
|
+
#obj = elm3.name
|
121
|
+
#end_time = Time.new.to_f
|
122
|
+
#puts '' + (end_time - start_time).to_s + ' sec'
|
123
|
+
#puts obj
|
data/demo/sample.html
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>HTMLテスト</title>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
5
|
+
</head>
|
6
|
+
|
7
|
+
<body bgcolor="#FFFFFF" text="#000000">
|
8
|
+
<font id="hello" color="#000000">Hello,World</font>
|
9
|
+
<font id="hello2">Hello,World</font>
|
10
|
+
<!-- @quark id="hello3" -->Hello,World<!-- /@quark -->
|
11
|
+
<form>
|
12
|
+
<input id="text1" type="text" >
|
13
|
+
|
14
|
+
<input id="radio1" type="radio" class="test">
|
15
|
+
|
16
|
+
<select id="select1">
|
17
|
+
<option id="option1">オプション</option>
|
18
|
+
</select>
|
19
|
+
|
20
|
+
<select id="select2">
|
21
|
+
<option id="option2">オプション</option>
|
22
|
+
</select>
|
23
|
+
</form>
|
24
|
+
|
25
|
+
<table>
|
26
|
+
<tr id="loop">
|
27
|
+
<td id="aa"></td><td id="bb"></td><td id="cc"></td>
|
28
|
+
</tr>
|
29
|
+
</table>
|
30
|
+
|
31
|
+
<div id="sample" style="test" >
|
32
|
+
<div>test</div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="sample" style="test" class="test">
|
36
|
+
<div>test</div>
|
37
|
+
</div>
|
38
|
+
|
39
|
+
</body>
|
40
|
+
</html>
|
data/demo/sample.xml
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
|
3
|
+
<!--
|
4
|
+
Document : test.xml
|
5
|
+
Created on : 2008/07/22, 17:32
|
6
|
+
Author : asip
|
7
|
+
Description:
|
8
|
+
Purpose of the document follows.
|
9
|
+
-->
|
10
|
+
|
11
|
+
<root>
|
12
|
+
|
13
|
+
<test1 manbo="mango" />
|
14
|
+
|
15
|
+
<test manbo="manbo">
|
16
|
+
<tech mono="mono">こまねち</tech>
|
17
|
+
</test>
|
18
|
+
<test manbo="mbo">
|
19
|
+
<tech mono="mono">komaneti</tech>
|
20
|
+
</test>
|
21
|
+
<test manbo="mbo">
|
22
|
+
<tech mono="mono2">komaneti</tech>
|
23
|
+
</test>
|
24
|
+
<!-- @quark id="mono" --><!-- /@quark -->
|
25
|
+
<!-- @quark id="moti" --><!-- /@quark -->
|
26
|
+
<momo>komaneti</momo>
|
27
|
+
<kobe momo="mono">komaneti</kobe>
|
28
|
+
<teo a="aa" b="bb"/>
|
29
|
+
<mink>komaneti</mink>
|
30
|
+
|
31
|
+
<potato id="aa" lc="/cc">
|
32
|
+
<potato id="/bb"><test></test></potato>
|
33
|
+
</potato>
|
34
|
+
|
35
|
+
<potato id="aa" id2="bb" lc="/cc">
|
36
|
+
<potato id="/bb"><test></test></potato>
|
37
|
+
</potato>
|
38
|
+
|
39
|
+
<potato2 id="aa" id2="bb" lc="/cc"/>
|
40
|
+
|
41
|
+
<hamachi id="aa" id2="bb" lc="/cc">
|
42
|
+
test
|
43
|
+
</hamachi>
|
44
|
+
|
45
|
+
<hamachi id="aa" id2="bb" />
|
46
|
+
|
47
|
+
<kobe momo="momo" value="komaneti" />
|
48
|
+
<!-- @pp id="cs" -->テスト<!-- /@pp -->
|
49
|
+
|
50
|
+
</root>
|
data/demo/sample_5.html
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>HTMLテスト</title>
|
4
|
+
<meta http-equiv="Content-Type" charset="utf-8" content="text/html; charset=UTF-8">
|
5
|
+
</head>
|
6
|
+
|
7
|
+
<body bgcolor="#FFFFFF" text="#000000">
|
8
|
+
<font id="hello" color="#000000">Hello,World</font>
|
9
|
+
<font id="hello2">Hello,World</font>
|
10
|
+
<!-- @quark id="hello3" -->Hello,World<!-- /@quark -->
|
11
|
+
<form>
|
12
|
+
<input id="text1" type="text" >
|
13
|
+
|
14
|
+
<input id="radio1" type="radio">
|
15
|
+
|
16
|
+
<select>
|
17
|
+
<option id="option1">オプション</option>
|
18
|
+
</select>
|
19
|
+
|
20
|
+
<select id="select2">
|
21
|
+
<option id="option2">オプション</option>
|
22
|
+
</select>
|
23
|
+
</form>
|
24
|
+
|
25
|
+
<table>
|
26
|
+
<tr id="loop">
|
27
|
+
<td id="aa"></td><td id="bb"></td><td id="cc"></td>
|
28
|
+
</tr>
|
29
|
+
</table>
|
30
|
+
|
31
|
+
</body>
|
32
|
+
</html>
|
data/demo/sample_x.html
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>HTMLテスト</title>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
6
|
+
</head>
|
7
|
+
|
8
|
+
<body bgcolor="#FFFFFF" text="#000000">
|
9
|
+
<font id="hello" color="#000000">Hello,World</font>
|
10
|
+
<font id="hello2">Hello,World</font>
|
11
|
+
<!-- @quark id="hello3" -->Hello,World<!-- /@quark -->
|
12
|
+
<form>
|
13
|
+
<input id="text1" type="text" />
|
14
|
+
|
15
|
+
<input id="radio1" type="radio" />
|
16
|
+
|
17
|
+
<select>
|
18
|
+
<option id="option1">オプション</option>
|
19
|
+
</select>
|
20
|
+
|
21
|
+
<select id="select2">
|
22
|
+
<option id="option2">オプション</option>
|
23
|
+
</select>
|
24
|
+
</form>
|
25
|
+
|
26
|
+
<table>
|
27
|
+
<tr id="loop">
|
28
|
+
<td id="aa"></td><td id="bb"></td><td id="cc"></td>
|
29
|
+
</tr>
|
30
|
+
</table>
|
31
|
+
|
32
|
+
</body>
|
33
|
+
</html>
|
data/demo/sample_x5.html
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>HTMLテスト</title>
|
5
|
+
<meta http-equiv="Content-Type" charset="utf-8" content="text/html; charset=UTF-8"/>
|
6
|
+
</head>
|
7
|
+
|
8
|
+
<body bgcolor="#FFFFFF" text="#000000">
|
9
|
+
<font id="hello" color="#000000">Hello,World</font>
|
10
|
+
<font id="hello2">Hello,World</font>
|
11
|
+
<!-- @quark id="hello3" -->Hello,World<!-- /@quark -->
|
12
|
+
<form>
|
13
|
+
<input id="text1" type="text" />
|
14
|
+
|
15
|
+
<input id="radio1" type="radio" />
|
16
|
+
|
17
|
+
<select>
|
18
|
+
<option id="option1">オプション</option>
|
19
|
+
</select>
|
20
|
+
|
21
|
+
<select id="select2">
|
22
|
+
<option id="option2">オプション</option>
|
23
|
+
</select>
|
24
|
+
</form>
|
25
|
+
|
26
|
+
<table>
|
27
|
+
<tr id="loop">
|
28
|
+
<td id="aa"></td><td id="bb"></td><td id="cc"></td>
|
29
|
+
</tr>
|
30
|
+
</table>
|
31
|
+
|
32
|
+
</body>
|
33
|
+
</html>
|
data/lib/meteor.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -* coding: UTF-8 -*-
|
2
2
|
# Meteor - A lightweight (X)HTML(5) & XML parser
|
3
3
|
#
|
4
|
-
# Copyright (C) 2008-
|
4
|
+
# Copyright (C) 2008-2014 Yasumasa Ashida.
|
5
5
|
#
|
6
6
|
# This program is free software; you can redistribute it and/or modify
|
7
7
|
# it under the terms of the GNU Lesser General Public License as published by
|
@@ -18,20 +18,14 @@
|
|
18
18
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
19
|
#
|
20
20
|
# @author Yasumasa Ashida
|
21
|
-
# @version 0.9.
|
21
|
+
# @version 0.9.8
|
22
22
|
#
|
23
23
|
|
24
24
|
module Meteor
|
25
25
|
|
26
|
-
VERSION =
|
26
|
+
VERSION = '0.9.8'
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
if RUBY_VERSION < RUBY_VERSION_1_9_0 then
|
31
|
-
require 'Kconv'
|
32
|
-
#E_UTF8 = 'UTF8'
|
33
|
-
$KCODE = 'UTF8'
|
34
|
-
end
|
28
|
+
#require 'fileutils'
|
35
29
|
|
36
30
|
ZERO = 0
|
37
31
|
ONE = 1
|
@@ -51,8 +45,55 @@ module Meteor
|
|
51
45
|
#
|
52
46
|
# Element Class (要素クラス)
|
53
47
|
#
|
48
|
+
# @!attribute [rw] name
|
49
|
+
# @return [String] tag name (要素名)
|
50
|
+
# @!attribute [rw] attributes
|
51
|
+
# @return [String] attributes (属性群)
|
52
|
+
# @!attribute [rw] mixed_content
|
53
|
+
# @return [String] content (内容)
|
54
|
+
# @!attribute [rw] pattern
|
55
|
+
# @return [String] pattern (パターン)
|
56
|
+
# @!attribute [rw] document_sync
|
57
|
+
# @return [true,false] document update flag (ドキュメント更新フラグ)
|
58
|
+
# @!attribute [rw] empty
|
59
|
+
# @return [true,false] content empty flag (内容存在フラグ)
|
60
|
+
# @!attribute [rw] cx
|
61
|
+
# @return [true,false] comment extension tag flag (コメント拡張タグフラグ)
|
62
|
+
# @!attribute [rw] mono
|
63
|
+
# @return [true,false] child element existance flag (子要素存在フラグ)
|
64
|
+
# @!attribute [rw] parser
|
65
|
+
# @return [Meteor::Parser] parser(パーサ)
|
66
|
+
# @!attribute [rw] type_value
|
67
|
+
# @return [String] type (タイプ属性)
|
68
|
+
# @!attribute [rw] usable
|
69
|
+
# @return [true,false] usable flag (有効・無効フラグ)
|
70
|
+
# @!attribute [rw] origin
|
71
|
+
# @return [Meteor::Element] original pointer (原本ポインタ)
|
72
|
+
# @!attribute [rw] copy
|
73
|
+
# @return [Meteor::Element] copy pointer (複製ポインタ)
|
74
|
+
# @!attribute [rw] removed
|
75
|
+
# @return [true,false] delete flag (削除フラグ)
|
76
|
+
#
|
54
77
|
class Element
|
55
78
|
|
79
|
+
attr_accessor :tag
|
80
|
+
attr_accessor :attributes
|
81
|
+
attr_accessor :mixed_content
|
82
|
+
attr_accessor :pattern
|
83
|
+
attr_accessor :document_sync
|
84
|
+
attr_accessor :empty
|
85
|
+
attr_accessor :cx
|
86
|
+
attr_accessor :mono
|
87
|
+
attr_accessor :parser
|
88
|
+
attr_accessor :type_value
|
89
|
+
attr_accessor :usable
|
90
|
+
attr_accessor :origin
|
91
|
+
attr_accessor :copy
|
92
|
+
attr_accessor :removed
|
93
|
+
|
94
|
+
alias :name :tag
|
95
|
+
alias :name= :tag=
|
96
|
+
|
56
97
|
#
|
57
98
|
# initializer (イニシャライザ)
|
58
99
|
# @overload initialize(tag)
|
@@ -66,7 +107,7 @@ module Meteor
|
|
66
107
|
def initialize(*args)
|
67
108
|
case args.length
|
68
109
|
when ONE
|
69
|
-
if args[0].kind_of?(String)
|
110
|
+
if args[0].kind_of?(String)
|
70
111
|
initialize_s(args[0])
|
71
112
|
elsif args[0].kind_of?(Meteor::Element)
|
72
113
|
initialize_e(args[0])
|
@@ -74,7 +115,7 @@ module Meteor
|
|
74
115
|
raise ArgumentError
|
75
116
|
end
|
76
117
|
when TWO
|
77
|
-
@
|
118
|
+
@tag = args[0].tag
|
78
119
|
@attributes = String.new(args[0].attributes)
|
79
120
|
@mixed_content = String.new(args[0].mixed_content)
|
80
121
|
#@pattern = String.new(args[0].pattern)
|
@@ -98,7 +139,7 @@ module Meteor
|
|
98
139
|
# @param [String] tag tag name (タグ名)
|
99
140
|
#
|
100
141
|
def initialize_s(tag)
|
101
|
-
@
|
142
|
+
@tag = tag
|
102
143
|
#@attributes = nil
|
103
144
|
#@mixed_content = nil
|
104
145
|
#@pattern = nil
|
@@ -118,7 +159,7 @@ module Meteor
|
|
118
159
|
# @param [Meteor::Element] elm element (要素)
|
119
160
|
#
|
120
161
|
def initialize_e(elm)
|
121
|
-
@
|
162
|
+
@tag = elm.tag
|
122
163
|
@attributes = String.new(elm.attributes)
|
123
164
|
#@pattern = String.new(elm.pattern)
|
124
165
|
@pattern = elm.pattern
|
@@ -144,7 +185,7 @@ module Meteor
|
|
144
185
|
case args.length
|
145
186
|
when TWO
|
146
187
|
@obj = args[1].element_hook
|
147
|
-
if @obj
|
188
|
+
if @obj
|
148
189
|
@obj.attributes = String.new(args[0].attributes)
|
149
190
|
@obj.mixed_content = String.new(args[0].mixed_content)
|
150
191
|
#@obj.pattern = String.new(args[0].pattern)
|
@@ -162,11 +203,11 @@ module Meteor
|
|
162
203
|
|
163
204
|
#
|
164
205
|
# clone (複製する)
|
165
|
-
|
206
|
+
# @return [Meteor::Element] element (要素)
|
166
207
|
#
|
167
208
|
def clone
|
168
209
|
obj = self.parser.element_cache[self.object_id]
|
169
|
-
if obj
|
210
|
+
if obj
|
170
211
|
obj.attributes = String.new(self.attributes)
|
171
212
|
obj.mixed_content = String.new(self.mixed_content)
|
172
213
|
#obj.pattern = String.new(self.pattern)
|
@@ -180,21 +221,6 @@ module Meteor
|
|
180
221
|
end
|
181
222
|
end
|
182
223
|
|
183
|
-
attr_accessor :name #[String] tag name (要素名)
|
184
|
-
attr_accessor :attributes #[String] attributes (属性群)
|
185
|
-
attr_accessor :mixed_content #[String] content (内容)
|
186
|
-
attr_accessor :pattern #[String] pattern (パターン)
|
187
|
-
attr_accessor :document_sync #[true,false] document update flag (ドキュメント更新フラグ)
|
188
|
-
attr_accessor :empty #[true,false] content empty flag (内容存在フラグ)
|
189
|
-
attr_accessor :cx #[true,false] comment extension tag flag (コメント拡張タグフラグ)
|
190
|
-
attr_accessor :mono #[true,false] child element existance flag (子要素存在フラグ)
|
191
|
-
attr_accessor :parser #[Meteor::Parser] parser(パーサ)
|
192
|
-
attr_accessor :type_value #[String] タイプ属性
|
193
|
-
attr_accessor :usable #[true,false] usable flag (有効・無効フラグ)
|
194
|
-
attr_accessor :origin #[Meteor::Element] original pointer (原本ポインタ)
|
195
|
-
attr_accessor :copy #[Meteor::Element] copy pointer (複製ポインタ)
|
196
|
-
attr_accessor :removed #[true,false] delete flag (削除フラグ)
|
197
|
-
|
198
224
|
#
|
199
225
|
# set document (ドキュメントをセットする)
|
200
226
|
# @param [String] doc document (ドキュメント)
|
@@ -209,32 +235,32 @@ module Meteor
|
|
209
235
|
# @return [String] document (ドキュメント)
|
210
236
|
#
|
211
237
|
def document
|
212
|
-
if @document_sync
|
238
|
+
if @document_sync
|
213
239
|
@document_sync = false
|
214
240
|
case @parser.doc_type
|
215
|
-
when Parser::HTML, Parser::HTML5
|
216
|
-
if @cx
|
217
|
-
#@pattern_cc = '' << SET_CX_1 << elm.
|
218
|
-
@document = "<!-- @#{@
|
241
|
+
when Parser::HTML, Parser::HTML5
|
242
|
+
if @cx
|
243
|
+
#@pattern_cc = '' << SET_CX_1 << elm.tag << SPACE << elm.attributes << SET_CX_2 << elm.mixed_content << SET_CX_3 << elm.tag << SET_CX_4
|
244
|
+
@document = "<!-- @#{@tag} #{@attributes} -->#{@mixed_content}<!-- /@#{@tag} -->"
|
219
245
|
else
|
220
|
-
if @empty
|
221
|
-
#@pattern_cc = '' << TAG_OPEN << elm.
|
222
|
-
@document = "<#{@
|
246
|
+
if @empty
|
247
|
+
#@pattern_cc = '' << TAG_OPEN << elm.tag << elm.attributes << TAG_CLOSE << elm.mixed_content << TAG_OPEN3 << elm.tag << TAG_CLOSE
|
248
|
+
@document = "<#{@tag}#{@attributes}>#{@mixed_content}</#{@tag}>"
|
223
249
|
else
|
224
|
-
@document = '' << Meteor::Core::Kernel::TAG_OPEN << @
|
250
|
+
@document = '' << Meteor::Core::Kernel::TAG_OPEN << @tag << @attributes << Meteor::Core::Kernel::TAG_CLOSE
|
225
251
|
#@document = "<#{@name}#{@attributes}>"
|
226
252
|
end
|
227
253
|
end
|
228
|
-
when Parser::XHTML, Parser::XHTML5, Parser::XML
|
229
|
-
if @cx
|
230
|
-
#@pattern_cc = '' << SET_CX_1 << elm.
|
231
|
-
@document = "<!-- @#{@
|
254
|
+
when Parser::XHTML, Parser::XHTML5, Parser::XML
|
255
|
+
if @cx
|
256
|
+
#@pattern_cc = '' << SET_CX_1 << elm.tag << SPACE << elm.attributes << SET_CX_2 << elm.mixed_content << SET_CX_3 << elm.tag << SET_CX_4
|
257
|
+
@document = "<!-- @#{@tag} #{@attributes} -->#{@mixed_content}<!-- /@#{@tag} -->"
|
232
258
|
else
|
233
|
-
if @empty
|
234
|
-
#@pattern_cc = '' << TAG_OPEN << elm.
|
235
|
-
@document = "<#{@
|
259
|
+
if @empty
|
260
|
+
#@pattern_cc = '' << TAG_OPEN << elm.tag << elm.attributes << TAG_CLOSE << elm.mixed_content << TAG_OPEN3 << elm.tag << TAG_CLOSE
|
261
|
+
@document = "<#{@tag}#{@attributes}>#{@mixed_content}</#{@tag}>"
|
236
262
|
else
|
237
|
-
@document = '' << Meteor::Core::Kernel::TAG_OPEN << @
|
263
|
+
@document = '' << Meteor::Core::Kernel::TAG_OPEN << @tag << @attributes << Meteor::Core::Kernel::TAG_CLOSE3
|
238
264
|
#@document = "<#{@name}#{@attributes}/>"
|
239
265
|
end
|
240
266
|
end
|
@@ -248,20 +274,20 @@ module Meteor
|
|
248
274
|
# get element (要素を取得する)
|
249
275
|
# @overload element()
|
250
276
|
# get element (要素を取得する)
|
251
|
-
# @return [Meteor::Element
|
277
|
+
# @return [Meteor::Element] element (要素)
|
252
278
|
# @overload element(tag)
|
253
279
|
# get element using tag name (要素のタグ名で要素を取得する)
|
254
280
|
# @param [String] tag tag name (タグ名)
|
255
|
-
# @return [Meteor::Element] 要素
|
281
|
+
# @return [Meteor::Element] element (要素)
|
256
282
|
# @overload element(tag,attrs)
|
257
283
|
# get element using tag name and attribute map (要素のタグ名と属性(属性名="属性値")あるいは属性1・属性2(属性名="属性値")で要素を取得する)
|
258
284
|
# @param [String] tag tag name (タグ名)
|
259
|
-
# @param [Hash] attrs attribute map (属性マップ)
|
285
|
+
# @param [Hash<String,String>] attrs attribute map (属性マップ)
|
260
286
|
# @return [Meteor::Element] element (要素)
|
261
287
|
# @overload element(attrs)
|
262
288
|
# get element using attribute map (属性(属性名="属性値")あるいは属性1・属性2(属性名="属性値")で要素を取得する)
|
263
|
-
# @param [Hash] attrs attribute map (属性マップ)
|
264
|
-
# @return [Meteor::Element] 要素
|
289
|
+
# @param [Hash<String,String>] attrs attribute map (属性マップ)
|
290
|
+
# @return [Meteor::Element] element(要素)
|
265
291
|
# @overload element(tag,attr_name,attr_value)
|
266
292
|
# get element using tag name and attribute(name="value") (要素のタグ名と属性(属性名="属性値")で要素を取得する)
|
267
293
|
# @param [String] tag tag name (タグ名)
|
@@ -272,7 +298,7 @@ module Meteor
|
|
272
298
|
# get element using attribute(name="value") (属性(属性名="属性値")で要素を取得する)
|
273
299
|
# @param [String] attr_name 属性名
|
274
300
|
# @param [String] attr_value 属性値
|
275
|
-
# @return [Meteor::Element] 要素
|
301
|
+
# @return [Meteor::Element] element (要素)
|
276
302
|
# @overload element(tag,attr_name1,attr_value1,attr_name2,attr_value2)
|
277
303
|
# get element using tag name and attribute1,2(name="value") (要素のタグ名と属性1・属性2(属性名="属性値")で要素を取得する)
|
278
304
|
# @param [String] tag tag name (タグ名)
|
@@ -287,7 +313,7 @@ module Meteor
|
|
287
313
|
# @param [String] attr_value1 属性値1
|
288
314
|
# @param [String] attr_name2 属性名2
|
289
315
|
# @param [String] attr_value2 属性値2
|
290
|
-
# @return [Meteor::Element] 要素
|
316
|
+
# @return [Meteor::Element] element(要素)
|
291
317
|
# @overload element(elm)
|
292
318
|
# mirror element (要素を射影する)
|
293
319
|
# @param [Meteor::Element] elm element(要素)
|
@@ -306,28 +332,74 @@ module Meteor
|
|
306
332
|
alias :child :element
|
307
333
|
|
308
334
|
#
|
309
|
-
# get
|
335
|
+
# get elements (要素を取得する)
|
336
|
+
# @overload elements(tag)
|
337
|
+
# get elements using tag name (要素のタグ名で要素を取得する)
|
338
|
+
# @param [String] tag tag name (タグ名)
|
339
|
+
# @return [Array<Meteor::Element>] element array(要素配列)
|
340
|
+
# @overload elements(tag,attrs)
|
341
|
+
# get elements using tag name and attribute map (要素のタグ名と属性(属性名="属性値")あるいは属性1・属性2(属性名="属性値")で要素を取得する)
|
342
|
+
# @param [String] tag tag name (タグ名)
|
343
|
+
# @param [Hash<String,String>] attrs attribute map (属性マップ)
|
344
|
+
# @return [Array<Meteor::Element>] element array (要素配列)
|
345
|
+
# @overload elements(attrs)
|
346
|
+
# get elements using attribute map (属性(属性名="属性値")あるいは属性1・属性2(属性名="属性値")で要素を取得する)
|
347
|
+
# @param [Hash<String,String>] attrs attribute map (属性マップ)
|
348
|
+
# @return [Array<Meteor::Element>] element array (要素配列)
|
349
|
+
# @overload elements(tag,attr_name,attr_value)
|
350
|
+
# get elements using tag name and attribute(name="value") (要素のタグ名と属性(属性名="属性値")で要素を取得する)
|
351
|
+
# @param [String] tag tag name (タグ名)
|
352
|
+
# @param [String] attr_name attribute name (属性名)
|
353
|
+
# @param [String] attr_value attribute value (属性値)
|
354
|
+
# @return [Array<Meteor::Element>] element array (要素配列)
|
355
|
+
# @overload elements(attr_name,attr_value)
|
356
|
+
# get elements using attribute(name="value") (属性(属性名="属性値")で要素を取得する)
|
357
|
+
# @param [String] attr_name attribute name (属性名)
|
358
|
+
# @param [String] attr_value attribute value (属性値)
|
359
|
+
# @return [Array<Meteor::Element>] element array (要素配列)
|
360
|
+
# @overload elements(tag,attr_name1,attr_value1,attr_name2,attr_value2)
|
361
|
+
# get elements using tag name and attribute1,2(name="value") (要素のタグ名と属性1・属性2(属性名="属性値")で要素を取得する)
|
362
|
+
# @param [String] tag tag name (タグ名)
|
363
|
+
# @param [String] attr_name1 attribute name1 (属性名1)
|
364
|
+
# @param [String] attr_value1 attribute value1 (属性値1)
|
365
|
+
# @param [String] attr_name2 attribute name2 (属性名2)
|
366
|
+
# @param [String] attr_value2 attribute value2 (属性値2)
|
367
|
+
# @return [Array<Meteor::Element>] element array (要素配列)
|
368
|
+
# @overload elements(attr_name1,attr_value1,attr_name2,attr_value2)
|
369
|
+
# get elements using attribute1,2(name="value") (属性1・属性2(属性名="属性値")で要素を取得する)
|
370
|
+
# @param [String] attr_name1 attribute name1 (属性名1)
|
371
|
+
# @param [String] attr_value1 attribute value1 (属性値1)
|
372
|
+
# @param [String] attr_name2 attribute name2 (属性名2)
|
373
|
+
# @param [String] attr_value2 attribute value2 (属性値2)
|
374
|
+
# @return [Array<Meteor::Element>] element array (要素配列)
|
375
|
+
#
|
376
|
+
def elements(*args)
|
377
|
+
@parser.elements(*args)
|
378
|
+
end
|
379
|
+
|
380
|
+
#
|
381
|
+
# get (child) elements using selector like css3(CSS3のようにセレクタを用いて(子)要素を取得する)
|
310
382
|
# CSS3 selector partial support (CSS3セレクタの部分的サポート)
|
311
383
|
# @param selector [String] selector (セレクタ)
|
312
|
-
# @return [Meteor::Element] element (要素)
|
384
|
+
# @return [Array<Meteor::Element>] element (要素)
|
313
385
|
#
|
314
|
-
def
|
315
|
-
@parser.
|
386
|
+
def find(selector)
|
387
|
+
@parser.find(selector)
|
316
388
|
end
|
317
389
|
|
318
|
-
alias :
|
390
|
+
alias :css :find
|
319
391
|
|
320
392
|
#
|
321
393
|
# get cx(comment extension) tag (CX(コメント拡張)タグを取得する)
|
322
394
|
# @overload cxtag(tag,id)
|
323
|
-
#
|
324
|
-
# @param [String] tag タグ名
|
325
|
-
# @param [String] id ID属性値
|
326
|
-
# @return [Meteor::Element] 要素
|
395
|
+
# get cx(comment extension) tag using tag name and id attribute (タグ名とID属性(id="ID属性値")でCX(コメント拡張)タグを取得する)
|
396
|
+
# @param [String] tag tag name (タグ名)
|
397
|
+
# @param [String] id id attribute value (ID属性値)
|
398
|
+
# @return [Meteor::Element] element(要素)
|
327
399
|
# @overload cxtag(id)
|
328
|
-
# ID属性(id="ID属性値")でCX(コメント拡張)タグを取得する
|
329
|
-
# @param [String] id ID属性値
|
330
|
-
# @return [Meteor::Element] 要素
|
400
|
+
# get cx(comment extension) tag using id attribute (ID属性(id="ID属性値")でCX(コメント拡張)タグを取得する)
|
401
|
+
# @param [String] id id attribute value (ID属性値)
|
402
|
+
# @return [Meteor::Element] element (要素)
|
331
403
|
#
|
332
404
|
def cxtag(*args)
|
333
405
|
@parser.cxtag(*args)
|
@@ -336,7 +408,7 @@ module Meteor
|
|
336
408
|
#
|
337
409
|
# @overload attr(attr)
|
338
410
|
# set attribute of element (要素の属性をセットする)
|
339
|
-
# @param [Hash] attr attribute (属性)
|
411
|
+
# @param [Hash<String,String>] attr attribute (属性)
|
340
412
|
# @return [Meteor::Element] element (要素)
|
341
413
|
# @deprecated
|
342
414
|
# @overload attr(attr_name,attr_value)
|
@@ -364,7 +436,7 @@ module Meteor
|
|
364
436
|
|
365
437
|
#
|
366
438
|
# set attribute map (要素マップをセットする)
|
367
|
-
# @
|
439
|
+
# @param [Hash<String,String>] attrs attribute map (属性マップ)
|
368
440
|
# @return [Meteor::Element] element (要素)
|
369
441
|
def attrs=(attrs)
|
370
442
|
@parser.attrs(self,attrs)
|
@@ -372,7 +444,7 @@ module Meteor
|
|
372
444
|
|
373
445
|
#
|
374
446
|
# get attribute map (属性マップを取得する)
|
375
|
-
# @return [Hash] attribute map (属性マップ)
|
447
|
+
# @return [Hash<String,String>] attribute map (属性マップ)
|
376
448
|
#
|
377
449
|
def attrs
|
378
450
|
@parser.attrs(self)
|
@@ -488,27 +560,25 @@ module Meteor
|
|
488
560
|
#
|
489
561
|
# root element class (ルート要素クラス)
|
490
562
|
#
|
563
|
+
# @!attribute [rw] content_type
|
564
|
+
# @return [String] content type (コンテントタイプ)
|
565
|
+
# @!attribute [rw] kaigyo_code
|
566
|
+
# @return [String] newline (改行コード)
|
567
|
+
# @!attribute [rw] charset
|
568
|
+
# @return [String] charset (文字コード)
|
569
|
+
# @!attribute [rw] character_encoding
|
570
|
+
# @return [String] character encoding (文字エンコーディング)
|
571
|
+
#
|
491
572
|
class RootElement < Element
|
492
573
|
|
493
574
|
EMPTY = ''
|
494
575
|
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
# #コンテントタイプ
|
500
|
-
# #@contentType = ''
|
501
|
-
# #改行コード
|
502
|
-
# #@kaigyoCode = ''
|
503
|
-
# #文字コード
|
504
|
-
# #@character_encoding=''
|
505
|
-
#end
|
506
|
-
|
507
|
-
attr_accessor :content_type #[String] content type (コンテントタイプ)
|
508
|
-
attr_accessor :kaigyo_code #[String] newline (改行コード)
|
509
|
-
attr_accessor :charset #[String] charset (文字コード)
|
510
|
-
attr_accessor :character_encoding #[String] character encoding (文字エンコーディング)
|
576
|
+
attr_accessor :content_type
|
577
|
+
attr_accessor :kaigyo_code
|
578
|
+
attr_accessor :charset
|
579
|
+
attr_accessor :character_encoding
|
511
580
|
#attr_accessor :document #[String] document (ドキュメント)
|
581
|
+
|
512
582
|
end
|
513
583
|
|
514
584
|
#
|
@@ -533,7 +603,6 @@ module Meteor
|
|
533
603
|
end
|
534
604
|
end
|
535
605
|
|
536
|
-
|
537
606
|
#
|
538
607
|
# initializer (イニシャライザ)
|
539
608
|
#
|
@@ -563,18 +632,18 @@ module Meteor
|
|
563
632
|
#
|
564
633
|
def store(name, value)
|
565
634
|
|
566
|
-
if !@map[name]
|
635
|
+
if !@map[name]
|
567
636
|
attr = Attribute.new
|
568
637
|
attr.name = name
|
569
638
|
attr.value = value
|
570
|
-
if @recordable
|
639
|
+
if @recordable
|
571
640
|
attr.changed = true
|
572
641
|
attr.removed = false
|
573
642
|
end
|
574
643
|
@map[name] = attr
|
575
644
|
else
|
576
645
|
attr = @map[name]
|
577
|
-
if @recordable && attr.value != value
|
646
|
+
if @recordable && attr.value != value
|
578
647
|
attr.changed = true
|
579
648
|
attr.removed = false
|
580
649
|
end
|
@@ -590,16 +659,13 @@ module Meteor
|
|
590
659
|
@map.keys
|
591
660
|
end
|
592
661
|
|
593
|
-
private :initialize_0
|
594
|
-
private :initialize_1
|
595
|
-
|
596
662
|
#
|
597
663
|
# get attribute value using attribute name (属性名で属性値を取得する)
|
598
664
|
# @param [String] name attribute name (属性名)
|
599
665
|
# @return [String] attribute value (属性値)
|
600
666
|
#
|
601
667
|
def fetch(name)
|
602
|
-
if @map[name] && !@map[name].removed
|
668
|
+
if @map[name] && !@map[name].removed
|
603
669
|
@map[name].value
|
604
670
|
end
|
605
671
|
end
|
@@ -609,7 +675,7 @@ module Meteor
|
|
609
675
|
# @param name attribute name (属性名)
|
610
676
|
#
|
611
677
|
def delete(name)
|
612
|
-
if @recordable && @map[name]
|
678
|
+
if @recordable && @map[name]
|
613
679
|
@map[name].removed = true
|
614
680
|
@map[name].changed = false
|
615
681
|
end
|
@@ -620,7 +686,7 @@ module Meteor
|
|
620
686
|
# @return [true,false] update flag of attribute (属性の変更状況)
|
621
687
|
#
|
622
688
|
def changed(name)
|
623
|
-
if @map[name]
|
689
|
+
if @map[name]
|
624
690
|
@map[name].changed
|
625
691
|
end
|
626
692
|
end
|
@@ -630,7 +696,7 @@ module Meteor
|
|
630
696
|
# @return [true,false] delete flag of attribute (属性の削除状況)
|
631
697
|
#
|
632
698
|
def removed(name)
|
633
|
-
if @map[name]
|
699
|
+
if @map[name]
|
634
700
|
@map[name].removed
|
635
701
|
end
|
636
702
|
end
|
@@ -659,88 +725,34 @@ module Meteor
|
|
659
725
|
end
|
660
726
|
end
|
661
727
|
|
662
|
-
if RUBY_VERSION < RUBY_VERSION_1_9_0 then
|
663
|
-
class AttributeMap
|
664
|
-
#
|
665
|
-
# initializer (イニシャライザ)
|
666
|
-
#
|
667
|
-
def initialize_0
|
668
|
-
@map = Hash.new
|
669
|
-
@names = Array.new
|
670
|
-
@recordable = false
|
671
|
-
end
|
672
|
-
|
673
|
-
private :initialize_0
|
674
|
-
|
675
|
-
#
|
676
|
-
# initializer (イニシャライザ)
|
677
|
-
# @param [Meteor::AttributeMap] attr_map attribute map (属性マップ)
|
678
|
-
#
|
679
|
-
def initialize_1(attr_map)
|
680
|
-
#@map = Marshal.load(Marshal.dump(attr_map.map))
|
681
|
-
@map = attr_map.map.dup
|
682
|
-
@names = Array.new(attr_map.names)
|
683
|
-
@recordable = attr_map.recordable
|
684
|
-
end
|
685
|
-
|
686
|
-
private :initialize_1
|
687
|
-
|
688
|
-
#
|
689
|
-
# set a couple of attribute name and attribute value (属性名と属性値を対としてセットする)
|
690
|
-
# @param [String] name attribute name (属性名)
|
691
|
-
# @param [String] value attribute value (属性値)
|
692
|
-
#
|
693
|
-
def store(name, value)
|
694
|
-
|
695
|
-
if !@map[name] then
|
696
|
-
attr = Attribute.new
|
697
|
-
attr.name = name
|
698
|
-
attr.value = value
|
699
|
-
if @recordable then
|
700
|
-
attr.changed = true
|
701
|
-
attr.removed = false
|
702
|
-
end
|
703
|
-
@map[name] = attr
|
704
|
-
@names << name
|
705
|
-
else
|
706
|
-
attr = @map[name]
|
707
|
-
if @recordable && attr.value != value then
|
708
|
-
attr.changed = true
|
709
|
-
attr.removed = false
|
710
|
-
end
|
711
|
-
attr.value = value
|
712
|
-
end
|
713
|
-
end
|
714
|
-
|
715
|
-
#
|
716
|
-
# get attribute name array (属性名配列を取得する)
|
717
|
-
# @return [Array] attribute name array (属性名配列)
|
718
|
-
#
|
719
|
-
def names
|
720
|
-
@names
|
721
|
-
end
|
722
|
-
end
|
723
|
-
end
|
724
|
-
|
725
728
|
#
|
726
729
|
# Attribute class (属性クラス)
|
727
730
|
#
|
731
|
+
# @!attribute [rw] name
|
732
|
+
# @return [String] attribute name (名前)
|
733
|
+
# @!attribute [rw] value
|
734
|
+
# @return [String] attribute value (値)
|
735
|
+
# @!attribute [rw] changed
|
736
|
+
# @return [true,false] update flag (更新フラグ)
|
737
|
+
# @!attribute [rw] removed
|
738
|
+
# @return [true,false] delete flag (削除フラグ)
|
739
|
+
#
|
728
740
|
class Attribute
|
729
741
|
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
#@name = nil
|
735
|
-
#@value = nil
|
736
|
-
#@changed = false
|
737
|
-
#@removed = false
|
738
|
-
end
|
742
|
+
attr_accessor :name
|
743
|
+
attr_accessor :value
|
744
|
+
attr_accessor :changed
|
745
|
+
attr_accessor :removed
|
739
746
|
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
747
|
+
##
|
748
|
+
## initializer (イニシャライザ)
|
749
|
+
##
|
750
|
+
#def initialize
|
751
|
+
# #@name = nil
|
752
|
+
# #@value = nil
|
753
|
+
# #@changed = false
|
754
|
+
# #@removed = false
|
755
|
+
#end
|
744
756
|
|
745
757
|
end
|
746
758
|
|
@@ -758,41 +770,58 @@ module Meteor
|
|
758
770
|
#
|
759
771
|
# Parser Factory Class (パーサファクトリクラス)
|
760
772
|
#
|
773
|
+
# @!attribute [rw] type
|
774
|
+
# @return [FixNum] default type of parser (デフォルトのパーサ・タイプ)
|
775
|
+
# @!attribute [rw] root
|
776
|
+
# @return [String] root root directory (基準ディレクトリ)
|
777
|
+
# @!attribute [rw] enc
|
778
|
+
# @return [String] default character encoding (デフォルトエンコーディング)
|
779
|
+
#
|
761
780
|
class ParserFactory
|
762
781
|
|
763
782
|
ABST_EXT_NAME = '.*'
|
783
|
+
#CURRENT_DIR = FileUtils.pwd
|
784
|
+
#puts CURRENT_DIR
|
764
785
|
CURRENT_DIR = '.'
|
765
786
|
SLASH = '/'
|
766
787
|
ENC_UTF8 = 'UTF-8'
|
767
788
|
|
768
|
-
attr_accessor :
|
769
|
-
attr_accessor :
|
770
|
-
attr_accessor :
|
789
|
+
attr_accessor :type
|
790
|
+
attr_accessor :root
|
791
|
+
attr_accessor :enc
|
771
792
|
|
772
|
-
|
793
|
+
alias_method :base_type, :type
|
794
|
+
alias_method :base_type=, :type=
|
795
|
+
alias_method :base_dir, :root
|
796
|
+
alias_method :base_dir=, :root=
|
797
|
+
alias_method :base_enc, :enc
|
798
|
+
alias_method :base_enc=, :enc=
|
799
|
+
|
800
|
+
alias_method :base_encoding, :enc
|
801
|
+
alias_method :base_encoding=, :enc=
|
773
802
|
|
774
803
|
#
|
775
804
|
# initializer (イニシャライザ)
|
776
805
|
# @overload initialize()
|
777
|
-
# @overload initialize(
|
778
|
-
# @param [String]
|
779
|
-
# @overload initialize(
|
780
|
-
# @param [String]
|
781
|
-
# @param [String]
|
782
|
-
# @overload initialize(
|
783
|
-
# @param [FixNum]
|
784
|
-
# @param [String]
|
785
|
-
# @param [String]
|
806
|
+
# @overload initialize(root)
|
807
|
+
# @param [String] root root directory (基準ディレクトリ)
|
808
|
+
# @overload initialize(root, enc)
|
809
|
+
# @param [String] root root directory (基準ディレクトリ)
|
810
|
+
# @param [String] enc default character encoding (デフォルトエンコーディング)
|
811
|
+
# @overload initialize(type, root, enc)
|
812
|
+
# @param [FixNum] type default type of parser (デフォルトのパーサ・タイプ)
|
813
|
+
# @param [String] root root directory (基準ディレクトリ)
|
814
|
+
# @param [String] enc default character encoding (デフォルト文字エンコーディング)
|
786
815
|
#
|
787
816
|
def initialize(*args)
|
788
817
|
case args.length
|
789
|
-
when 0
|
818
|
+
when 0
|
790
819
|
initialize_0
|
791
|
-
when 1
|
820
|
+
when 1
|
792
821
|
initialize_1(args[0])
|
793
|
-
when 2
|
822
|
+
when 2
|
794
823
|
initialize_2(args[0], args[1])
|
795
|
-
when 3
|
824
|
+
when 3
|
796
825
|
initialize_3(args[0],args[1],args[2])
|
797
826
|
else
|
798
827
|
raise ArgumentError
|
@@ -804,48 +833,48 @@ module Meteor
|
|
804
833
|
#
|
805
834
|
def initialize_0
|
806
835
|
@cache = Hash.new
|
807
|
-
@
|
808
|
-
@
|
836
|
+
@root = CURRENT_DIR
|
837
|
+
@enc = ENC_UTF8
|
809
838
|
end
|
810
839
|
|
811
840
|
private :initialize_0
|
812
841
|
|
813
842
|
#
|
814
843
|
# イニシャライザ
|
815
|
-
# @param [String]
|
844
|
+
# @param [String] root root directory (基準ディレクトリ)
|
816
845
|
#
|
817
|
-
def initialize_1(
|
846
|
+
def initialize_1(root)
|
818
847
|
@cache = Hash.new
|
819
|
-
@
|
820
|
-
@
|
848
|
+
@root = root
|
849
|
+
@enc = ENC_UTF8
|
821
850
|
end
|
822
851
|
|
823
852
|
private :initialize_1
|
824
853
|
|
825
854
|
#
|
826
855
|
# イニシャライザ
|
827
|
-
# @param [String]
|
828
|
-
# @param [String]
|
856
|
+
# @param [String] root root directory (基準ディレクトリ)
|
857
|
+
# @param [String] enc default character encoding (デフォルト文字エンコーディング)
|
829
858
|
#
|
830
|
-
def initialize_2(
|
859
|
+
def initialize_2(root, enc)
|
831
860
|
@cache = Hash.new
|
832
|
-
@
|
833
|
-
@
|
861
|
+
@root = root
|
862
|
+
@enc = enc
|
834
863
|
end
|
835
864
|
|
836
865
|
private :initialize_2
|
837
866
|
|
838
867
|
#
|
839
868
|
# イニシャライザ
|
840
|
-
# @
|
841
|
-
# @param [String]
|
842
|
-
# @param [String]
|
869
|
+
# @param [FixNum] type default type of parser (デフォルトのパーサ・タイプ)
|
870
|
+
# @param [String] root root directory (基準ディレクトリ)
|
871
|
+
# @param [String] enc default character encoding (デフォルト文字エンコーディング)
|
843
872
|
#
|
844
|
-
def initialize_3(
|
873
|
+
def initialize_3(type , root, enc)
|
845
874
|
@cache = Hash.new
|
846
|
-
@
|
847
|
-
@
|
848
|
-
@
|
875
|
+
@type = type
|
876
|
+
@root = root
|
877
|
+
@enc = enc
|
849
878
|
end
|
850
879
|
|
851
880
|
private :initialize_3
|
@@ -853,20 +882,29 @@ module Meteor
|
|
853
882
|
#
|
854
883
|
# set options (オプションをセットする)
|
855
884
|
# @param [Hash] opts option (オプション)
|
856
|
-
# @option opts [String] :
|
857
|
-
# @option opts [String] :
|
858
|
-
# @option opts [
|
885
|
+
# @option opts [String] :root root directory (基準ディレクトリ)
|
886
|
+
# @option @deprecated opts [String] :base_dir root directory (基準ディレクトリ)
|
887
|
+
# @option opts [String] :enc default character encoding (デフォルト文字エンコーディング)
|
888
|
+
# @option @deprecated opts [String] :base_enc default character encoding (デフォルト文字エンコーディング)
|
889
|
+
# @option opts [FixNum] :type default type of parser (デフォルトのパーサ・タイプ)
|
890
|
+
# @option @deprecated opts [FixNum] :base_type default type of parser (デフォルトのパーサ・タイプ)
|
859
891
|
#
|
860
892
|
def options=(opts)
|
861
893
|
if opts.kind_of?(Hash)
|
862
|
-
if opts.include?(:
|
863
|
-
@
|
894
|
+
if opts.include?(:root)
|
895
|
+
@root = opts[:root]
|
896
|
+
elsif opts.include?(:base_dir)
|
897
|
+
@root = opts[:base_dir]
|
864
898
|
end
|
865
|
-
if opts.include?(:
|
866
|
-
@
|
899
|
+
if opts.include?(:enc)
|
900
|
+
@enc = opts[:enc]
|
901
|
+
elsif opts.include?(:base_enc)
|
902
|
+
@enc = opts[:base_enc]
|
867
903
|
end
|
868
|
-
if opts.include?(:
|
869
|
-
@
|
904
|
+
if opts.include?(:type)
|
905
|
+
@type = opts[:type]
|
906
|
+
elsif opts.include?(:base_type)
|
907
|
+
@type = opts[:base_type]
|
870
908
|
end
|
871
909
|
else
|
872
910
|
raise ArgumentError
|
@@ -897,9 +935,9 @@ module Meteor
|
|
897
935
|
#
|
898
936
|
def bind(*args)
|
899
937
|
case args.length
|
900
|
-
when 1
|
938
|
+
when 1
|
901
939
|
bind_1(args[0])
|
902
|
-
when 2
|
940
|
+
when 2
|
903
941
|
if args[0].kind_of?(Fixnum)
|
904
942
|
bind_2_n(args[0], args[1])
|
905
943
|
elsif args[0].kind_of?(String)
|
@@ -907,7 +945,7 @@ module Meteor
|
|
907
945
|
else
|
908
946
|
raise ArgumentError
|
909
947
|
end
|
910
|
-
when 3
|
948
|
+
when 3
|
911
949
|
bind_3(args[0], args[1], args[2])
|
912
950
|
else
|
913
951
|
raise ArgumentError
|
@@ -915,49 +953,60 @@ module Meteor
|
|
915
953
|
end
|
916
954
|
|
917
955
|
#
|
918
|
-
#
|
919
|
-
# @param [
|
920
|
-
# @
|
921
|
-
# @param [String] enc character encoding (文字エンコーディング)
|
922
|
-
# @return [Meteor::Parser] parser(パーサ)
|
956
|
+
# change relative path to relative url (相対パスを相対URLにする)
|
957
|
+
# @param [String] path relative path (相対パス)
|
958
|
+
# @return [String] relative url (相対URL)
|
923
959
|
#
|
924
|
-
def
|
960
|
+
def path_to_url(path)
|
961
|
+
paths = File.split(path)
|
925
962
|
|
926
|
-
paths
|
927
|
-
|
928
|
-
if paths.length == 1 then
|
929
|
-
relative_url = File.basename(paths[0], ABST_EXT_NAME)
|
963
|
+
if paths.length == 1
|
964
|
+
return File.basename(paths[0], ABST_EXT_NAME)
|
930
965
|
else
|
931
|
-
if CURRENT_DIR.eql?(paths[0])
|
966
|
+
if CURRENT_DIR.eql?(paths[0])
|
932
967
|
paths.delete_at 0
|
933
968
|
paths[paths.length - 1] = File.basename(paths[paths.length - 1], ABST_EXT_NAME)
|
934
|
-
|
969
|
+
return paths.join(SLASH)
|
935
970
|
else
|
936
971
|
paths[paths.length - 1] = File.basename(paths[paths.length - 1], ABST_EXT_NAME)
|
937
|
-
|
972
|
+
return paths.join(SLASH)
|
938
973
|
end
|
939
974
|
end
|
975
|
+
end
|
976
|
+
|
977
|
+
private :path_to_url
|
978
|
+
|
979
|
+
#
|
980
|
+
# generate parser (パーサを作成する)
|
981
|
+
# @param [Fixnum] type type of parser (パーサ・タイプ)
|
982
|
+
# @param [String] relative_path relative file path (相対ファイルパス)
|
983
|
+
# @param [String] enc character encoding (文字エンコーディング)
|
984
|
+
# @return [Meteor::Parser] parser(パーサ)
|
985
|
+
#
|
986
|
+
def bind_3(type, relative_path, enc)
|
987
|
+
|
988
|
+
relative_url = path_to_url(relative_path)
|
940
989
|
|
941
990
|
case type
|
942
|
-
when Parser::HTML
|
943
|
-
html = Meteor::Ml::Html::ParserImpl.new
|
944
|
-
html.read(File.expand_path(relative_path, @
|
991
|
+
when Parser::HTML
|
992
|
+
html = Meteor::Ml::Html::ParserImpl.new
|
993
|
+
html.read(File.expand_path(relative_path, @root), enc)
|
945
994
|
@cache[relative_url] = html
|
946
|
-
when Parser::XHTML
|
947
|
-
xhtml = Meteor::Ml::Xhtml::ParserImpl.new
|
948
|
-
xhtml.read(File.expand_path(relative_path, @
|
995
|
+
when Parser::XHTML
|
996
|
+
xhtml = Meteor::Ml::Xhtml::ParserImpl.new
|
997
|
+
xhtml.read(File.expand_path(relative_path, @root), enc)
|
949
998
|
@cache[relative_url] = xhtml
|
950
|
-
when Parser::HTML5
|
951
|
-
html5 = Meteor::Ml::Html5::ParserImpl.new
|
952
|
-
html5.read(File.expand_path(relative_path, @
|
999
|
+
when Parser::HTML5
|
1000
|
+
html5 = Meteor::Ml::Html5::ParserImpl.new
|
1001
|
+
html5.read(File.expand_path(relative_path, @root), enc)
|
953
1002
|
@cache[relative_url] = html5
|
954
|
-
when Parser::XHTML5
|
955
|
-
xhtml5 = Meteor::Ml::Xhtml5::ParserImpl.new
|
956
|
-
xhtml5.read(File.expand_path(relative_path, @
|
1003
|
+
when Parser::XHTML5
|
1004
|
+
xhtml5 = Meteor::Ml::Xhtml5::ParserImpl.new
|
1005
|
+
xhtml5.read(File.expand_path(relative_path, @root), enc)
|
957
1006
|
@cache[relative_url] = xhtml5
|
958
|
-
when Parser::XML
|
959
|
-
xml = Meteor::Ml::Xml::ParserImpl.new
|
960
|
-
xml.read(File.expand_path(relative_path, @
|
1007
|
+
when Parser::XML
|
1008
|
+
xml = Meteor::Ml::Xml::ParserImpl.new
|
1009
|
+
xml.read(File.expand_path(relative_path, @root), enc)
|
961
1010
|
@cache[relative_url] = xml
|
962
1011
|
end
|
963
1012
|
end
|
@@ -972,44 +1021,24 @@ module Meteor
|
|
972
1021
|
#
|
973
1022
|
def bind_2_n(type, relative_path)
|
974
1023
|
|
975
|
-
|
976
|
-
|
977
|
-
if paths.length == 1 then
|
978
|
-
relative_url = File.basename(paths[0], ABST_EXT_NAME)
|
979
|
-
else
|
980
|
-
if CURRENT_DIR.eql?(paths[0]) then
|
981
|
-
paths.delete_at 0
|
982
|
-
paths[paths.length - 1] = File.basename(paths[paths.length - 1], ABST_EXT_NAME)
|
983
|
-
relative_url = paths.join(SLASH)
|
984
|
-
else
|
985
|
-
paths[paths.length - 1] = File.basename(paths[paths.length - 1], ABST_EXT_NAME)
|
986
|
-
relative_url = paths.join(SLASH)
|
987
|
-
end
|
988
|
-
end
|
1024
|
+
relative_url = path_to_url(relative_path)
|
989
1025
|
|
990
1026
|
case type
|
991
|
-
when Parser::HTML
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
when Parser::
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
when Parser::
|
1000
|
-
|
1001
|
-
html5.read(File.expand_path(relative_path, @base_dir), @base_enc)
|
1002
|
-
@cache[relative_url] = html5
|
1003
|
-
when Parser::XHTML5 then
|
1004
|
-
xhtml5 = Meteor::Ml::Xhtml5::ParserImpl.new()
|
1005
|
-
xhtml5.read(File.expand_path(relative_path, @base_dir), @base_enc)
|
1006
|
-
@cache[relative_url] = xhtml5
|
1007
|
-
when Parser::XML then
|
1008
|
-
xml = Meteor::Ml::Xml::ParserImpl.new()
|
1009
|
-
xml.read(File.expand_path(relative_path, @base_dir), @base_enc)
|
1010
|
-
@cache[relative_url] = xml
|
1027
|
+
when Parser::HTML
|
1028
|
+
ps = Meteor::Ml::Html::ParserImpl.new
|
1029
|
+
when Parser::XHTML
|
1030
|
+
ps = Meteor::Ml::Xhtml::ParserImpl.new
|
1031
|
+
when Parser::HTML5
|
1032
|
+
ps = Meteor::Ml::Html5::ParserImpl.new
|
1033
|
+
when Parser::XHTML5
|
1034
|
+
ps = Meteor::Ml::Xhtml5::ParserImpl.new
|
1035
|
+
when Parser::XML
|
1036
|
+
ps = Meteor::Ml::Xml::ParserImpl.new
|
1011
1037
|
end
|
1012
1038
|
|
1039
|
+
ps.read(File.expand_path(relative_path, @root), @enc)
|
1040
|
+
@cache[relative_url] = ps
|
1041
|
+
|
1013
1042
|
end
|
1014
1043
|
|
1015
1044
|
private :bind_2_n
|
@@ -1022,43 +1051,23 @@ module Meteor
|
|
1022
1051
|
#
|
1023
1052
|
def bind_2_s(relative_path,enc)
|
1024
1053
|
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1054
|
+
relative_url = path_to_url(relative_path)
|
1055
|
+
|
1056
|
+
case @type
|
1057
|
+
when Parser::HTML
|
1058
|
+
ps = Meteor::Ml::Html::ParserImpl.new
|
1059
|
+
when Parser::XHTML
|
1060
|
+
ps = Meteor::Ml::Xhtml::ParserImpl.new
|
1061
|
+
when Parser::HTML5
|
1062
|
+
ps = Meteor::Ml::Html5::ParserImpl.new
|
1063
|
+
when Parser::XHTML5
|
1064
|
+
ps = Meteor::Ml::Xhtml5::ParserImpl.new
|
1065
|
+
when Parser::XML
|
1066
|
+
ps = Meteor::Ml::Xml::ParserImpl.new
|
1038
1067
|
end
|
1039
1068
|
|
1040
|
-
|
1041
|
-
|
1042
|
-
html = Meteor::Ml::Html::ParserImpl.new()
|
1043
|
-
html.read(File.expand_path(relative_path, @base_dir), enc)
|
1044
|
-
@cache[relative_url] = html
|
1045
|
-
when Parser::XHTML then
|
1046
|
-
xhtml = Meteor::Ml::Xhtml::ParserImpl.new()
|
1047
|
-
xhtml.read(File.expand_path(relative_path, @base_dir), enc)
|
1048
|
-
@cache[relative_url] = xhtml
|
1049
|
-
when Parser::HTML5 then
|
1050
|
-
html5 = Meteor::Ml::Html5::ParserImpl.new()
|
1051
|
-
html5.read(File.expand_path(relative_path, @base_dir), enc)
|
1052
|
-
@cache[relative_url] = html5
|
1053
|
-
when Parser::XHTML5 then
|
1054
|
-
xhtml5 = Meteor::Ml::Xhtml5::ParserImpl.new()
|
1055
|
-
xhtml5.read(File.expand_path(relative_path, @base_dir), enc)
|
1056
|
-
@cache[relative_url] = xhtml5
|
1057
|
-
when Parser::XML then
|
1058
|
-
xml = Meteor::Ml::Xml::ParserImpl.new()
|
1059
|
-
xml.read(File.expand_path(relative_path, @base_dir), enc)
|
1060
|
-
@cache[relative_url] = xml
|
1061
|
-
end
|
1069
|
+
ps.read(File.expand_path(relative_path, @root), enc)
|
1070
|
+
@cache[relative_url] = ps
|
1062
1071
|
|
1063
1072
|
end
|
1064
1073
|
|
@@ -1071,46 +1080,26 @@ module Meteor
|
|
1071
1080
|
#
|
1072
1081
|
def bind_1(relative_path)
|
1073
1082
|
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
end
|
1088
|
-
|
1089
|
-
case @base_type
|
1090
|
-
when Parser::HTML then
|
1091
|
-
html = Meteor::Ml::Html::ParserImpl.new()
|
1092
|
-
html.read(File.expand_path(relative_path, @base_dir), @base_enc)
|
1093
|
-
@cache[relative_url] = html
|
1094
|
-
when Parser::XHTML then
|
1095
|
-
xhtml = Meteor::Ml::Xhtml::ParserImpl.new()
|
1096
|
-
xhtml.read(File.expand_path(relative_path, @base_dir), @base_enc)
|
1097
|
-
@cache[relative_url] = xhtml
|
1098
|
-
when Parser::HTML5 then
|
1099
|
-
html5 = Meteor::Ml::Html5::ParserImpl.new()
|
1100
|
-
html5.read(File.expand_path(relative_path, @base_dir), @base_enc)
|
1101
|
-
@cache[relative_url] = html5
|
1102
|
-
when Parser::XHTML5 then
|
1103
|
-
xhtml5 = Meteor::Ml::Xhtml5::ParserImpl.new()
|
1104
|
-
xhtml5.read(File.expand_path(relative_path, @base_dir), @base_enc)
|
1105
|
-
@cache[relative_url] = xhtml5
|
1106
|
-
when Parser::XML then
|
1107
|
-
xml = Meteor::Ml::Xml::ParserImpl.new()
|
1108
|
-
xml.read(File.expand_path(relative_path, @base_dir), @base_enc)
|
1109
|
-
@cache[relative_url] = xml
|
1083
|
+
relative_url = path_to_url(relative_path)
|
1084
|
+
|
1085
|
+
case @type
|
1086
|
+
when Parser::HTML
|
1087
|
+
ps = Meteor::Ml::Html::ParserImpl.new
|
1088
|
+
when Parser::XHTML
|
1089
|
+
ps = Meteor::Ml::Xhtml::ParserImpl.new
|
1090
|
+
when Parser::HTML5
|
1091
|
+
ps = Meteor::Ml::Html5::ParserImpl.new
|
1092
|
+
when Parser::XHTML5
|
1093
|
+
ps = Meteor::Ml::Xhtml5::ParserImpl.new
|
1094
|
+
when Parser::XML
|
1095
|
+
ps = Meteor::Ml::Xml::ParserImpl.new
|
1110
1096
|
else
|
1111
1097
|
raise ArgumentError
|
1112
1098
|
end
|
1113
1099
|
|
1100
|
+
ps.read(File.expand_path(relative_path, @root), @enc)
|
1101
|
+
@cache[relative_url] = ps
|
1102
|
+
|
1114
1103
|
end
|
1115
1104
|
|
1116
1105
|
private :bind_1
|
@@ -1135,9 +1124,9 @@ module Meteor
|
|
1135
1124
|
# @deprecated
|
1136
1125
|
def parser(*args)
|
1137
1126
|
case args.length
|
1138
|
-
when 1
|
1127
|
+
when 1
|
1139
1128
|
parser_1(args[0])
|
1140
|
-
when 2,3
|
1129
|
+
when 2,3
|
1141
1130
|
bind(args)
|
1142
1131
|
end
|
1143
1132
|
#parser_1(key)
|
@@ -1151,15 +1140,15 @@ module Meteor
|
|
1151
1140
|
def parser_1(key)
|
1152
1141
|
@pif = @cache[key]
|
1153
1142
|
|
1154
|
-
if Meteor::Parser::HTML == @pif.doc_type
|
1143
|
+
if Meteor::Parser::HTML == @pif.doc_type
|
1155
1144
|
Meteor::Ml::Html::ParserImpl.new(@pif)
|
1156
|
-
elsif Meteor::Parser::XHTML == @pif.doc_type
|
1145
|
+
elsif Meteor::Parser::XHTML == @pif.doc_type
|
1157
1146
|
Meteor::Ml::Xhtml::ParserImpl.new(@pif)
|
1158
|
-
elsif Meteor::Parser::HTML5 == @pif.doc_type
|
1147
|
+
elsif Meteor::Parser::HTML5 == @pif.doc_type
|
1159
1148
|
Meteor::Ml::Html5::ParserImpl.new(@pif)
|
1160
|
-
elsif Meteor::Parser::XHTML5 == @pif.doc_type
|
1149
|
+
elsif Meteor::Parser::XHTML5 == @pif.doc_type
|
1161
1150
|
Meteor::Ml::Xhtml5::ParserImpl.new(@pif)
|
1162
|
-
elsif Meteor::Parser::XML == @pif.doc_type
|
1151
|
+
elsif Meteor::Parser::XML == @pif.doc_type
|
1163
1152
|
Meteor::Ml::Xml::ParserImpl.new(@pif)
|
1164
1153
|
end
|
1165
1154
|
end
|
@@ -1175,7 +1164,7 @@ module Meteor
|
|
1175
1164
|
parser_1(key).root_element
|
1176
1165
|
end
|
1177
1166
|
|
1178
|
-
|
1167
|
+
#
|
1179
1168
|
# @overload bind_str(type, relative_url, doc)
|
1180
1169
|
# generate parser (パーサを作成する)
|
1181
1170
|
# @param [Fixnum] type type of parser (パーサ・タイプ)
|
@@ -1190,9 +1179,9 @@ module Meteor
|
|
1190
1179
|
#
|
1191
1180
|
def bind_str(*args)
|
1192
1181
|
case args.length
|
1193
|
-
when 2
|
1182
|
+
when 2
|
1194
1183
|
bind_str_2(args[0],args[1])
|
1195
|
-
when 3
|
1184
|
+
when 3
|
1196
1185
|
bind_str_3(args[0],args[1],args[2])
|
1197
1186
|
else
|
1198
1187
|
raise ArgumentError
|
@@ -1208,27 +1197,21 @@ module Meteor
|
|
1208
1197
|
#
|
1209
1198
|
def bind_str_3(type, relative_url, doc)
|
1210
1199
|
case type
|
1211
|
-
when Parser::HTML
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
when Parser::
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
when Parser::
|
1220
|
-
|
1221
|
-
html5.parse(doc)
|
1222
|
-
@cache[relative_url] = html5
|
1223
|
-
when Parser::XHTML5 then
|
1224
|
-
xhtml5 = Meteor::Ml::Xhtml5::ParserImpl.new()
|
1225
|
-
xhtml5.parse(doc)
|
1226
|
-
@cache[relative_url] = xhtml5
|
1227
|
-
when Parser::XML then
|
1228
|
-
xml = Meteor::Ml::Xml::ParserImpl.new()
|
1229
|
-
xml.parse(doc)
|
1230
|
-
@cache[relative_url] = xml
|
1200
|
+
when Parser::HTML
|
1201
|
+
ps = Meteor::Ml::Html::ParserImpl.new
|
1202
|
+
when Parser::XHTML
|
1203
|
+
ps = Meteor::Ml::Xhtml::ParserImpl.new
|
1204
|
+
when Parser::HTML5
|
1205
|
+
ps = Meteor::Ml::Html5::ParserImpl.new
|
1206
|
+
when Parser::XHTML5
|
1207
|
+
ps = Meteor::Ml::Xhtml5::ParserImpl.new
|
1208
|
+
when Parser::XML
|
1209
|
+
ps = Meteor::Ml::Xml::ParserImpl.new
|
1231
1210
|
end
|
1211
|
+
|
1212
|
+
ps.dcument = doc
|
1213
|
+
ps.parse
|
1214
|
+
@cache[relative_url] = ps
|
1232
1215
|
end
|
1233
1216
|
|
1234
1217
|
private :bind_str_3
|
@@ -1240,28 +1223,23 @@ module Meteor
|
|
1240
1223
|
# @return [Meteor::Parser] parser (パーサ)
|
1241
1224
|
#
|
1242
1225
|
def bind_str_2(relative_url, doc)
|
1243
|
-
case @
|
1244
|
-
when Parser::HTML
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
when Parser::
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
when Parser::
|
1253
|
-
|
1254
|
-
html5.parse(doc)
|
1255
|
-
@cache[relative_url] = html5
|
1256
|
-
when Parser::XHTML5 then
|
1257
|
-
xhtml5 = Meteor::Ml::Xhtml5::ParserImpl.new()
|
1258
|
-
xhtml5.parse(doc)
|
1259
|
-
@cache[relative_url] = xhtml5
|
1260
|
-
when Parser::XML then
|
1261
|
-
xml = Meteor::Ml::Xml::ParserImpl.new()
|
1262
|
-
xml.parse(doc)
|
1263
|
-
@cache[relative_url] = xml
|
1226
|
+
case @type
|
1227
|
+
when Parser::HTML
|
1228
|
+
ps = Meteor::Ml::Html::ParserImpl.new
|
1229
|
+
when Parser::XHTML
|
1230
|
+
ps = Meteor::Ml::Xhtml::ParserImpl.new
|
1231
|
+
when Parser::HTML5
|
1232
|
+
ps = Meteor::Ml::Html5::ParserImpl.new
|
1233
|
+
when Parser::XHTML5
|
1234
|
+
ps = Meteor::Ml::Xhtml5::ParserImpl.new
|
1235
|
+
when Parser::XML
|
1236
|
+
ps = Meteor::Ml::Xml::ParserImpl.new
|
1264
1237
|
end
|
1238
|
+
|
1239
|
+
ps.document = doc
|
1240
|
+
ps.parse
|
1241
|
+
@cache[relative_url] = ps
|
1242
|
+
|
1265
1243
|
end
|
1266
1244
|
|
1267
1245
|
private :bind_str_2
|
@@ -1324,14 +1302,20 @@ module Meteor
|
|
1324
1302
|
end
|
1325
1303
|
|
1326
1304
|
#
|
1327
|
-
#
|
1328
|
-
#
|
1329
|
-
#
|
1330
|
-
#
|
1331
|
-
#
|
1305
|
+
# @overload bind_str(type, relative_url, doc)
|
1306
|
+
# generate parser (パーサを作成する)
|
1307
|
+
# @param [Fixnum] type type of parser (パーサ・タイプ)
|
1308
|
+
# @param [String] relative_url relative URL (相対URL)
|
1309
|
+
# @param [String] doc document (ドキュメント)
|
1310
|
+
# @return [Meteor::Parser] parser (パーサ)
|
1311
|
+
# @overload bind_str(relative_url, doc)
|
1312
|
+
# generate parser (パーサを作成する)
|
1313
|
+
# @param [String] relative_url relative URL (相対URL)
|
1314
|
+
# @param [String] doc document (ドキュメント)
|
1315
|
+
# @return [Meteor::Parser] parser (パーサ)
|
1332
1316
|
#
|
1333
|
-
def self.bind_str(
|
1334
|
-
@@pf.bind_str(
|
1317
|
+
def self.bind_str(*args)
|
1318
|
+
@@pf.bind_str(args)
|
1335
1319
|
end
|
1336
1320
|
|
1337
1321
|
#
|
@@ -1345,77 +1329,17 @@ module Meteor
|
|
1345
1329
|
|
1346
1330
|
end
|
1347
1331
|
|
1348
|
-
module Hook
|
1349
|
-
|
1350
|
-
#
|
1351
|
-
# Hook Class (フッククラス)
|
1352
|
-
#
|
1353
|
-
class Hooker
|
1354
|
-
|
1355
|
-
#
|
1356
|
-
# initializer (イニシャライザ)
|
1357
|
-
#
|
1358
|
-
def initialize
|
1359
|
-
end
|
1360
|
-
|
1361
|
-
def do_action(elm)
|
1362
|
-
#内容あり要素の場合
|
1363
|
-
if elm.empty then
|
1364
|
-
elm2 = elm.child()
|
1365
|
-
execute(elm2)
|
1366
|
-
end
|
1367
|
-
end
|
1368
|
-
|
1369
|
-
#def execute(elm)
|
1370
|
-
#end
|
1371
|
-
#private :execute
|
1372
|
-
end
|
1373
|
-
|
1374
|
-
#
|
1375
|
-
# Lopp Hook Class (ループフッククラス)
|
1376
|
-
#
|
1377
|
-
class Looper
|
1378
|
-
|
1379
|
-
#
|
1380
|
-
# initializer (イニシャライザ)
|
1381
|
-
#
|
1382
|
-
def initialize
|
1383
|
-
end
|
1384
|
-
|
1385
|
-
def do_action(elm, list)
|
1386
|
-
#内容あり要素の場合
|
1387
|
-
if elm.empty then
|
1388
|
-
elm2 = elm.child()
|
1389
|
-
init(elm2)
|
1390
|
-
list.each do |item|
|
1391
|
-
if !elm2.mono then
|
1392
|
-
elm2.parser.root_element.document = elm.mixed_content
|
1393
|
-
end
|
1394
|
-
execute(elm2, item)
|
1395
|
-
elm2.flush
|
1396
|
-
end
|
1397
|
-
end
|
1398
|
-
end
|
1399
|
-
|
1400
|
-
#def init(elm)
|
1401
|
-
#end
|
1402
|
-
#private :init
|
1403
|
-
|
1404
|
-
#def execute(elm,item)
|
1405
|
-
#end
|
1406
|
-
#private :execute
|
1407
|
-
|
1408
|
-
end
|
1409
|
-
end
|
1410
|
-
|
1411
1332
|
module Exception
|
1412
1333
|
|
1413
1334
|
#
|
1414
1335
|
# Element Search Exception (要素検索例外)
|
1415
1336
|
#
|
1337
|
+
# @!attribute [rw] message
|
1338
|
+
# @return [String] message (メッセージ)
|
1339
|
+
#
|
1416
1340
|
class NoSuchElementException
|
1417
1341
|
|
1418
|
-
attr_accessor :message
|
1342
|
+
attr_accessor :message
|
1419
1343
|
|
1420
1344
|
#
|
1421
1345
|
# initializer (イニシャライザ)
|
@@ -1494,6 +1418,15 @@ module Meteor
|
|
1494
1418
|
#
|
1495
1419
|
# Parser Core Class (パーサコアクラス)
|
1496
1420
|
#
|
1421
|
+
# @!attribute [rw] element_cache
|
1422
|
+
# @return [Hash] element cache (要素キャッシュ)
|
1423
|
+
# @!attribute [rw] doc_type
|
1424
|
+
# @return [Fixnum] document type (ドキュメントタイプ)
|
1425
|
+
# @!attribute [rw] document_hook
|
1426
|
+
# @return [String] hook document (フック・ドキュメント)
|
1427
|
+
# @!attribute [rw] element_hook
|
1428
|
+
# @return [Meteor::Element] element (要素)
|
1429
|
+
#
|
1497
1430
|
class Kernel < Meteor::Parser
|
1498
1431
|
|
1499
1432
|
EMPTY = ''
|
@@ -1587,14 +1520,23 @@ module Meteor
|
|
1587
1520
|
#TAG_SEARCH_NC_4_7_2 = "\")(?:[^<>\\/]*>|(?!([^<>]*\\/>))[^<>]*>))("
|
1588
1521
|
|
1589
1522
|
#find
|
1523
|
+
# E
|
1590
1524
|
PATTERN_FIND_1 = '^([^,\\[\\]#\\.]+)$'
|
1525
|
+
# #id_attribute_value
|
1591
1526
|
PATTERN_FIND_2_1 = '^#([^\\.,\\[\\]#][^,\\[\\]#]*)$'
|
1527
|
+
# .class_attribute_value
|
1592
1528
|
PATTERN_FIND_2_2 = '^\\.([^\\.,\\[\\]#][^,\\[\\]#]*)$'
|
1529
|
+
# [attribute_name=attribute_value]
|
1593
1530
|
PATTERN_FIND_2_3 = '^\\[([^\\[\\],]+)=([^\\[\\],]+)\\]$'
|
1531
|
+
# E[attribute_name=attribute_value]
|
1594
1532
|
PATTERN_FIND_3_1 = '^([^\\.,\\[\\]#][^,\\[\\]#]+)\\[([^,\\[\\]]+)=([^,\\[\\]]+)\\]$'
|
1533
|
+
# E#id_attribute_value
|
1595
1534
|
PATTERN_FIND_3_2 = '^([^\\.,\\[\\]#][^,\\[\\]#]+)#([^\\.,\\[\\]#][^,\\[\\]#]*)$'
|
1535
|
+
# E.class_attribute_value
|
1596
1536
|
PATTERN_FIND_3_3 = '^([^\\.,\\[\\]#][^,\\[\\]#]+)\\.([^\\.,\\[\\]#][^,\\[\\]#]*)$'
|
1537
|
+
# [attribute_name1=attribute_value1][attribute_name2=attribute_value2]
|
1597
1538
|
PATTERN_FIND_4 = '^\\[([^,]+)=([^,]+)\\]\\[([^,]+)=([^,]+)\\]$'
|
1539
|
+
# E[attribute_name1=attribute_value1][attribute_name2=attribute_value2]
|
1598
1540
|
PATTERN_FIND_5 = '^([^\\.,\\[\\]#][^,\\[\\]#]+)\\[([^,]+)=([^,]+)\\]\\[([^,]+)=([^,]+)\\]$'
|
1599
1541
|
|
1600
1542
|
@@pattern_find_1 = Regexp.new(PATTERN_FIND_1)
|
@@ -1729,27 +1671,14 @@ module Meteor
|
|
1729
1671
|
CSS_ID = 'id'
|
1730
1672
|
CSS_CLASS = 'class'
|
1731
1673
|
|
1732
|
-
|
1733
|
-
|
1734
|
-
|
1735
|
-
|
1736
|
-
#親要素
|
1737
|
-
#@parent = nil
|
1738
|
-
|
1739
|
-
#正規表現パターン
|
1740
|
-
#@pattern = nil
|
1741
|
-
#ルート要素
|
1742
|
-
@root = RootElement.new
|
1743
|
-
@root.parser = self
|
1744
|
-
#要素キャッシュ
|
1745
|
-
@element_cache = Hash.new()
|
1746
|
-
#フックドキュメント
|
1747
|
-
@document_hook = ''
|
1748
|
-
end
|
1674
|
+
attr_accessor :element_cache
|
1675
|
+
attr_accessor :doc_type
|
1676
|
+
attr_accessor :document_hook
|
1677
|
+
attr_accessor :element_hook
|
1749
1678
|
|
1750
1679
|
#
|
1751
1680
|
# set document (ドキュメントをセットする)
|
1752
|
-
#
|
1681
|
+
#
|
1753
1682
|
# @param [String] doc document (ドキュメント)
|
1754
1683
|
#
|
1755
1684
|
def document=(doc)
|
@@ -1764,11 +1693,6 @@ module Meteor
|
|
1764
1693
|
@root.document
|
1765
1694
|
end
|
1766
1695
|
|
1767
|
-
attr_accessor :element_cache #[Hash] element cache (要素キャッシュ)
|
1768
|
-
attr_accessor :doc_type #[Fixnum] document type (ドキュメントタイプ)
|
1769
|
-
attr_accessor :document_hook #[String] hook document (フック・ドキュメント)
|
1770
|
-
attr_accessor :element_hook #[Meteor::Element] element (要素)
|
1771
|
-
|
1772
1696
|
#
|
1773
1697
|
# set character encoding (文字エンコーディングをセットする)
|
1774
1698
|
# @param [String] enc character encoding (文字エンコーディング)
|
@@ -1793,6 +1717,24 @@ module Meteor
|
|
1793
1717
|
@root
|
1794
1718
|
end
|
1795
1719
|
|
1720
|
+
#
|
1721
|
+
# initializer (イニシャライザ)
|
1722
|
+
#
|
1723
|
+
def initialize
|
1724
|
+
#親要素
|
1725
|
+
#@parent = nil
|
1726
|
+
|
1727
|
+
#正規表現パターン
|
1728
|
+
#@pattern = nil
|
1729
|
+
#ルート要素
|
1730
|
+
@root = RootElement.new
|
1731
|
+
@root.parser = self
|
1732
|
+
#要素キャッシュ
|
1733
|
+
@element_cache = Hash.new
|
1734
|
+
#フックドキュメント
|
1735
|
+
@document_hook = ''
|
1736
|
+
end
|
1737
|
+
|
1796
1738
|
#
|
1797
1739
|
# read file , set in parser (ファイルを読み込み、パーサにセットする)
|
1798
1740
|
# @param [String] file_path absolute path of input file (入力ファイルの絶対パス)
|
@@ -1803,7 +1745,7 @@ module Meteor
|
|
1803
1745
|
#try {
|
1804
1746
|
@character_encoding = enc
|
1805
1747
|
#ファイルのオープン
|
1806
|
-
if ParserFactory::ENC_UTF8.eql?(enc)
|
1748
|
+
if ParserFactory::ENC_UTF8.eql?(enc)
|
1807
1749
|
#io = File.open(file_path,MODE_BF << enc)
|
1808
1750
|
io = File.open(file_path, MODE_UTF8)
|
1809
1751
|
else
|
@@ -1811,18 +1753,21 @@ module Meteor
|
|
1811
1753
|
end
|
1812
1754
|
|
1813
1755
|
#読込及び格納
|
1814
|
-
|
1756
|
+
@root.document = io.read
|
1757
|
+
|
1758
|
+
parse
|
1815
1759
|
|
1816
1760
|
#ファイルのクローズ
|
1817
1761
|
io.close
|
1762
|
+
|
1763
|
+
return @root.document
|
1818
1764
|
end
|
1819
1765
|
|
1820
1766
|
#
|
1821
|
-
#
|
1767
|
+
# psrse document (ドキュメントを解析する)
|
1822
1768
|
# @param [String] document document (ドキュメント)
|
1823
1769
|
#
|
1824
|
-
def parse
|
1825
|
-
@root.document = document
|
1770
|
+
def parse
|
1826
1771
|
end
|
1827
1772
|
|
1828
1773
|
#
|
@@ -1832,13 +1777,13 @@ module Meteor
|
|
1832
1777
|
# @param [String] tag tag name (タグ名)
|
1833
1778
|
# @return [Meteor::Element] element(要素)
|
1834
1779
|
# @overload element(tag,attrs)
|
1835
|
-
# 要素のタグ名と属性(属性名="属性値")あるいは属性1・属性2(属性名="属性値")で要素を取得する
|
1836
|
-
# @param [String] tag タグ名
|
1837
|
-
# @param [Hash] attrs 属性マップ
|
1838
|
-
# @return [Meteor::Element] 要素
|
1839
|
-
# @overload element(attrs)
|
1840
|
-
# get element using
|
1841
|
-
# @param [Hash] attrs attribute map (属性マップ)
|
1780
|
+
# get element using tag name and attribute map (要素のタグ名と属性(属性名="属性値")あるいは属性1・属性2(属性名="属性値")で要素を取得する)
|
1781
|
+
# @param [String] tag tag name (タグ名)
|
1782
|
+
# @param [Hash<String,String>] attrs attribute map (属性マップ)
|
1783
|
+
# @return [Meteor::Element] element (要素)
|
1784
|
+
# @overload element(attrs)
|
1785
|
+
# get element using attribute map (属性(属性名="属性値")あるいは属性1・属性2(属性名="属性値")で要素を取得する)
|
1786
|
+
# @param [Hash<String,String>] attrs attribute map (属性マップ)
|
1842
1787
|
# @return [Meteor::Element] element (要素)
|
1843
1788
|
# @overload element(tag,attr_name,attr_value)
|
1844
1789
|
# get element using tag name and attribute(name="value") (要素のタグ名と属性(属性名="属性値")で要素を取得する)
|
@@ -1853,7 +1798,7 @@ module Meteor
|
|
1853
1798
|
# @return [Meteor::Element] element (要素)
|
1854
1799
|
# @overload element(tag,attr_name1,attr_value1,attr_name2,attr_value2)
|
1855
1800
|
# get element using tag name and attribute1,2(name="value") (要素のタグ名と属性1・属性2(属性名="属性値")で要素を取得する)
|
1856
|
-
# @param [String] tag
|
1801
|
+
# @param [String] tag tag name (タグ名)
|
1857
1802
|
# @param [String] attr_name1 attribute name1 (属性名1)
|
1858
1803
|
# @param [String] attr_value1 attribute value1 (属性値1)
|
1859
1804
|
# @param [String] attr_name2 attribute name2 (属性名2)
|
@@ -1863,7 +1808,7 @@ module Meteor
|
|
1863
1808
|
# get element using attribute1,2(name="value") (属性1・属性2(属性名="属性値")で要素を取得する)
|
1864
1809
|
# @param [String] attr_name1 attribute name1 (属性名1)
|
1865
1810
|
# @param [String] attr_value1 attribute value1 (属性値1)
|
1866
|
-
# @param [String] attr_name2
|
1811
|
+
# @param [String] attr_name2 attribute name2 (属性名2)
|
1867
1812
|
# @param [String] attr_value2 attribute value2 (属性値2)
|
1868
1813
|
# @return [Meteor::Element] element (要素)
|
1869
1814
|
# @overload element(elm)
|
@@ -1875,7 +1820,7 @@ module Meteor
|
|
1875
1820
|
if !attrs
|
1876
1821
|
if elm.kind_of?(String)
|
1877
1822
|
element_1(elm)
|
1878
|
-
if @elm_
|
1823
|
+
if @elm_
|
1879
1824
|
@element_cache.store(@elm_.object_id, @elm_)
|
1880
1825
|
end
|
1881
1826
|
elsif elm.kind_of?(Meteor::Element)
|
@@ -1883,12 +1828,12 @@ module Meteor
|
|
1883
1828
|
elsif elm.kind_of?(Hash)
|
1884
1829
|
if elm.size == ONE
|
1885
1830
|
element_2(elm.keys[0], elm.values[0])
|
1886
|
-
if @elm_
|
1831
|
+
if @elm_
|
1887
1832
|
@element_cache.store(@elm_.object_id, @elm_)
|
1888
1833
|
end
|
1889
1834
|
elsif elm.size == TWO
|
1890
1835
|
element_4(elm.keys[0], elm.values[0], elm.keys[1], elm.values[1])
|
1891
|
-
if @elm_
|
1836
|
+
if @elm_
|
1892
1837
|
@element_cache.store(@elm_.object_id, @elm_)
|
1893
1838
|
end
|
1894
1839
|
else
|
@@ -1900,12 +1845,12 @@ module Meteor
|
|
1900
1845
|
elsif attrs.kind_of?(Hash)
|
1901
1846
|
if attrs.size == ONE
|
1902
1847
|
element_3(elm, attrs.keys[0], attrs.values[0])
|
1903
|
-
if @elm_
|
1848
|
+
if @elm_
|
1904
1849
|
@element_cache.store(@elm_.object_id, @elm_)
|
1905
1850
|
end
|
1906
1851
|
elsif attrs.size == TWO
|
1907
1852
|
element_5(elm, attrs.keys[0], attrs.values[0], attrs.keys[1], attrs.values[1])
|
1908
|
-
if @elm_
|
1853
|
+
if @elm_
|
1909
1854
|
@element_cache.store(@elm_.object_id, @elm_)
|
1910
1855
|
end
|
1911
1856
|
else
|
@@ -1916,22 +1861,22 @@ module Meteor
|
|
1916
1861
|
case args.length
|
1917
1862
|
when ZERO
|
1918
1863
|
element_2(elm,attrs)
|
1919
|
-
if @elm_
|
1864
|
+
if @elm_
|
1920
1865
|
@element_cache.store(@elm_.object_id, @elm_)
|
1921
1866
|
end
|
1922
1867
|
when ONE
|
1923
1868
|
element_3(elm, attrs, args[0])
|
1924
|
-
if @elm_
|
1869
|
+
if @elm_
|
1925
1870
|
@element_cache.store(@elm_.object_id, @elm_)
|
1926
1871
|
end
|
1927
1872
|
when TWO
|
1928
1873
|
element_4(elm, attrs, args[0],args[1])
|
1929
|
-
if @elm_
|
1874
|
+
if @elm_
|
1930
1875
|
@element_cache.store(@elm_.object_id, @elm_)
|
1931
1876
|
end
|
1932
1877
|
when THREE
|
1933
1878
|
element_5(elm, attrs, args[0],args[1],args[2])
|
1934
|
-
if @elm_
|
1879
|
+
if @elm_
|
1935
1880
|
@element_cache.store(@elm_.object_id, @elm_)
|
1936
1881
|
end
|
1937
1882
|
else
|
@@ -1944,64 +1889,6 @@ module Meteor
|
|
1944
1889
|
end
|
1945
1890
|
end
|
1946
1891
|
|
1947
|
-
#
|
1948
|
-
# get element using selector like CSS3 (CSS3のようにセレクタを用いて要素を取得する)
|
1949
|
-
# CSS3 selector partial support (CSS3セレクタの部分的サポート)
|
1950
|
-
# @param [String] selector selector (セレクタ)
|
1951
|
-
# @return [Meteor::Element] element (要素)
|
1952
|
-
#
|
1953
|
-
def css(selector)
|
1954
|
-
#puts selector
|
1955
|
-
if @res = @@pattern_find_1.match(selector) then
|
1956
|
-
element_1(@res[1])
|
1957
|
-
if @elm_ then
|
1958
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
1959
|
-
end
|
1960
|
-
elsif @res = @@pattern_find_2_1.match(selector) then
|
1961
|
-
element_2(CSS_ID, @res[1])
|
1962
|
-
if @elm_ then
|
1963
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
1964
|
-
end
|
1965
|
-
elsif @res = @@pattern_find_3_1.match(selector) then
|
1966
|
-
element_3(@res[1], @res[2], @res[3])
|
1967
|
-
if @elm_ then
|
1968
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
1969
|
-
end
|
1970
|
-
elsif @res = @@pattern_find_3_2.match(selector) then
|
1971
|
-
element_3(@res[1], CSS_ID, @res[2])
|
1972
|
-
if @elm_ then
|
1973
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
1974
|
-
end
|
1975
|
-
elsif @res = @@pattern_find_3_3.match(selector) then
|
1976
|
-
element_3(@res[1], CSS_CLASS, @res[2])
|
1977
|
-
if @elm_ then
|
1978
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
1979
|
-
end
|
1980
|
-
elsif @res = @@pattern_find_5.match(selector) then
|
1981
|
-
element_5(@res[1], @res[2], @res[3], @res[4], @res[5])
|
1982
|
-
if @elm_ then
|
1983
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
1984
|
-
end
|
1985
|
-
elsif @res = @@pattern_find_2_3.match(selector) then
|
1986
|
-
element_2(@res[1], @res[2])
|
1987
|
-
if @elm_ then
|
1988
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
1989
|
-
end
|
1990
|
-
elsif @res = @@pattern_find_4.match(selector) then
|
1991
|
-
element_4(@res[1], @res[2], @res[3], @res[4])
|
1992
|
-
if @elm_ then
|
1993
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
1994
|
-
end
|
1995
|
-
elsif @res = @@pattern_find_2_2.match(selector) then
|
1996
|
-
element_2(CSS_CLASS, @res[1])
|
1997
|
-
if @elm_ then
|
1998
|
-
@element_cache.store(@elm_.object_id, @elm_)
|
1999
|
-
end
|
2000
|
-
else
|
2001
|
-
nil
|
2002
|
-
end
|
2003
|
-
end
|
2004
|
-
|
2005
1892
|
#
|
2006
1893
|
# get element using tag name (タグ名で検索し、要素を取得する)
|
2007
1894
|
# @param [String] tag tag name (タグ名)
|
@@ -2024,8 +1911,7 @@ module Meteor
|
|
2024
1911
|
else
|
2025
1912
|
element_with_1(tag)
|
2026
1913
|
end
|
2027
|
-
else
|
2028
|
-
|
1914
|
+
#else
|
2029
1915
|
end
|
2030
1916
|
|
2031
1917
|
@elm_
|
@@ -2083,22 +1969,19 @@ module Meteor
|
|
2083
1969
|
#
|
2084
1970
|
# get element using tag name and attribute(name="value") (要素のタグ名と属性(属性名="属性値")で検索し、要素を取得する)
|
2085
1971
|
# @param [String] tag tag name (タグ名)
|
2086
|
-
# @param [String]
|
1972
|
+
# @param [String] attr_name attribute name (属性名)
|
2087
1973
|
# @param [String] attr_value attribute value (属性値)
|
2088
1974
|
# @return [Meteor::Element] element (要素)
|
2089
1975
|
def element_3(tag, attr_name, attr_value)
|
2090
1976
|
|
2091
|
-
|
2092
|
-
@_attr_name = Regexp.quote(attr_name)
|
2093
|
-
@_attr_value = Regexp.quote(attr_value)
|
2094
|
-
|
1977
|
+
element_quote_3(tag,attr_name,attr_value)
|
2095
1978
|
|
2096
|
-
@pattern_cc_1 =
|
1979
|
+
@pattern_cc_1 = element_pattern_3
|
2097
1980
|
|
2098
1981
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc_1)
|
2099
1982
|
@res1 = @pattern.match(@root.document)
|
2100
1983
|
|
2101
|
-
if @res1 && @res1[1] || !@res1
|
1984
|
+
if @res1 && @res1[1] || !@res1
|
2102
1985
|
@res2 = element_with_3_2
|
2103
1986
|
@pattern_cc_2 = @pattern_cc
|
2104
1987
|
|
@@ -2106,8 +1989,8 @@ module Meteor
|
|
2106
1989
|
#puts @res2.regexp.to_s
|
2107
1990
|
end
|
2108
1991
|
|
2109
|
-
if @res1 && @res2
|
2110
|
-
if @res1.begin(0) < @res2.begin(0)
|
1992
|
+
if @res1 && @res2
|
1993
|
+
if @res1.begin(0) < @res2.begin(0)
|
2111
1994
|
@res = @res1
|
2112
1995
|
#@pattern_cc = @pattern_cc_1
|
2113
1996
|
if @res[1]
|
@@ -2120,7 +2003,7 @@ module Meteor
|
|
2120
2003
|
#@pattern_cc = @pattern_cc_2
|
2121
2004
|
element_with_3_1(tag)
|
2122
2005
|
end
|
2123
|
-
elsif @res1 && !@res2
|
2006
|
+
elsif @res1 && !@res2
|
2124
2007
|
@res = @res1
|
2125
2008
|
#@pattern_cc = @pattern_cc_1
|
2126
2009
|
if @res[1]
|
@@ -2128,7 +2011,7 @@ module Meteor
|
|
2128
2011
|
else
|
2129
2012
|
element_with_3_1(tag)
|
2130
2013
|
end
|
2131
|
-
elsif @res2 && !@res1
|
2014
|
+
elsif @res2 && !@res1
|
2132
2015
|
@res = @res2
|
2133
2016
|
#@pattern_cc = @pattern_cc_2
|
2134
2017
|
element_with_3_1(tag)
|
@@ -2142,6 +2025,21 @@ module Meteor
|
|
2142
2025
|
|
2143
2026
|
private :element_3
|
2144
2027
|
|
2028
|
+
def element_pattern_3
|
2029
|
+
|
2030
|
+
"<#{@_tag}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*)\\/>|<#{@_tag}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*)>(((?!(#{@_tag}[^<>]*>)).)*)<\\/#{@_tag}>"
|
2031
|
+
end
|
2032
|
+
|
2033
|
+
private :element_pattern_3
|
2034
|
+
|
2035
|
+
def element_quote_3(tag,attr_name,attr_value)
|
2036
|
+
@_tag = Regexp.quote(tag)
|
2037
|
+
@_attr_name = Regexp.quote(attr_name)
|
2038
|
+
@_attr_value = Regexp.quote(attr_value)
|
2039
|
+
end
|
2040
|
+
|
2041
|
+
private :element_quote_3
|
2042
|
+
|
2145
2043
|
def element_with_3_1(tag)
|
2146
2044
|
case @res.captures.length
|
2147
2045
|
when FOUR
|
@@ -2209,6 +2107,22 @@ module Meteor
|
|
2209
2107
|
|
2210
2108
|
def element_with_3_2
|
2211
2109
|
|
2110
|
+
element_pattern_with_3_2
|
2111
|
+
|
2112
|
+
if @sbuf.length == ZERO || @cnt != ZERO
|
2113
|
+
return nil
|
2114
|
+
end
|
2115
|
+
|
2116
|
+
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
2117
|
+
@res = @pattern.match(@root.document)
|
2118
|
+
|
2119
|
+
@res
|
2120
|
+
end
|
2121
|
+
|
2122
|
+
private :element_with_3_2
|
2123
|
+
|
2124
|
+
def element_pattern_with_3_2
|
2125
|
+
|
2212
2126
|
#@pattern_cc_1 = '' << TAG_OPEN << @_tag << TAG_SEARCH_2_1 << @_attr_name << ATTR_EQ
|
2213
2127
|
#@pattern_cc_1 << @_attr_value << TAG_SEARCH_2_4_2
|
2214
2128
|
@pattern_cc_1 = "<#{@_tag}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}(?:[^<>\\/]*>|(?:(?!([^<>]*\\/>))[^<>]*>)))"
|
@@ -2247,17 +2161,9 @@ module Meteor
|
|
2247
2161
|
|
2248
2162
|
@pattern_cc = @sbuf
|
2249
2163
|
|
2250
|
-
if @sbuf.length == ZERO || @cnt != ZERO then
|
2251
|
-
return nil
|
2252
|
-
end
|
2253
|
-
|
2254
|
-
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
2255
|
-
@res = @pattern.match(@root.document)
|
2256
|
-
|
2257
|
-
@res
|
2258
2164
|
end
|
2259
2165
|
|
2260
|
-
private :
|
2166
|
+
private :element_pattern_with_3_2
|
2261
2167
|
|
2262
2168
|
def element_without_3(tag)
|
2263
2169
|
element_without_3_1(tag, TAG_SEARCH_NC_2_3_2)
|
@@ -2292,18 +2198,15 @@ module Meteor
|
|
2292
2198
|
# @return [Meteor::Element] element (要素)
|
2293
2199
|
#
|
2294
2200
|
def element_2(attr_name, attr_value)
|
2295
|
-
@_attr_name = Regexp.quote(attr_name)
|
2296
|
-
@_attr_value = Regexp.quote(attr_value)
|
2297
|
-
#=begin
|
2298
|
-
##@pattern_cc = '' << TAG_SEARCH_3_1 << @_attr_name << ATTR_EQ << @_attr_value << TAG_SEARCH_2_4
|
2299
|
-
#@pattern_cc = '' << TAG_SEARCH_3_1 << @_attr_name << ATTR_EQ << @_attr_value << TAG_SEARCH_2_4_2_3
|
2300
|
-
@pattern_cc = "<([^<>\"]*)\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\""
|
2301
2201
|
|
2302
|
-
|
2202
|
+
element_quote_2(attr_name,attr_value)
|
2303
2203
|
|
2204
|
+
element_pattern_2
|
2205
|
+
|
2206
|
+
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
2304
2207
|
@res = @pattern.match(@root.document)
|
2305
2208
|
|
2306
|
-
if @res
|
2209
|
+
if @res
|
2307
2210
|
element_3(@res[1], attr_name, attr_value)
|
2308
2211
|
else
|
2309
2212
|
puts Meteor::Exception::NoSuchElementException.new(attr_name, attr_value).message
|
@@ -2318,7 +2221,7 @@ module Meteor
|
|
2318
2221
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc_1)
|
2319
2222
|
@res1 = @pattern.match(@root.document)
|
2320
2223
|
|
2321
|
-
if @res1 && @res1[1] || !@res1
|
2224
|
+
if @res1 && @res1[1] || !@res1
|
2322
2225
|
@res2 = element_with_2_2
|
2323
2226
|
@pattern_cc_2 = @pattern_cc
|
2324
2227
|
|
@@ -2326,8 +2229,8 @@ module Meteor
|
|
2326
2229
|
#puts @res2.regexp.to_s
|
2327
2230
|
end
|
2328
2231
|
|
2329
|
-
if @res1 && @res2
|
2330
|
-
if @res1.begin(0) < @res2.begin(0)
|
2232
|
+
if @res1 && @res2
|
2233
|
+
if @res1.begin(0) < @res2.begin(0)
|
2331
2234
|
@res = @res1
|
2332
2235
|
#@pattern_cc = @pattern_cc_1
|
2333
2236
|
if @res[1]
|
@@ -2340,7 +2243,7 @@ module Meteor
|
|
2340
2243
|
#@pattern_cc = @pattern_cc_2
|
2341
2244
|
element_with_2_1
|
2342
2245
|
end
|
2343
|
-
elsif @res1 && !@res2
|
2246
|
+
elsif @res1 && !@res2
|
2344
2247
|
@res = @res1
|
2345
2248
|
#@pattern_cc = @pattern_cc_1
|
2346
2249
|
if @res[1]
|
@@ -2348,7 +2251,7 @@ module Meteor
|
|
2348
2251
|
else
|
2349
2252
|
element_with_2_1
|
2350
2253
|
end
|
2351
|
-
elsif @res2 && !@res1
|
2254
|
+
elsif @res2 && !@res1
|
2352
2255
|
@res = @res2
|
2353
2256
|
#@pattern_cc = @pattern_cc_2
|
2354
2257
|
element_with_2_1
|
@@ -2363,8 +2266,24 @@ module Meteor
|
|
2363
2266
|
|
2364
2267
|
private :element_2
|
2365
2268
|
|
2269
|
+
def element_quote_2(attr_name, attr_value)
|
2270
|
+
@_attr_name = Regexp.quote(attr_name)
|
2271
|
+
@_attr_value = Regexp.quote(attr_value)
|
2272
|
+
end
|
2273
|
+
|
2274
|
+
private :element_quote_2
|
2275
|
+
|
2276
|
+
def element_pattern_2
|
2277
|
+
|
2278
|
+
##@pattern_cc = '' << TAG_SEARCH_3_1 << @_attr_name << ATTR_EQ << @_attr_value << TAG_SEARCH_2_4
|
2279
|
+
#@pattern_cc = '' << TAG_SEARCH_3_1 << @_attr_name << ATTR_EQ << @_attr_value << TAG_SEARCH_2_4_2_3
|
2280
|
+
@pattern_cc = "<([^<>\"]*)\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\""
|
2281
|
+
end
|
2282
|
+
|
2283
|
+
private :element_pattern_2
|
2284
|
+
|
2366
2285
|
=begin
|
2367
|
-
def element_with_2_1
|
2286
|
+
def element_with_2_1
|
2368
2287
|
#puts @res.captures.length
|
2369
2288
|
case @res.captures.length
|
2370
2289
|
when FOUR
|
@@ -2452,7 +2371,7 @@ module Meteor
|
|
2452
2371
|
|
2453
2372
|
@pattern_cc = @sbuf
|
2454
2373
|
|
2455
|
-
if @sbuf.length == ZERO || @cnt != ZERO
|
2374
|
+
if @sbuf.length == ZERO || @cnt != ZERO
|
2456
2375
|
return nil
|
2457
2376
|
end
|
2458
2377
|
|
@@ -2524,19 +2443,14 @@ module Meteor
|
|
2524
2443
|
#
|
2525
2444
|
def element_5(tag, attr_name1, attr_value1, attr_name2, attr_value2)
|
2526
2445
|
|
2527
|
-
|
2528
|
-
@_attr_name1 = Regexp.quote(attr_name1)
|
2529
|
-
@_attr_name2 = Regexp.quote(attr_name2)
|
2530
|
-
@_attr_value1 = Regexp.quote(attr_value1)
|
2531
|
-
@_attr_value2 = Regexp.quote(attr_value2)
|
2532
|
-
|
2446
|
+
element_quote_5(tag, attr_name1, attr_value1, attr_name2, attr_value2)
|
2533
2447
|
|
2534
2448
|
@pattern_cc_1 = "<#{@_tag}(\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")[^<>]*)\\/>|<#{@_tag}(\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")[^<>]*)>(((?!(#{@_tag}[^<>]*>)).)*)<\\/#{@_tag}>"
|
2535
2449
|
|
2536
2450
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc_1)
|
2537
2451
|
@res1 = @pattern.match(@root.document)
|
2538
2452
|
|
2539
|
-
if @res1 && @res1[1] || !@res1
|
2453
|
+
if @res1 && @res1[1] || !@res1
|
2540
2454
|
@res2 = element_with_5_2
|
2541
2455
|
@pattern_cc_2 = @pattern_cc
|
2542
2456
|
|
@@ -2544,8 +2458,8 @@ module Meteor
|
|
2544
2458
|
#puts @res2.regexp.to_s
|
2545
2459
|
end
|
2546
2460
|
|
2547
|
-
if @res1 && @res2
|
2548
|
-
if @res1.begin(0) < @res2.begin(0)
|
2461
|
+
if @res1 && @res2
|
2462
|
+
if @res1.begin(0) < @res2.begin(0)
|
2549
2463
|
@res = @res1
|
2550
2464
|
#@pattern_cc = @pattern_cc_1
|
2551
2465
|
if @res[1]
|
@@ -2558,7 +2472,7 @@ module Meteor
|
|
2558
2472
|
#@pattern_cc = @pattern_cc_2
|
2559
2473
|
element_with_5_1(tag)
|
2560
2474
|
end
|
2561
|
-
elsif @res1 && !@res2
|
2475
|
+
elsif @res1 && !@res2
|
2562
2476
|
@res = @res1
|
2563
2477
|
#@pattern_cc = @pattern_cc_1
|
2564
2478
|
if @res[1]
|
@@ -2566,7 +2480,7 @@ module Meteor
|
|
2566
2480
|
else
|
2567
2481
|
element_with_5_1(tag)
|
2568
2482
|
end
|
2569
|
-
elsif @res2 && !@res1
|
2483
|
+
elsif @res2 && !@res1
|
2570
2484
|
@res = @res2
|
2571
2485
|
#@pattern_cc = @pattern_cc_2
|
2572
2486
|
element_with_5_1(tag)
|
@@ -2580,6 +2494,16 @@ module Meteor
|
|
2580
2494
|
|
2581
2495
|
private :element_5
|
2582
2496
|
|
2497
|
+
def element_quote_5(tag, attr_name1, attr_value1, attr_name2, attr_value2)
|
2498
|
+
@_tag = Regexp.quote(tag)
|
2499
|
+
@_attr_name1 = Regexp.quote(attr_name1)
|
2500
|
+
@_attr_name2 = Regexp.quote(attr_name2)
|
2501
|
+
@_attr_value1 = Regexp.quote(attr_value1)
|
2502
|
+
@_attr_value2 = Regexp.quote(attr_value2)
|
2503
|
+
end
|
2504
|
+
|
2505
|
+
private :element_quote_5
|
2506
|
+
|
2583
2507
|
def element_with_5_1(tag)
|
2584
2508
|
|
2585
2509
|
#puts @res.captures.length
|
@@ -2654,6 +2578,22 @@ module Meteor
|
|
2654
2578
|
|
2655
2579
|
def element_with_5_2
|
2656
2580
|
|
2581
|
+
element_pattern_with_5_2
|
2582
|
+
|
2583
|
+
if @sbuf.length == ZERO || @cnt != ZERO
|
2584
|
+
return nil
|
2585
|
+
end
|
2586
|
+
|
2587
|
+
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
2588
|
+
@res = @pattern.match(@root.document)
|
2589
|
+
|
2590
|
+
@res
|
2591
|
+
end
|
2592
|
+
|
2593
|
+
private :element_with_5_2
|
2594
|
+
|
2595
|
+
def element_pattern_with_5_2
|
2596
|
+
|
2657
2597
|
#@pattern_cc_1 = '' << TAG_OPEN << @_tag << TAG_SEARCH_2_1_2 << @_attr_name1 << ATTR_EQ
|
2658
2598
|
#@pattern_cc_1 << @_attr_value1 << TAG_SEARCH_2_6 << @_attr_name2 << ATTR_EQ
|
2659
2599
|
#@pattern_cc_1 << @_attr_value2 << TAG_SEARCH_2_7 << @_attr_name2 << ATTR_EQ
|
@@ -2701,17 +2641,9 @@ module Meteor
|
|
2701
2641
|
|
2702
2642
|
@pattern_cc = @sbuf
|
2703
2643
|
|
2704
|
-
if @sbuf.length == ZERO || @cnt != ZERO then
|
2705
|
-
return nil
|
2706
|
-
end
|
2707
|
-
|
2708
|
-
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
2709
|
-
@res = @pattern.match(@root.document)
|
2710
|
-
|
2711
|
-
@res
|
2712
2644
|
end
|
2713
2645
|
|
2714
|
-
private :
|
2646
|
+
private :element_pattern_with_5_2
|
2715
2647
|
|
2716
2648
|
def element_without_5(tag)
|
2717
2649
|
element_without_5_1(tag, TAG_SEARCH_NC_2_3_2_2)
|
@@ -2754,23 +2686,14 @@ module Meteor
|
|
2754
2686
|
#
|
2755
2687
|
def element_4(attr_name1, attr_value1, attr_name2, attr_value2)
|
2756
2688
|
|
2757
|
-
|
2758
|
-
@_attr_name2 = Regexp.quote(attr_name2)
|
2759
|
-
@_attr_value1 = Regexp.quote(attr_value1)
|
2760
|
-
@_attr_value2 = Regexp.quote(attr_value2)
|
2689
|
+
element_quote_4(attr_name1, attr_value1, attr_name2, attr_value2)
|
2761
2690
|
|
2762
|
-
|
2763
|
-
#@pattern_cc << @_attr_value1 << TAG_SEARCH_2_6 << @_attr_name2 << ATTR_EQ
|
2764
|
-
#@pattern_cc << @_attr_value2 << TAG_SEARCH_2_7 << @_attr_name2 << ATTR_EQ
|
2765
|
-
#@pattern_cc << @_attr_value2 << TAG_SEARCH_2_6 << @_attr_name1 << ATTR_EQ
|
2766
|
-
#@pattern_cc << @_attr_value1 << TAG_SEARCH_2_4_2_3
|
2767
|
-
@pattern_cc = "<([^<>\"]*)\\s[^<>]*(#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")"
|
2691
|
+
element_pattern_4
|
2768
2692
|
|
2769
2693
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
2770
|
-
|
2771
2694
|
@res = @pattern.match(@root.document)
|
2772
2695
|
|
2773
|
-
if @res
|
2696
|
+
if @res
|
2774
2697
|
#@elm_ = element_5(@res[1], attr_name1, attr_value1,attr_name2, attr_value2)
|
2775
2698
|
element_5(@res[1], attr_name1, attr_value1, attr_name2, attr_value2)
|
2776
2699
|
else
|
@@ -2783,24 +2706,46 @@ module Meteor
|
|
2783
2706
|
|
2784
2707
|
private :element_4
|
2785
2708
|
|
2709
|
+
def element_quote_4(attr_name1, attr_value1, attr_name2, attr_value2)
|
2710
|
+
@_attr_name1 = Regexp.quote(attr_name1)
|
2711
|
+
@_attr_name2 = Regexp.quote(attr_name2)
|
2712
|
+
@_attr_value1 = Regexp.quote(attr_value1)
|
2713
|
+
@_attr_value2 = Regexp.quote(attr_value2)
|
2714
|
+
end
|
2715
|
+
|
2716
|
+
private :element_quote_4
|
2717
|
+
|
2718
|
+
def element_pattern_4
|
2719
|
+
|
2720
|
+
#@pattern_cc = '' << TAG_SEARCH_3_1_2_2 << @_attr_name1 << ATTR_EQ
|
2721
|
+
#@pattern_cc << @_attr_value1 << TAG_SEARCH_2_6 << @_attr_name2 << ATTR_EQ
|
2722
|
+
#@pattern_cc << @_attr_value2 << TAG_SEARCH_2_7 << @_attr_name2 << ATTR_EQ
|
2723
|
+
#@pattern_cc << @_attr_value2 << TAG_SEARCH_2_6 << @_attr_name1 << ATTR_EQ
|
2724
|
+
#@pattern_cc << @_attr_value1 << TAG_SEARCH_2_4_2_3
|
2725
|
+
@pattern_cc = "<([^<>\"]*)\\s[^<>]*(#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")"
|
2726
|
+
|
2727
|
+
end
|
2728
|
+
|
2729
|
+
private :element_pattern_4
|
2730
|
+
|
2786
2731
|
def create_element_pattern
|
2787
2732
|
@position = 0
|
2788
2733
|
|
2789
2734
|
while (@res = @pattern.match(@root.document, @position)) || @cnt > ZERO
|
2790
2735
|
|
2791
|
-
if @res
|
2736
|
+
if @res
|
2792
2737
|
|
2793
|
-
if @cnt > ZERO
|
2738
|
+
if @cnt > ZERO
|
2794
2739
|
|
2795
2740
|
@position2 = @res.end(0)
|
2796
2741
|
|
2797
2742
|
@res = @pattern_2.match(@root.document, @position)
|
2798
2743
|
|
2799
|
-
if @res
|
2744
|
+
if @res
|
2800
2745
|
|
2801
2746
|
@position = @res.end(0)
|
2802
2747
|
|
2803
|
-
if @position > @position2
|
2748
|
+
if @position > @position2
|
2804
2749
|
|
2805
2750
|
@sbuf << @pattern_cc_1_2
|
2806
2751
|
|
@@ -2811,7 +2756,7 @@ module Meteor
|
|
2811
2756
|
|
2812
2757
|
@cnt -= ONE
|
2813
2758
|
|
2814
|
-
if @cnt != ZERO
|
2759
|
+
if @cnt != ZERO
|
2815
2760
|
@sbuf << @pattern_cc_2_1
|
2816
2761
|
else
|
2817
2762
|
@sbuf << @pattern_cc_2_2
|
@@ -2836,17 +2781,17 @@ module Meteor
|
|
2836
2781
|
end
|
2837
2782
|
else
|
2838
2783
|
|
2839
|
-
if @cnt == ZERO
|
2784
|
+
if @cnt == ZERO
|
2840
2785
|
break
|
2841
2786
|
end
|
2842
2787
|
|
2843
2788
|
@res = @pattern_2.match(@root.document, @position)
|
2844
2789
|
|
2845
|
-
if @res
|
2790
|
+
if @res
|
2846
2791
|
|
2847
2792
|
@cnt -= ONE
|
2848
2793
|
|
2849
|
-
if @cnt != ZERO
|
2794
|
+
if @cnt != ZERO
|
2850
2795
|
@sbuf << @pattern_cc_2_1
|
2851
2796
|
else
|
2852
2797
|
@sbuf << @pattern_cc_2_2
|
@@ -2872,19 +2817,19 @@ module Meteor
|
|
2872
2817
|
|
2873
2818
|
while (@res = @pattern.match(@root.document, @position)) || @cnt > ZERO
|
2874
2819
|
|
2875
|
-
if @res
|
2820
|
+
if @res
|
2876
2821
|
|
2877
|
-
if @cnt > ZERO
|
2822
|
+
if @cnt > ZERO
|
2878
2823
|
|
2879
2824
|
@position2 = @res.end(0)
|
2880
2825
|
|
2881
2826
|
@res = @pattern_2.match(@root.document, @position)
|
2882
2827
|
|
2883
|
-
if @res
|
2828
|
+
if @res
|
2884
2829
|
|
2885
2830
|
@position = @res.end(0)
|
2886
2831
|
|
2887
|
-
if @position > @position2
|
2832
|
+
if @position > @position2
|
2888
2833
|
|
2889
2834
|
@sbuf << @pattern_cc_1_2
|
2890
2835
|
|
@@ -2895,7 +2840,7 @@ module Meteor
|
|
2895
2840
|
|
2896
2841
|
@cnt -= ONE
|
2897
2842
|
|
2898
|
-
if @cnt != ZERO
|
2843
|
+
if @cnt != ZERO
|
2899
2844
|
@sbuf << @pattern_cc_2_1
|
2900
2845
|
else
|
2901
2846
|
@sbuf << @pattern_cc_2_2
|
@@ -2904,68 +2849,296 @@ module Meteor
|
|
2904
2849
|
|
2905
2850
|
end
|
2906
2851
|
else
|
2907
|
-
|
2908
|
-
@sbuf << @pattern_cc_1_2
|
2909
|
-
|
2910
|
-
@cnt += 1
|
2911
|
-
|
2912
|
-
@position = @position2
|
2852
|
+
|
2853
|
+
@sbuf << @pattern_cc_1_2
|
2854
|
+
|
2855
|
+
@cnt += 1
|
2856
|
+
|
2857
|
+
@position = @position2
|
2858
|
+
end
|
2859
|
+
else
|
2860
|
+
@position = @res.end(0)
|
2861
|
+
|
2862
|
+
@_tag = @res[1]
|
2863
|
+
|
2864
|
+
create_pattern_2(args_cnt)
|
2865
|
+
|
2866
|
+
@sbuf << @pattern_cc_1_1
|
2867
|
+
|
2868
|
+
@cnt += ONE
|
2869
|
+
|
2870
|
+
end
|
2871
|
+
else
|
2872
|
+
|
2873
|
+
if @cnt == ZERO
|
2874
|
+
break
|
2875
|
+
end
|
2876
|
+
|
2877
|
+
@res = @pattern_2.match(@root.document, @position)
|
2878
|
+
|
2879
|
+
if @res
|
2880
|
+
|
2881
|
+
@cnt -= ONE
|
2882
|
+
|
2883
|
+
if @cnt != ZERO
|
2884
|
+
@sbuf << @pattern_cc_2_1
|
2885
|
+
else
|
2886
|
+
@sbuf << @pattern_cc_2_2
|
2887
|
+
break
|
2888
|
+
end
|
2889
|
+
|
2890
|
+
@position = @res.end(0)
|
2891
|
+
else
|
2892
|
+
break
|
2893
|
+
end
|
2894
|
+
|
2895
|
+
end
|
2896
|
+
|
2897
|
+
@pattern = @pattern_1b
|
2898
|
+
end
|
2899
|
+
end
|
2900
|
+
|
2901
|
+
private :create_element_pattern_2
|
2902
|
+
|
2903
|
+
#def create_pattern_2
|
2904
|
+
#end
|
2905
|
+
|
2906
|
+
#private :create_pattern_2
|
2907
|
+
=end
|
2908
|
+
|
2909
|
+
# get elements (要素を取得する)
|
2910
|
+
# @overload elements(tag)
|
2911
|
+
# get elements using tag name (要素のタグ名で要素を取得する)
|
2912
|
+
# @param [String] tag tag name (タグ名)
|
2913
|
+
# @return [Array<Meteor::Element>] element array(要素配列)
|
2914
|
+
# @overload elements(tag,attrs)
|
2915
|
+
# get elements using tag name and attribute map (要素のタグ名と属性(属性名="属性値")あるいは属性1・属性2(属性名="属性値")で要素を取得する)
|
2916
|
+
# @param [String] tag tag name (タグ名)
|
2917
|
+
# @param [Hash<String,String>] attrs attribute map (属性マップ)
|
2918
|
+
# @return [Array<Meteor::Element>] element array (要素配列)
|
2919
|
+
# @overload elements(attrs)
|
2920
|
+
# get elements using attribute map (属性(属性名="属性値")あるいは属性1・属性2(属性名="属性値")で要素を取得する)
|
2921
|
+
# @param [Hash<String,String>] attrs attribute map (属性マップ)
|
2922
|
+
# @return [Array<Meteor::Element>] element array (要素配列)
|
2923
|
+
# @overload elements(tag,attr_name,attr_value)
|
2924
|
+
# get elements using tag name and attribute(name="value") (要素のタグ名と属性(属性名="属性値")で要素を取得する)
|
2925
|
+
# @param [String] tag tag name (タグ名)
|
2926
|
+
# @param [String] attr_name attribute name (属性名)
|
2927
|
+
# @param [String] attr_value attribute value (属性値)
|
2928
|
+
# @return [Array<Meteor::Element>] element array (要素配列)
|
2929
|
+
# @overload elements(attr_name,attr_value)
|
2930
|
+
# get elements using attribute(name="value") (属性(属性名="属性値")で要素を取得する)
|
2931
|
+
# @param [String] attr_name attribute name (属性名)
|
2932
|
+
# @param [String] attr_value attribute value (属性値)
|
2933
|
+
# @return [Array<Meteor::Element>] element array (要素配列)
|
2934
|
+
# @overload elements(tag,attr_name1,attr_value1,attr_name2,attr_value2)
|
2935
|
+
# get elements using tag name and attribute1,2(name="value") (要素のタグ名と属性1・属性2(属性名="属性値")で要素を取得する)
|
2936
|
+
# @param [String] tag tag name (タグ名)
|
2937
|
+
# @param [String] attr_name1 attribute name1 (属性名1)
|
2938
|
+
# @param [String] attr_value1 attribute value1 (属性値1)
|
2939
|
+
# @param [String] attr_name2 attribute name2 (属性名2)
|
2940
|
+
# @param [String] attr_value2 attribute value2 (属性値2)
|
2941
|
+
# @return [Array<Meteor::Element>] element array (要素配列)
|
2942
|
+
# @overload elements(attr_name1,attr_value1,attr_name2,attr_value2)
|
2943
|
+
# get elements using attribute1,2(name="value") (属性1・属性2(属性名="属性値")で要素を取得する)
|
2944
|
+
# @param [String] attr_name1 attribute name1 (属性名1)
|
2945
|
+
# @param [String] attr_value1 attribute value1 (属性値1)
|
2946
|
+
# @param [String] attr_name2 attribute name2 (属性名2)
|
2947
|
+
# @param [String] attr_value2 attribute value2 (属性値2)
|
2948
|
+
# @return [Array<Meteor::Element>] element array (要素配列)
|
2949
|
+
#
|
2950
|
+
def elements(elm, attrs = nil,*args)
|
2951
|
+
if !attrs
|
2952
|
+
if elm.kind_of?(String)
|
2953
|
+
elements_(elm)
|
2954
|
+
elsif elm.kind_of?(Hash)
|
2955
|
+
if elm.size == ONE
|
2956
|
+
elements_(elm.keys[0], elm.values[0])
|
2957
|
+
elsif elm.size == TWO
|
2958
|
+
elements_(elm.keys[0], elm.values[0], elm.keys[1], elm.values[1])
|
2959
|
+
else
|
2960
|
+
raise ArgumentError
|
2961
|
+
end
|
2962
|
+
else
|
2963
|
+
raise ArgumentError
|
2964
|
+
end
|
2965
|
+
elsif attrs.kind_of?(Hash)
|
2966
|
+
if attrs.size == ONE
|
2967
|
+
elements_(elm, attrs.keys[0], attrs.values[0])
|
2968
|
+
elsif attrs.size == TWO
|
2969
|
+
elements_(elm, attrs.keys[0], attrs.values[0], attrs.keys[1], attrs.values[1])
|
2970
|
+
else
|
2971
|
+
@elm_ = nil
|
2972
|
+
raise ArgumentError
|
2973
|
+
end
|
2974
|
+
elsif attrs.kind_of?(String)
|
2975
|
+
case args.length
|
2976
|
+
when ZERO
|
2977
|
+
elements_(elm,attrs)
|
2978
|
+
when ONE
|
2979
|
+
elements_(elm, attrs, args[0])
|
2980
|
+
when TWO
|
2981
|
+
elements_(elm, attrs, args[0],args[1])
|
2982
|
+
when THREE
|
2983
|
+
elements_(elm, attrs, args[0],args[1],args[2])
|
2984
|
+
else
|
2985
|
+
@elm_ = nil
|
2986
|
+
raise ArgumentError
|
2987
|
+
end
|
2988
|
+
else
|
2989
|
+
@elm_ = nil
|
2990
|
+
raise ArgumentError
|
2991
|
+
end
|
2992
|
+
end
|
2993
|
+
|
2994
|
+
def elements_(*args)
|
2995
|
+
elm_arr = Array.new
|
2996
|
+
|
2997
|
+
case args.size
|
2998
|
+
when ONE
|
2999
|
+
@elm_ = element_1(*args)
|
3000
|
+
when TWO
|
3001
|
+
@elm_ = element_2(*args)
|
3002
|
+
when THREE
|
3003
|
+
@elm_ = element_3(*args)
|
3004
|
+
when FOUR
|
3005
|
+
@elm_ = element_4(*args)
|
3006
|
+
when FIVE
|
3007
|
+
@elm_ = element_5(*args)
|
3008
|
+
end
|
3009
|
+
|
3010
|
+
if !@elm_
|
3011
|
+
return elm_arr
|
3012
|
+
end
|
3013
|
+
|
3014
|
+
@patten_cc = @elm_.pattern
|
3015
|
+
|
3016
|
+
@patten = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
3017
|
+
|
3018
|
+
@position = 0
|
3019
|
+
|
3020
|
+
while (@res = @pattern.match(@root.document,@position))
|
3021
|
+
|
3022
|
+
if @res
|
3023
|
+
case args.size
|
3024
|
+
when ONE
|
3025
|
+
if @elm_.empty
|
3026
|
+
element_with_1(@elm_.tag)
|
3027
|
+
else
|
3028
|
+
element_without_1(@elm_.tag)
|
3029
|
+
end
|
3030
|
+
when TWO,THREE
|
3031
|
+
if @elm_.empty
|
3032
|
+
element_with_3_1(@elm_.tag)
|
3033
|
+
else
|
3034
|
+
element_without_3(@elm_.tag)
|
3035
|
+
end
|
3036
|
+
when FOUR,FIVE
|
3037
|
+
if @elm_.empty
|
3038
|
+
element_with_5_1(@elm_.tag)
|
3039
|
+
else
|
3040
|
+
element_without_5(@elm_.tag)
|
3041
|
+
end
|
3042
|
+
end
|
3043
|
+
|
3044
|
+
@elm_.pattern = Regexp.quote(@elm_.document)
|
3045
|
+
elm_arr << @elm_
|
3046
|
+
|
3047
|
+
@element_cache.store(@elm_.object_id, @elm_)
|
3048
|
+
|
3049
|
+
@position = @res.end(0)
|
3050
|
+
else
|
3051
|
+
break
|
3052
|
+
end
|
3053
|
+
end
|
3054
|
+
|
3055
|
+
elm_arr
|
3056
|
+
end
|
3057
|
+
|
3058
|
+
#
|
3059
|
+
# get elements using selector like CSS3 (CSS3のようにセレクタを用いて要素を取得する)
|
3060
|
+
# CSS3 selector partial support (CSS3セレクタの部分的サポート)
|
3061
|
+
# @param [String] selector selector (セレクタ)
|
3062
|
+
# @return [Array<Meteor::Element>] element array (要素配列)
|
3063
|
+
#
|
3064
|
+
def find(selector)
|
3065
|
+
open_count = selector.count('[')
|
3066
|
+
|
3067
|
+
case open_count
|
3068
|
+
when ZERO
|
3069
|
+
if selector.count('#.') == 0
|
3070
|
+
if @res = @@pattern_find_1.match(selector)
|
3071
|
+
elements_(@res[1])
|
3072
|
+
else
|
3073
|
+
nil
|
3074
|
+
end
|
3075
|
+
elsif selector.count('#') == 1
|
3076
|
+
if selector[0] == '#'
|
3077
|
+
if @res = @@pattern_find_2_1.match(selector)
|
3078
|
+
elements_(CSS_ID, @res[1])
|
3079
|
+
else
|
3080
|
+
nil
|
3081
|
+
end
|
3082
|
+
else
|
3083
|
+
if @res = @@pattern_find_3_2.match(selector)
|
3084
|
+
elements_(@res[1], CSS_ID, @res[2])
|
3085
|
+
else
|
3086
|
+
nil
|
3087
|
+
end
|
3088
|
+
end
|
3089
|
+
elsif selector.count('.') == 1
|
3090
|
+
if selector[0] == '.'
|
3091
|
+
if @res = @@pattern_find_2_2.match(selector)
|
3092
|
+
elements_(CSS_CLASS, @res[1])
|
3093
|
+
else
|
3094
|
+
nil
|
3095
|
+
end
|
3096
|
+
else
|
3097
|
+
if @res = @@pattern_find_3_3.match(selector)
|
3098
|
+
elements_(@res[1], CSS_CLASS, @res[2])
|
3099
|
+
else
|
3100
|
+
nil
|
3101
|
+
end
|
3102
|
+
end
|
3103
|
+
end
|
3104
|
+
when ONE
|
3105
|
+
if selector[0] == '['
|
3106
|
+
if @res = @@pattern_find_2_3.match(selector)
|
3107
|
+
elements_(@res[1], @res[2])
|
3108
|
+
else
|
3109
|
+
nil
|
2913
3110
|
end
|
2914
3111
|
else
|
2915
|
-
@
|
2916
|
-
|
2917
|
-
|
2918
|
-
|
2919
|
-
|
2920
|
-
|
2921
|
-
@sbuf << @pattern_cc_1_1
|
2922
|
-
|
2923
|
-
@cnt += ONE
|
2924
|
-
|
2925
|
-
end
|
2926
|
-
else
|
2927
|
-
|
2928
|
-
if @cnt == ZERO then
|
2929
|
-
break
|
3112
|
+
if @res = @@pattern_find_3_1.match(selector)
|
3113
|
+
elements_(@res[1], @res[2], @res[3])
|
3114
|
+
else
|
3115
|
+
nil
|
3116
|
+
end
|
2930
3117
|
end
|
2931
|
-
|
2932
|
-
|
2933
|
-
|
2934
|
-
|
2935
|
-
|
2936
|
-
@cnt -= ONE
|
2937
|
-
|
2938
|
-
if @cnt != ZERO then
|
2939
|
-
@sbuf << @pattern_cc_2_1
|
3118
|
+
when 2
|
3119
|
+
if selector[0] == '['
|
3120
|
+
if @res = @@pattern_find_4.match(selector)
|
3121
|
+
elements_(@res[1], @res[2], @res[3], @res[4])
|
2940
3122
|
else
|
2941
|
-
|
2942
|
-
break
|
3123
|
+
nil
|
2943
3124
|
end
|
2944
|
-
|
2945
|
-
@position = @res.end(0)
|
2946
3125
|
else
|
2947
|
-
|
3126
|
+
if @res = @@pattern_find_5.match(selector)
|
3127
|
+
elements_(@res[1], @res[2], @res[3], @res[4], @res[5])
|
3128
|
+
else
|
3129
|
+
nil
|
3130
|
+
end
|
2948
3131
|
end
|
2949
|
-
|
2950
|
-
|
2951
|
-
|
2952
|
-
@pattern = @pattern_1b
|
3132
|
+
else
|
3133
|
+
nil
|
2953
3134
|
end
|
2954
3135
|
end
|
2955
3136
|
|
2956
|
-
private :create_element_pattern_2
|
2957
|
-
|
2958
|
-
#def create_pattern_2
|
2959
|
-
#end
|
2960
|
-
|
2961
|
-
#private :create_pattern_2
|
2962
|
-
=end
|
2963
|
-
|
2964
3137
|
#
|
2965
3138
|
# @overload attr(elm,attr)
|
2966
3139
|
# set attribute of element (要素の属性をセットする)
|
2967
3140
|
# @param [Meteor::Element] elm element (要素)
|
2968
|
-
# @param [Hash] attr attribute (属性)
|
3141
|
+
# @param [Hash<String,String>] attr attribute (属性)
|
2969
3142
|
# @return [Meteor::Element] element (要素)
|
2970
3143
|
# @overload attr(elm,attr_name,attr_value)
|
2971
3144
|
# set attribute of element (要素の属性をセットする)
|
@@ -3010,7 +3183,7 @@ module Meteor
|
|
3010
3183
|
# @return [Meteor::Element] element (要素)
|
3011
3184
|
#
|
3012
3185
|
def set_attribute_3(elm, attr_name, attr_value)
|
3013
|
-
if !elm.cx
|
3186
|
+
if !elm.cx
|
3014
3187
|
attr_value = escape(attr_value.to_s)
|
3015
3188
|
#属性群の更新
|
3016
3189
|
edit_attrs_(elm, attr_name, attr_value)
|
@@ -3026,7 +3199,7 @@ module Meteor
|
|
3026
3199
|
#@res = @pattern.match(elm.attributes)
|
3027
3200
|
|
3028
3201
|
#検索対象属性の存在判定
|
3029
|
-
if elm.attributes.include?(' ' << attr_name << ATTR_EQ)
|
3202
|
+
if elm.attributes.include?(' ' << attr_name << ATTR_EQ)
|
3030
3203
|
|
3031
3204
|
@_attr_value = attr_value
|
3032
3205
|
|
@@ -3040,7 +3213,7 @@ module Meteor
|
|
3040
3213
|
#属性文字列の最後に新規の属性を追加する
|
3041
3214
|
@_attr_value = attr_value
|
3042
3215
|
|
3043
|
-
if EMPTY != elm.attributes && EMPTY != elm.attributes.strip
|
3216
|
+
if EMPTY != elm.attributes && EMPTY != elm.attributes.strip
|
3044
3217
|
elm.attributes = '' << SPACE << elm.attributes.strip
|
3045
3218
|
else
|
3046
3219
|
elm.attributes = ''
|
@@ -3073,7 +3246,7 @@ module Meteor
|
|
3073
3246
|
|
3074
3247
|
@res = @pattern.match(elm.attributes)
|
3075
3248
|
|
3076
|
-
if @res
|
3249
|
+
if @res
|
3077
3250
|
unescape(@res[1])
|
3078
3251
|
else
|
3079
3252
|
nil
|
@@ -3084,9 +3257,11 @@ module Meteor
|
|
3084
3257
|
|
3085
3258
|
#
|
3086
3259
|
# @overload attrs(elm,attrs)
|
3087
|
-
# @param
|
3088
|
-
#
|
3260
|
+
# @param [Meteor::element] elm element (要素)
|
3261
|
+
# @param [Hash<String,String>] attrs attribute map (属性マップ)
|
3089
3262
|
# @overload attrs(elm)
|
3263
|
+
# @param [Meteor::element] elm element (要素)
|
3264
|
+
# @return [Hash<String,String>] attribute map (要素マップ)
|
3090
3265
|
#
|
3091
3266
|
def attrs(elm,*args)
|
3092
3267
|
case args.length
|
@@ -3113,7 +3288,7 @@ module Meteor
|
|
3113
3288
|
#
|
3114
3289
|
# get attribute map (属性マップを取得する)
|
3115
3290
|
# @param [Meteor::Element] elm element (要素)
|
3116
|
-
# @return [Hash] attribute map (属性マップ)
|
3291
|
+
# @return [Hash<String,String>] attribute map (属性マップ)
|
3117
3292
|
#
|
3118
3293
|
def get_attrs(elm)
|
3119
3294
|
attrs = Hash.new
|
@@ -3130,11 +3305,11 @@ module Meteor
|
|
3130
3305
|
#
|
3131
3306
|
# set attribute map (要素に属性マップをセットする)
|
3132
3307
|
# @param [Meteor::Element] elm element (要素)
|
3133
|
-
# @param [Hash] attr_map attribute map (属性マップ)
|
3308
|
+
# @param [Hash<String,String>] attr_map attribute map (属性マップ)
|
3134
3309
|
# @return [Meteor::Element] element (要素)
|
3135
3310
|
#
|
3136
3311
|
def set_attrs(elm, attr_map)
|
3137
|
-
if !elm.cx
|
3312
|
+
if !elm.cx
|
3138
3313
|
elm.document_sync = true
|
3139
3314
|
attr_map.each do |name, value|
|
3140
3315
|
set_attribute_3(elm, name, value)
|
@@ -3161,7 +3336,7 @@ module Meteor
|
|
3161
3336
|
when ZERO
|
3162
3337
|
get_attr_map(elm)
|
3163
3338
|
when ONE
|
3164
|
-
#if elm.kind_of?(Meteor::Element) && args[0].kind_of?(Meteor::AttributeMap)
|
3339
|
+
#if elm.kind_of?(Meteor::Element) && args[0].kind_of?(Meteor::AttributeMap)
|
3165
3340
|
elm.document_sync = true
|
3166
3341
|
set_attr_map(elm, args[0])
|
3167
3342
|
#end
|
@@ -3195,11 +3370,11 @@ module Meteor
|
|
3195
3370
|
# @return [Meteor::Element] element (要素)
|
3196
3371
|
#
|
3197
3372
|
def set_attr_map(elm, attr_map)
|
3198
|
-
if !elm.cx
|
3373
|
+
if !elm.cx
|
3199
3374
|
attr_map.map.each do |name, attr|
|
3200
|
-
if attr_map.changed(name)
|
3375
|
+
if attr_map.changed(name)
|
3201
3376
|
edit_attrs_(elm, name, attr.value)
|
3202
|
-
elsif attr_map.removed(name)
|
3377
|
+
elsif attr_map.removed(name)
|
3203
3378
|
remove_attrs_(elm, name)
|
3204
3379
|
end
|
3205
3380
|
end
|
@@ -3229,18 +3404,18 @@ module Meteor
|
|
3229
3404
|
def content(*args)
|
3230
3405
|
case args.length
|
3231
3406
|
when ONE
|
3232
|
-
#if args[0].kind_of?(Meteor::Element)
|
3407
|
+
#if args[0].kind_of?(Meteor::Element)
|
3233
3408
|
get_content_1(args[0])
|
3234
3409
|
#else
|
3235
3410
|
# raise ArgumentError
|
3236
3411
|
#end
|
3237
3412
|
when TWO
|
3238
|
-
#if args[0].kind_of?(Meteor::Element) && args[1].kind_of?(String)
|
3413
|
+
#if args[0].kind_of?(Meteor::Element) && args[1].kind_of?(String)
|
3239
3414
|
args[0].document_sync = true
|
3240
3415
|
set_content_2(args[0], args[1])
|
3241
|
-
|
3242
|
-
|
3243
|
-
|
3416
|
+
#else
|
3417
|
+
# raise ArgumentError
|
3418
|
+
#end
|
3244
3419
|
when THREE
|
3245
3420
|
args[0].document_sync = true
|
3246
3421
|
set_content_3(args[0], args[1], args[2])
|
@@ -3258,7 +3433,7 @@ module Meteor
|
|
3258
3433
|
#
|
3259
3434
|
def set_content_3(elm, content, entity_ref=true)
|
3260
3435
|
|
3261
|
-
if entity_ref
|
3436
|
+
if entity_ref
|
3262
3437
|
escape_content(content, elm)
|
3263
3438
|
end
|
3264
3439
|
elm.mixed_content = content
|
@@ -3287,8 +3462,8 @@ module Meteor
|
|
3287
3462
|
# @return [String] content (内容)
|
3288
3463
|
#
|
3289
3464
|
def get_content_1(elm)
|
3290
|
-
if !elm.cx
|
3291
|
-
if elm.empty
|
3465
|
+
if !elm.cx
|
3466
|
+
if elm.empty
|
3292
3467
|
unescape_content(elm.mixed_content, elm)
|
3293
3468
|
else
|
3294
3469
|
nil
|
@@ -3307,7 +3482,7 @@ module Meteor
|
|
3307
3482
|
# @return [Meteor::Element] element (要素)
|
3308
3483
|
#
|
3309
3484
|
def remove_attr(elm, attr_name)
|
3310
|
-
if !elm.cx
|
3485
|
+
if !elm.cx
|
3311
3486
|
elm.document_sync = true
|
3312
3487
|
remove_attrs_(elm, attr_name)
|
3313
3488
|
end
|
@@ -3341,23 +3516,23 @@ module Meteor
|
|
3341
3516
|
# @overload cxtag(tag,id)
|
3342
3517
|
# get cx(comment extension) tag using tag name and id attribute (要素のタグ名とID属性(id="ID属性値")でCX(コメント拡張)タグを取得する)
|
3343
3518
|
# @param [String] tag tag name (タグ名)
|
3344
|
-
# @param [String] id
|
3519
|
+
# @param [String] id id attribute value (ID属性値)
|
3345
3520
|
# @return [Meteor::Element] element (要素)
|
3346
3521
|
# @overload cxtag(id)
|
3347
3522
|
# get cx(comment extension) tag using id attribute (ID属性(id="ID属性値")でCX(コメント拡張)タグを取得する)
|
3348
|
-
# @param [String] id
|
3523
|
+
# @param [String] id id attribute value (ID属性値)
|
3349
3524
|
# @return [Meteor::Element] element (要素)
|
3350
3525
|
#
|
3351
3526
|
def cxtag(*args)
|
3352
3527
|
case args.length
|
3353
3528
|
when ONE
|
3354
3529
|
cxtag_1(args[0])
|
3355
|
-
if @elm_
|
3530
|
+
if @elm_
|
3356
3531
|
@element_cache.store(@elm_.object_id, @elm_)
|
3357
3532
|
end
|
3358
3533
|
when TWO
|
3359
3534
|
cxtag_2(args[0], args[1])
|
3360
|
-
if @elm_
|
3535
|
+
if @elm_
|
3361
3536
|
@element_cache.store(@elm_.object_id, @elm_)
|
3362
3537
|
end
|
3363
3538
|
else
|
@@ -3368,7 +3543,7 @@ module Meteor
|
|
3368
3543
|
#
|
3369
3544
|
# get cx(comment extension) tag using tag name and id attribute (要素のタグ名とID属性(id="ID属性値")でCX(コメント拡張)タグを取得する)
|
3370
3545
|
# @param [String] tag tag name (タグ名)
|
3371
|
-
# @param [String] id
|
3546
|
+
# @param [String] id id attribute value (ID属性値)
|
3372
3547
|
# @return [Meteor::Element] element (要素)
|
3373
3548
|
#
|
3374
3549
|
def cxtag_2(tag, id)
|
@@ -3386,7 +3561,7 @@ module Meteor
|
|
3386
3561
|
#CXタグ検索
|
3387
3562
|
@res = @pattern.match(@root.document)
|
3388
3563
|
|
3389
|
-
if @res
|
3564
|
+
if @res
|
3390
3565
|
#要素
|
3391
3566
|
@elm_ = Meteor::Element.new(tag)
|
3392
3567
|
|
@@ -3414,7 +3589,7 @@ module Meteor
|
|
3414
3589
|
|
3415
3590
|
#
|
3416
3591
|
# get cx(comment extension) tag using id attribute (ID属性(id="ID属性値")で検索し、CX(コメント拡張)タグを取得する)
|
3417
|
-
# @param [String] id
|
3592
|
+
# @param [String] id id attribute value (ID属性値)
|
3418
3593
|
# @return [Meteor::Element] element (要素)
|
3419
3594
|
#
|
3420
3595
|
def cxtag_1(id)
|
@@ -3428,7 +3603,7 @@ module Meteor
|
|
3428
3603
|
|
3429
3604
|
@res = @pattern.match(@root.document)
|
3430
3605
|
|
3431
|
-
if @res
|
3606
|
+
if @res
|
3432
3607
|
#@elm_ = cxtag(@res[1],id)
|
3433
3608
|
cxtag(@res[1], id)
|
3434
3609
|
else
|
@@ -3443,7 +3618,7 @@ module Meteor
|
|
3443
3618
|
#
|
3444
3619
|
# replace element (要素を置換する)
|
3445
3620
|
# @param [Meteor::Element] elm element (要素)
|
3446
|
-
# @param [String]
|
3621
|
+
# @param [String] replace_document string for replacement (置換文字列)
|
3447
3622
|
#
|
3448
3623
|
def replace(elm, replace_document)
|
3449
3624
|
#タグ置換パターン
|
@@ -3457,10 +3632,10 @@ module Meteor
|
|
3457
3632
|
def reflect
|
3458
3633
|
#puts @element_cache.size.to_s
|
3459
3634
|
@element_cache.values.each do |item|
|
3460
|
-
if item.usable
|
3635
|
+
if item.usable
|
3461
3636
|
#puts "#{item.name}:#{item.document}"
|
3462
|
-
if !item.removed
|
3463
|
-
if item.copy
|
3637
|
+
if !item.removed
|
3638
|
+
if item.copy
|
3464
3639
|
@pattern = Meteor::Core::Util::PatternCache.get(item.pattern)
|
3465
3640
|
@root.document.sub!(@pattern, item.copy.parser.document_hook)
|
3466
3641
|
#item.copy.parser.element_cache.clear
|
@@ -3486,27 +3661,6 @@ module Meteor
|
|
3486
3661
|
private :edit_document_1
|
3487
3662
|
|
3488
3663
|
def edit_document_2(elm, closer)
|
3489
|
-
#if !elm.cx then
|
3490
|
-
# @_attributes = elm.attributes
|
3491
|
-
#
|
3492
|
-
# if elm.empty then
|
3493
|
-
# #内容あり要素の場合
|
3494
|
-
# @_content = elm.mixed_content
|
3495
|
-
#
|
3496
|
-
# elm.document = '' << TAG_OPEN << elm.name << @_attributes << TAG_CLOSE << @_content << TAG_OPEN3 << elm.name << TAG_CLOSE
|
3497
|
-
# #elm.document = "<#{elm.name}#{@_attributes}>#{@_content}</#{elm.name}>"
|
3498
|
-
# else
|
3499
|
-
# #空要素の場合
|
3500
|
-
# elm.document = '' << TAG_OPEN << elm.name << @_attributes << closer
|
3501
|
-
# #elm.document = "<#{elm.name}#{@_attributes}#{closer}"
|
3502
|
-
# end
|
3503
|
-
#else
|
3504
|
-
# @_content = elm.mixed_content
|
3505
|
-
#
|
3506
|
-
# #elm.document = '' << SET_CX_1 << elm.name << SPACE << elm.attributes << SET_CX_2
|
3507
|
-
# #elm.document << @_content << SET_CX_3 << elm.name << SET_CX_4
|
3508
|
-
# elm.document = "<!-- @#{elm.name} #{elm.attributes}-->#{@_content}<!-- /@#{elm.name} -->"
|
3509
|
-
#end
|
3510
3664
|
|
3511
3665
|
#タグ置換
|
3512
3666
|
@pattern = Meteor::Core::Util::PatternCache.get(elm.pattern)
|
@@ -3520,36 +3674,36 @@ module Meteor
|
|
3520
3674
|
#
|
3521
3675
|
def flush
|
3522
3676
|
|
3523
|
-
if self.element_hook
|
3524
|
-
if self.element_hook.origin.mono
|
3525
|
-
if self.element_hook.origin.cx
|
3526
|
-
#@root.hookDocument << SET_CX_1 << @root.element.
|
3677
|
+
if self.element_hook
|
3678
|
+
if self.element_hook.origin.mono
|
3679
|
+
if self.element_hook.origin.cx
|
3680
|
+
#@root.hookDocument << SET_CX_1 << @root.element.tag << SPACE
|
3527
3681
|
#@root.hookDocument << @root.element.attributes << SET_CX_2
|
3528
3682
|
#@root.hookDocument << @root.element.mixed_content << SET_CX_3
|
3529
|
-
#@root.hookDocument << @root.element.
|
3530
|
-
self.document_hook << "<!-- @#{self.element_hook.
|
3683
|
+
#@root.hookDocument << @root.element.tag << SET_CX_4
|
3684
|
+
self.document_hook << "<!-- @#{self.element_hook.tag} #{self.element_hook.attributes}-->#{self.element_hook.mixed_content}<!-- /@#{self.element_hook.tag} -->"
|
3531
3685
|
else
|
3532
|
-
#@root.hookDocument << TAG_OPEN << @root.element.
|
3686
|
+
#@root.hookDocument << TAG_OPEN << @root.element.tag
|
3533
3687
|
#@root.hookDocument << @root.element.attributes << TAG_CLOSE << @root.element.mixed_content
|
3534
|
-
#@root.hookDocument << TAG_OPEN3 << @root.element.
|
3535
|
-
self.document_hook << "<#{self.element_hook.
|
3688
|
+
#@root.hookDocument << TAG_OPEN3 << @root.element.tag << TAG_CLOSE
|
3689
|
+
self.document_hook << "<#{self.element_hook.tag}#{self.element_hook.attributes}>#{self.element_hook.mixed_content}</#{self.element_hook.tag}>"
|
3536
3690
|
end
|
3537
3691
|
self.element_hook = Element.new!(self.element_hook.origin, self)
|
3538
3692
|
else
|
3539
3693
|
reflect
|
3540
3694
|
@_attributes = self.element_hook.attributes
|
3541
3695
|
|
3542
|
-
if self.element_hook.origin.cx
|
3543
|
-
#@root.hookDocument << SET_CX_1 << @root.element.
|
3696
|
+
if self.element_hook.origin.cx
|
3697
|
+
#@root.hookDocument << SET_CX_1 << @root.element.tag << SPACE
|
3544
3698
|
#@root.hookDocument << @_attributes << SET_CX_2
|
3545
3699
|
#@root.hookDocument << @root.document << SET_CX_3
|
3546
|
-
#@root.hookDocument << @root.element.
|
3547
|
-
self.document_hook << "<!-- @#{self.element_hook.
|
3700
|
+
#@root.hookDocument << @root.element.tag << SET_CX_4
|
3701
|
+
self.document_hook << "<!-- @#{self.element_hook.tag} #{@_attributes}-->#{@root.document}<!-- /@#{self.element_hook.tag} -->"
|
3548
3702
|
else
|
3549
|
-
#@root.hookDocument << TAG_OPEN << @root.element.
|
3703
|
+
#@root.hookDocument << TAG_OPEN << @root.element.tag
|
3550
3704
|
#@root.hookDocument << @_attributes << TAG_CLOSE << @root.document
|
3551
|
-
#@root.hookDocument << TAG_OPEN3 << @root.element.
|
3552
|
-
self.document_hook << "<#{self.element_hook.
|
3705
|
+
#@root.hookDocument << TAG_OPEN3 << @root.element.tag << TAG_CLOSE
|
3706
|
+
self.document_hook << "<#{self.element_hook.tag}#{@_attributes}>#{@root.document}</#{self.element_hook.tag}>"
|
3553
3707
|
end
|
3554
3708
|
self.element_hook = Element.new!(self.element_hook.origin, self)
|
3555
3709
|
end
|
@@ -3568,19 +3722,19 @@ module Meteor
|
|
3568
3722
|
#CX終了タグ置換
|
3569
3723
|
@pattern = @@pattern_clean2
|
3570
3724
|
@root.document.gsub!(@pattern, EMPTY)
|
3571
|
-
|
3725
|
+
# @root.document << "<!-- Powered by Meteor (C)Yasumasa Ashida -->"
|
3572
3726
|
end
|
3573
3727
|
|
3574
3728
|
private :clean
|
3575
3729
|
|
3576
3730
|
#
|
3577
|
-
# mirror element 要素を射影する
|
3731
|
+
# mirror element (要素を射影する)
|
3578
3732
|
#
|
3579
3733
|
# @param [Meteor::Element] elm element (要素)
|
3580
3734
|
# @return [Meteor::Element] element (要素)
|
3581
3735
|
#
|
3582
3736
|
def shadow(elm)
|
3583
|
-
if elm.empty
|
3737
|
+
if elm.empty
|
3584
3738
|
#内容あり要素の場合
|
3585
3739
|
set_mono_info(elm)
|
3586
3740
|
|
@@ -3588,7 +3742,7 @@ module Meteor
|
|
3588
3742
|
|
3589
3743
|
@elm_ = Element.new!(elm, pif2)
|
3590
3744
|
|
3591
|
-
if !elm.mono
|
3745
|
+
if !elm.mono
|
3592
3746
|
pif2.root_element.document = String.new(elm.mixed_content)
|
3593
3747
|
else
|
3594
3748
|
pif2.root_element.document = String.new(elm.document)
|
@@ -3604,54 +3758,20 @@ module Meteor
|
|
3604
3758
|
|
3605
3759
|
@res = @@pattern_set_mono1.match(elm.mixed_content)
|
3606
3760
|
|
3607
|
-
if @res
|
3761
|
+
if @res
|
3608
3762
|
elm.mono = true
|
3609
3763
|
end
|
3610
3764
|
end
|
3611
3765
|
|
3612
3766
|
private :set_mono_info
|
3613
3767
|
|
3614
|
-
#
|
3615
|
-
# @overload execute(elm,hook)
|
3616
|
-
# run action of Hooker (Hookerクラスの処理を実行する)
|
3617
|
-
# @param [Meteor::Element] elm element (要素)
|
3618
|
-
# @param [Meteor::Hook::Hooker] hook Hooker object (Hookerオブジェクト)
|
3619
|
-
# @overload execute(elm,loop,list)
|
3620
|
-
# run action of Looper (Looperクラスの処理を実行する)
|
3621
|
-
# @param [Meteor::Element] elm element (要素)
|
3622
|
-
# @param [Meteor::Element::Looper] loop Looper object (Looperオブジェクト)
|
3623
|
-
# @param [Array] array(配列)
|
3624
|
-
#
|
3625
|
-
def execute(*args)
|
3626
|
-
case args.length
|
3627
|
-
when TWO
|
3628
|
-
execute_2(args[0], args[1])
|
3629
|
-
when THREE
|
3630
|
-
execute_3(args[0], args[1], args[2])
|
3631
|
-
else
|
3632
|
-
raise ArgumentError
|
3633
|
-
end
|
3634
|
-
end
|
3635
|
-
|
3636
|
-
def execute_2(elm, hook)
|
3637
|
-
hook.do_action(elm)
|
3638
|
-
end
|
3639
|
-
|
3640
|
-
private :execute_2
|
3641
|
-
|
3642
|
-
def execute_3(elm, loop, list)
|
3643
|
-
loop.do_action(elm, list)
|
3644
|
-
end
|
3645
|
-
|
3646
|
-
private :execute_3
|
3647
|
-
|
3648
3768
|
def is_match(regex, str)
|
3649
|
-
if regex.kind_of?(Regexp)
|
3769
|
+
if regex.kind_of?(Regexp)
|
3650
3770
|
is_match_r(regex, str)
|
3651
|
-
elsif regex.kind_of?(Array)
|
3771
|
+
elsif regex.kind_of?(Array)
|
3652
3772
|
is_match_a(regex, str)
|
3653
|
-
elsif regex.kind_of?(String)
|
3654
|
-
if regex.eql?(str.downcase)
|
3773
|
+
elsif regex.kind_of?(String)
|
3774
|
+
if regex.eql?(str.downcase)
|
3655
3775
|
true
|
3656
3776
|
else
|
3657
3777
|
false
|
@@ -3664,7 +3784,7 @@ module Meteor
|
|
3664
3784
|
private :is_match
|
3665
3785
|
|
3666
3786
|
def is_match_r(regex, str)
|
3667
|
-
if regex.match(str.downcase)
|
3787
|
+
if regex.match(str.downcase)
|
3668
3788
|
true
|
3669
3789
|
else
|
3670
3790
|
false
|
@@ -3676,7 +3796,7 @@ module Meteor
|
|
3676
3796
|
def is_match_a(regex, str)
|
3677
3797
|
str = str.downcase
|
3678
3798
|
regex.each do |item|
|
3679
|
-
if item.eql?(str)
|
3799
|
+
if item.eql?(str)
|
3680
3800
|
return true
|
3681
3801
|
end
|
3682
3802
|
end
|
@@ -3686,7 +3806,7 @@ module Meteor
|
|
3686
3806
|
private :is_match_a
|
3687
3807
|
|
3688
3808
|
def is_match_s(regex, str)
|
3689
|
-
if regex.match(str.downcase)
|
3809
|
+
if regex.match(str.downcase)
|
3690
3810
|
true
|
3691
3811
|
else
|
3692
3812
|
false
|
@@ -3697,15 +3817,15 @@ module Meteor
|
|
3697
3817
|
|
3698
3818
|
def create(pif)
|
3699
3819
|
case pif.doc_type
|
3700
|
-
when Parser::HTML
|
3820
|
+
when Parser::HTML
|
3701
3821
|
Meteor::Ml::Html::ParserImpl.new
|
3702
|
-
when Parser::XHTML
|
3822
|
+
when Parser::XHTML
|
3703
3823
|
Meteor::Ml::Xhtml::ParserImpl.new
|
3704
|
-
when Parser::HTML5
|
3824
|
+
when Parser::HTML5
|
3705
3825
|
Meteor::Ml::Html5::ParserImpl.new
|
3706
|
-
when Parser::XHTML5
|
3826
|
+
when Parser::XHTML5
|
3707
3827
|
Meteor::Ml::Xhtml5::ParserImpl.new
|
3708
|
-
when Parser::XML
|
3828
|
+
when Parser::XML
|
3709
3829
|
Meteor::Ml::Xml::ParserImpl.new
|
3710
3830
|
else
|
3711
3831
|
nil
|
@@ -3716,118 +3836,6 @@ module Meteor
|
|
3716
3836
|
|
3717
3837
|
end
|
3718
3838
|
|
3719
|
-
if RUBY_VERSION < RUBY_VERSION_1_9_0 then
|
3720
|
-
class Kernel
|
3721
|
-
MODE = 'r'
|
3722
|
-
|
3723
|
-
#
|
3724
|
-
# read file , set in parser (ファイルを読み込み、パーサにセットする)
|
3725
|
-
# @param [String] file_path absolute path of input file (入力ファイルの絶対パス)
|
3726
|
-
# @param [String] enc character encoding of input file (入力ファイルの文字コード)
|
3727
|
-
#
|
3728
|
-
def read(file_path, enc)
|
3729
|
-
|
3730
|
-
#try {
|
3731
|
-
@character_encoding = enc
|
3732
|
-
#ファイルのオープン
|
3733
|
-
|
3734
|
-
#読込及び格納
|
3735
|
-
io = open(file_path, MODE)
|
3736
|
-
parse(io.read)
|
3737
|
-
#@root.document = @root.document.kconv(get_encoding(), Kconv.guess(@root.document))
|
3738
|
-
enc = Kconv.guess(@root.document)
|
3739
|
-
#enc = get_encoding
|
3740
|
-
if !Kconv::UTF8.equal?(enc) then
|
3741
|
-
parse(@root.document.kconv(Kconv::UTF8, enc))
|
3742
|
-
end
|
3743
|
-
|
3744
|
-
#ファイルのクローズ
|
3745
|
-
io.close
|
3746
|
-
end
|
3747
|
-
|
3748
|
-
def create_element_pattern
|
3749
|
-
@rx_document = @root.document
|
3750
|
-
|
3751
|
-
while (@res = @pattern.match(@rx_document)) || @cnt > ZERO
|
3752
|
-
|
3753
|
-
if @res then
|
3754
|
-
|
3755
|
-
if @cnt > ZERO then
|
3756
|
-
|
3757
|
-
@rx_document2 = @res.post_match
|
3758
|
-
|
3759
|
-
@res = @pattern_2.match(@rx_document)
|
3760
|
-
|
3761
|
-
if @res then
|
3762
|
-
|
3763
|
-
@rx_document = @res.post_match
|
3764
|
-
|
3765
|
-
if @rx_document2.length > @rx_document.length then
|
3766
|
-
|
3767
|
-
@sbuf << @pattern_cc_1_2
|
3768
|
-
|
3769
|
-
@cnt += ONE
|
3770
|
-
|
3771
|
-
@rx_document = @rx_document2
|
3772
|
-
else
|
3773
|
-
|
3774
|
-
@cnt -= ONE
|
3775
|
-
|
3776
|
-
if @cnt != ZERO then
|
3777
|
-
@sbuf << @pattern_cc_2_1
|
3778
|
-
else
|
3779
|
-
@sbuf << @pattern_cc_2_2
|
3780
|
-
break
|
3781
|
-
end
|
3782
|
-
|
3783
|
-
end
|
3784
|
-
else
|
3785
|
-
|
3786
|
-
@sbuf << @pattern_cc_1_2
|
3787
|
-
|
3788
|
-
@cnt += ONE
|
3789
|
-
|
3790
|
-
@rx_document = @rx_document2
|
3791
|
-
end
|
3792
|
-
else
|
3793
|
-
@rx_document = @res.post_match
|
3794
|
-
|
3795
|
-
@sbuf << @pattern_cc_1_1
|
3796
|
-
|
3797
|
-
@cnt += ONE
|
3798
|
-
end
|
3799
|
-
else
|
3800
|
-
|
3801
|
-
if @cnt == ZERO then
|
3802
|
-
break
|
3803
|
-
end
|
3804
|
-
|
3805
|
-
@res = @pattern_2.match(@rx_document)
|
3806
|
-
|
3807
|
-
if @res then
|
3808
|
-
|
3809
|
-
@cnt -= ONE
|
3810
|
-
|
3811
|
-
if @cnt != ZERO then
|
3812
|
-
@sbuf << @pattern_cc_2_1
|
3813
|
-
else
|
3814
|
-
@sbuf << @pattern_cc_2_2
|
3815
|
-
break
|
3816
|
-
end
|
3817
|
-
|
3818
|
-
@rx_document = @res.post_match
|
3819
|
-
else
|
3820
|
-
break
|
3821
|
-
end
|
3822
|
-
|
3823
|
-
end
|
3824
|
-
|
3825
|
-
@pattern = @pattern_1b
|
3826
|
-
end
|
3827
|
-
end
|
3828
|
-
end
|
3829
|
-
end
|
3830
|
-
|
3831
3839
|
module Util
|
3832
3840
|
|
3833
3841
|
#
|
@@ -3836,11 +3844,11 @@ module Meteor
|
|
3836
3844
|
class PatternCache
|
3837
3845
|
@@regex_cache = Hash.new
|
3838
3846
|
|
3839
|
-
|
3840
|
-
|
3841
|
-
|
3842
|
-
def initialize
|
3843
|
-
end
|
3847
|
+
##
|
3848
|
+
## intializer (イニシャライザ)
|
3849
|
+
##
|
3850
|
+
#def initialize
|
3851
|
+
#end
|
3844
3852
|
|
3845
3853
|
|
3846
3854
|
#
|
@@ -3857,14 +3865,14 @@ module Meteor
|
|
3857
3865
|
case args.length
|
3858
3866
|
when ONE
|
3859
3867
|
#get_1(args[0])
|
3860
|
-
if @@regex_cache[args[0].to_sym]
|
3868
|
+
if @@regex_cache[args[0].to_sym]
|
3861
3869
|
@@regex_cache[args[0].to_sym]
|
3862
3870
|
else
|
3863
3871
|
@@regex_cache[args[0].to_sym] = Regexp.new(args[0], Regexp::MULTILINE)
|
3864
3872
|
end
|
3865
3873
|
when TWO
|
3866
3874
|
#get_2(args[0], args[1])
|
3867
|
-
if @@regex_cache[args[0].to_sym]
|
3875
|
+
if @@regex_cache[args[0].to_sym]
|
3868
3876
|
@@regex_cache[args[0].to_sym]
|
3869
3877
|
else
|
3870
3878
|
@@regex_cache[args[0].to_sym] = Regexp.new(args[0], args[1])
|
@@ -3882,27 +3890,19 @@ module Meteor
|
|
3882
3890
|
#def self.get_1(regex)
|
3883
3891
|
# ##pattern = @@regex_cache[regex]
|
3884
3892
|
# ##
|
3885
|
-
# ##if pattern == nil
|
3886
|
-
# #if regex.kind_of?(String)
|
3887
|
-
# if !@@regex_cache[regex.to_sym]
|
3893
|
+
# ##if pattern == nil
|
3894
|
+
# #if regex.kind_of?(String)
|
3895
|
+
# if !@@regex_cache[regex.to_sym]
|
3888
3896
|
# #pattern = Regexp.new(regex)
|
3889
3897
|
# #@@regex_cache[regex] = pattern
|
3890
|
-
#
|
3891
|
-
# @@regex_cache[regex.to_sym] = Regexp.new(regex, Regexp::MULTILINE)
|
3892
|
-
# else
|
3893
|
-
# @@regex_cache[regex.to_sym] = Regexp.new(regex, Regexp::MULTILINE,E_UTF8)
|
3894
|
-
# end
|
3898
|
+
# @@regex_cache[regex.to_sym] = Regexp.new(regex, Regexp::MULTILINE)
|
3895
3899
|
# end
|
3896
3900
|
#
|
3897
3901
|
# #return pattern
|
3898
3902
|
# @@regex_cache[regex.to_sym]
|
3899
|
-
# ##elsif regex.kind_of?(Symbol)
|
3900
|
-
# ## if !@@regex_cache[regex]
|
3901
|
-
# ##
|
3902
|
-
# ## @@regex_cache[regex.object_id] = Regexp.new(regex.to_s, Regexp::MULTILINE)
|
3903
|
-
# ## else
|
3904
|
-
# ## @@regex_cache[regex.object_id] = Regexp.new(regex.to_s, Regexp::MULTILINE,E_UTF8)
|
3905
|
-
# ## end
|
3903
|
+
# ##elsif regex.kind_of?(Symbol)
|
3904
|
+
# ## if !@@regex_cache[regex]
|
3905
|
+
# ## @@regex_cache[regex.object_id] = Regexp.new(regex.to_s, Regexp::MULTILINE)
|
3906
3906
|
# ## end
|
3907
3907
|
# ##
|
3908
3908
|
# ## @@regex_cache[regex]
|
@@ -3918,9 +3918,9 @@ module Meteor
|
|
3918
3918
|
#def self.get_2(regex, option)
|
3919
3919
|
# ##pattern = @@regex_cache[regex]
|
3920
3920
|
# ##
|
3921
|
-
# ##if pattern == nil
|
3922
|
-
# #if regex.kind_of?(String)
|
3923
|
-
# if !@@regex_cache[regex.to_sym]
|
3921
|
+
# ##if pattern == nil
|
3922
|
+
# #if regex.kind_of?(String)
|
3923
|
+
# if !@@regex_cache[regex.to_sym]
|
3924
3924
|
# #pattern = Regexp.new(regex)
|
3925
3925
|
# #@@regex_cache[regex] = pattern
|
3926
3926
|
# @@regex_cache[regex.to_sym] = Regexp.new(regex, option,E_UTF8)
|
@@ -3928,8 +3928,8 @@ module Meteor
|
|
3928
3928
|
#
|
3929
3929
|
# #return pattern
|
3930
3930
|
# @@regex_cache[regex.to_sym]
|
3931
|
-
# ##elsif regex.kind_of?(Symbol)
|
3932
|
-
# ## if !@@regex_cache[regex]
|
3931
|
+
# ##elsif regex.kind_of?(Symbol)
|
3932
|
+
# ## if !@@regex_cache[regex]
|
3933
3933
|
# ## @@regex_cache[regex] = Regexp.new(regex.to_s, option,E_UTF8)
|
3934
3934
|
# ## end
|
3935
3935
|
# ##
|
@@ -3944,6 +3944,7 @@ module Meteor
|
|
3944
3944
|
|
3945
3945
|
module Ml
|
3946
3946
|
module Html
|
3947
|
+
|
3947
3948
|
#
|
3948
3949
|
# HTML parser (HTMLパーサ)
|
3949
3950
|
#
|
@@ -4045,35 +4046,33 @@ module Meteor
|
|
4045
4046
|
#@@pattern_@@match_tag = Regexp.new(@@match_tag)
|
4046
4047
|
#@@pattern_@@match_tag2 = Regexp.new(@@match_tag_2)
|
4047
4048
|
|
4048
|
-
|
4049
|
-
|
4050
|
-
|
4051
|
-
|
4052
|
-
|
4053
|
-
|
4054
|
-
|
4055
|
-
|
4056
|
-
|
4057
|
-
|
4058
|
-
|
4059
|
-
|
4060
|
-
|
4061
|
-
|
4062
|
-
|
4063
|
-
|
4064
|
-
|
4065
|
-
|
4066
|
-
|
4067
|
-
|
4068
|
-
|
4069
|
-
|
4070
|
-
|
4071
|
-
|
4072
|
-
|
4073
|
-
|
4074
|
-
|
4075
|
-
@@pattern_br_2 = Regexp.new(BR_2)
|
4076
|
-
end
|
4049
|
+
TABLE_FOR_ESCAPE_ = {
|
4050
|
+
'&' => '&',
|
4051
|
+
'"' => '"',
|
4052
|
+
'\'' => ''',
|
4053
|
+
'<' => '<',
|
4054
|
+
'>' => '>',
|
4055
|
+
' ' => ' ',
|
4056
|
+
}
|
4057
|
+
|
4058
|
+
TABLE_FOR_ESCAPE_CONTENT_ = {
|
4059
|
+
'&' => '&',
|
4060
|
+
'"' => '"',
|
4061
|
+
'\'' => ''',
|
4062
|
+
'<' => '<',
|
4063
|
+
'>' => '>',
|
4064
|
+
' ' => ' ',
|
4065
|
+
"\r\n" => '<br>',
|
4066
|
+
"\r" => '<br>',
|
4067
|
+
"\n" => '<br>',
|
4068
|
+
}
|
4069
|
+
|
4070
|
+
PATTERN_ESCAPE = "[&\"'<> ]"
|
4071
|
+
PATTERN_ESCAPE_CONTENT = "[&\"'<> \\n]"
|
4072
|
+
|
4073
|
+
@@pattern_escape = Regexp.new(PATTERN_ESCAPE)
|
4074
|
+
@@pattern_escape_content = Regexp.new(PATTERN_ESCAPE_CONTENT)
|
4075
|
+
@@pattern_br_2 = Regexp.new(BR_2)
|
4077
4076
|
|
4078
4077
|
#
|
4079
4078
|
# initializer (イニシャライザ)
|
@@ -4086,7 +4085,7 @@ module Meteor
|
|
4086
4085
|
@doc_type = Parser::HTML
|
4087
4086
|
case args.length
|
4088
4087
|
when ZERO
|
4089
|
-
initialize_0
|
4088
|
+
#initialize_0
|
4090
4089
|
when ONE
|
4091
4090
|
initialize_1(args[0])
|
4092
4091
|
else
|
@@ -4097,10 +4096,10 @@ module Meteor
|
|
4097
4096
|
#
|
4098
4097
|
# initializer (イニシャライザ)
|
4099
4098
|
#
|
4100
|
-
def initialize_0
|
4101
|
-
end
|
4102
|
-
|
4103
|
-
private :initialize_0
|
4099
|
+
#def initialize_0
|
4100
|
+
#end
|
4101
|
+
#
|
4102
|
+
#private :initialize_0
|
4104
4103
|
|
4105
4104
|
#
|
4106
4105
|
# initializer (イニシャライザ)
|
@@ -4116,31 +4115,20 @@ module Meteor
|
|
4116
4115
|
private :initialize_1
|
4117
4116
|
|
4118
4117
|
#
|
4119
|
-
#
|
4120
|
-
# @param [String] document document (ドキュメント)
|
4118
|
+
# parse document (ドキュメントを解析する)
|
4121
4119
|
#
|
4122
|
-
def parse
|
4123
|
-
|
4124
|
-
analyze_ml()
|
4120
|
+
def parse
|
4121
|
+
analyze_ml
|
4125
4122
|
end
|
4126
4123
|
|
4127
|
-
#
|
4128
|
-
# read file , set in parser (ファイルを読み込み、パーサにセットする)
|
4129
|
-
# @param [String] filePath file path (ファイルパス)
|
4130
|
-
# @param [String] enc character encoding (エンコーディング)
|
4131
|
-
#
|
4132
|
-
#def read(file_path, enc)
|
4133
|
-
# super(file_path, enc)
|
4134
|
-
#end
|
4135
|
-
|
4136
4124
|
#
|
4137
4125
|
# analyze document (ドキュメントをパースする)
|
4138
4126
|
#
|
4139
|
-
def analyze_ml
|
4127
|
+
def analyze_ml
|
4140
4128
|
#content-typeの取得
|
4141
|
-
analyze_content_type
|
4129
|
+
analyze_content_type
|
4142
4130
|
#改行コードの取得
|
4143
|
-
analyze_kaigyo_code
|
4131
|
+
analyze_kaigyo_code
|
4144
4132
|
|
4145
4133
|
@res = nil
|
4146
4134
|
end
|
@@ -4161,11 +4149,11 @@ module Meteor
|
|
4161
4149
|
def analyze_content_type
|
4162
4150
|
element_3(META_S, HTTP_EQUIV, CONTENT_TYPE)
|
4163
4151
|
|
4164
|
-
if !@elm_
|
4152
|
+
if !@elm_
|
4165
4153
|
element_3(META, HTTP_EQUIV, CONTENT_TYPE)
|
4166
4154
|
end
|
4167
4155
|
|
4168
|
-
if @elm_
|
4156
|
+
if @elm_
|
4169
4157
|
@root.content_type = @elm_.attr(CONTENT)
|
4170
4158
|
else
|
4171
4159
|
@root.content_type = EMPTY
|
@@ -4177,19 +4165,11 @@ module Meteor
|
|
4177
4165
|
#
|
4178
4166
|
# analuze document , set newline (ドキュメントをパースし、改行コードをセットする)
|
4179
4167
|
#
|
4180
|
-
def analyze_kaigyo_code
|
4168
|
+
def analyze_kaigyo_code
|
4181
4169
|
#改行コード取得
|
4182
|
-
#@pattern = Regexp.new(KAIGYO_CODE)
|
4183
|
-
#@res = @pattern.match(@root.document)
|
4184
|
-
|
4185
|
-
#if @res then
|
4186
|
-
# @root.kaigyo_code = @res[0]
|
4187
|
-
# puts "test"
|
4188
|
-
# puts @res[0]
|
4189
|
-
#end
|
4190
4170
|
|
4191
4171
|
for a in KAIGYO_CODE
|
4192
|
-
if @root.document.include?(a)
|
4172
|
+
if @root.document.include?(a)
|
4193
4173
|
@root.kaigyo_code = a
|
4194
4174
|
end
|
4195
4175
|
end
|
@@ -4207,13 +4187,13 @@ module Meteor
|
|
4207
4187
|
@_tag = Regexp.quote(tag)
|
4208
4188
|
|
4209
4189
|
#空要素の場合(<->内容あり要素の場合)
|
4210
|
-
if is_match(@@match_tag, tag)
|
4190
|
+
if is_match(@@match_tag, tag)
|
4211
4191
|
#空要素検索用パターン
|
4212
4192
|
@pattern_cc = '' << TAG_OPEN << @_tag << TAG_SEARCH_1_4_2
|
4213
4193
|
#@pattern_cc = "<#{@_tag}(|\\s[^<>]*)>"
|
4214
4194
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
4215
4195
|
@res = @pattern.match(@root.document)
|
4216
|
-
if @res
|
4196
|
+
if @res
|
4217
4197
|
element_without_1(tag)
|
4218
4198
|
else
|
4219
4199
|
puts Meteor::Exception::NoSuchElementException.new(tag).message
|
@@ -4229,7 +4209,7 @@ module Meteor
|
|
4229
4209
|
#内容あり要素検索
|
4230
4210
|
@res = @pattern.match(@root.document)
|
4231
4211
|
#内容あり要素の場合
|
4232
|
-
if @res
|
4212
|
+
if @res
|
4233
4213
|
element_with_1(tag)
|
4234
4214
|
else
|
4235
4215
|
puts Meteor::Exception::NoSuchElementException.new(tag).message
|
@@ -4265,12 +4245,10 @@ module Meteor
|
|
4265
4245
|
#
|
4266
4246
|
def element_3(tag, attr_name, attr_value)
|
4267
4247
|
|
4268
|
-
|
4269
|
-
@_attr_name = Regexp.quote(attr_name)
|
4270
|
-
@_attr_value = Regexp.quote(attr_value)
|
4248
|
+
element_quote_3(tag, attr_name, attr_value)
|
4271
4249
|
|
4272
4250
|
#空要素の場合(<->内容あり要素の場合)
|
4273
|
-
if is_match(@@match_tag, tag)
|
4251
|
+
if is_match(@@match_tag, tag)
|
4274
4252
|
#空要素検索パターン
|
4275
4253
|
#@pattern_cc = '' << TAG_OPEN << @_tag << TAG_SEARCH_2_1 << @_attr_name << ATTR_EQ
|
4276
4254
|
#@pattern_cc << @_attr_value << TAG_SEARCH_2_4_3
|
@@ -4279,7 +4257,7 @@ module Meteor
|
|
4279
4257
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
4280
4258
|
#空要素検索
|
4281
4259
|
@res = @pattern.match(@root.document)
|
4282
|
-
if @res
|
4260
|
+
if @res
|
4283
4261
|
element_without_3(tag)
|
4284
4262
|
else
|
4285
4263
|
puts Meteor::Exception::NoSuchElementException.new(tag, attr_name, attr_value).message
|
@@ -4296,11 +4274,11 @@ module Meteor
|
|
4296
4274
|
#内容あり要素検索
|
4297
4275
|
@res = @pattern.match(@root.document)
|
4298
4276
|
|
4299
|
-
if !@res && !is_match(@@match_tag_sng, tag)
|
4277
|
+
if !@res && !is_match(@@match_tag_sng, tag)
|
4300
4278
|
@res = element_with_3_2
|
4301
4279
|
end
|
4302
4280
|
|
4303
|
-
if @res
|
4281
|
+
if @res
|
4304
4282
|
element_with_3_1(tag)
|
4305
4283
|
else
|
4306
4284
|
puts Meteor::Exception::NoSuchElementException.new(tag, attr_name, attr_value).message
|
@@ -4326,8 +4304,8 @@ module Meteor
|
|
4326
4304
|
# @return [Meteor::Element] element (要素)
|
4327
4305
|
#
|
4328
4306
|
def element_2(attr_name, attr_value)
|
4329
|
-
|
4330
|
-
|
4307
|
+
|
4308
|
+
element_quote_2(attr_name, attr_value)
|
4331
4309
|
|
4332
4310
|
#@pattern_cc = '' << TAG_SEARCH_3_1 << @_attr_name << ATTR_EQ << @_attr_value
|
4333
4311
|
#@pattern_cc << TAG_SEARCH_2_4_4
|
@@ -4336,7 +4314,7 @@ module Meteor
|
|
4336
4314
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
4337
4315
|
@res = @pattern.match(@root.document)
|
4338
4316
|
|
4339
|
-
if @res
|
4317
|
+
if @res
|
4340
4318
|
element_3(@res[1], attr_name, attr_value)
|
4341
4319
|
else
|
4342
4320
|
puts Meteor::Exception::NoSuchElementException.new(attr_name, attr_value).message
|
@@ -4359,14 +4337,10 @@ module Meteor
|
|
4359
4337
|
#
|
4360
4338
|
def element_5(tag, attr_name1, attr_value1, attr_name2, attr_value2)
|
4361
4339
|
|
4362
|
-
|
4363
|
-
@_attr_name1 = Regexp.quote(attr_name1)
|
4364
|
-
@_attr_value1 = Regexp.quote(attr_value1)
|
4365
|
-
@_attr_name2 = Regexp.quote(attr_name2)
|
4366
|
-
@_attr_value2 = Regexp.quote(attr_value2)
|
4340
|
+
element_quote_5(tag, attr_name1, attr_value1, attr_name2, attr_value2)
|
4367
4341
|
|
4368
4342
|
#空要素の場合(<->内容あり要素の場合)
|
4369
|
-
if is_match(@@match_tag, tag)
|
4343
|
+
if is_match(@@match_tag, tag)
|
4370
4344
|
#空要素検索パターン
|
4371
4345
|
#@pattern_cc = '' << TAG_OPEN << @_tag << TAG_SEARCH_2_1_2 << @_attr_name1 << ATTR_EQ
|
4372
4346
|
#@pattern_cc << @_attr_value1 << TAG_SEARCH_2_6 << @_attr_name2 << ATTR_EQ
|
@@ -4379,7 +4353,7 @@ module Meteor
|
|
4379
4353
|
#空要素検索
|
4380
4354
|
@res = @pattern.match(@root.document)
|
4381
4355
|
|
4382
|
-
if @res
|
4356
|
+
if @res
|
4383
4357
|
element_without_5(tag)
|
4384
4358
|
else
|
4385
4359
|
puts Meteor::Exception::NoSuchElementException.new(tag, attr_name1, attr_value1, attr_name2, attr_value2).message
|
@@ -4399,11 +4373,11 @@ module Meteor
|
|
4399
4373
|
#内容あり要素検索
|
4400
4374
|
@res = @pattern.match(@root.document)
|
4401
4375
|
|
4402
|
-
if !@res && !is_match(@@match_tag_sng, tag)
|
4376
|
+
if !@res && !is_match(@@match_tag_sng, tag)
|
4403
4377
|
@res = element_with_5_2
|
4404
4378
|
end
|
4405
4379
|
|
4406
|
-
if @res
|
4380
|
+
if @res
|
4407
4381
|
element_with_5_1(tag)
|
4408
4382
|
else
|
4409
4383
|
puts Meteor::Exception::NoSuchElementException.new(tag, attr_name1, attr_value1, attr_name2, attr_value2).message
|
@@ -4432,10 +4406,8 @@ module Meteor
|
|
4432
4406
|
# @return [Meteor::Element] element (要素)
|
4433
4407
|
#
|
4434
4408
|
def element_4(attr_name1, attr_value1, attr_name2, attr_value2)
|
4435
|
-
|
4436
|
-
|
4437
|
-
@_attr_name2 = Regexp.quote(attr_name2)
|
4438
|
-
@_attr_value2 = Regexp.quote(attr_value2)
|
4409
|
+
|
4410
|
+
element_quote_4(attr_name1, attr_value1, attr_name2, attr_value2)
|
4439
4411
|
|
4440
4412
|
#@pattern_cc = '' << TAG_SEARCH_3_1_2_2 << @_attr_name1 << ATTR_EQ << @_attr_value1
|
4441
4413
|
#@pattern_cc << TAG_SEARCH_2_6 << @_attr_name2 << ATTR_EQ << @_attr_value2
|
@@ -4448,7 +4420,7 @@ module Meteor
|
|
4448
4420
|
|
4449
4421
|
@res = @pattern.match(@root.document)
|
4450
4422
|
|
4451
|
-
if @res
|
4423
|
+
if @res
|
4452
4424
|
element_5(@res[1], attr_name1, attr_value1, attr_name2, attr_value2)
|
4453
4425
|
else
|
4454
4426
|
puts Meteor::Exception::NoSuchElementException.new(attr_name1, attr_value1, attr_name2, attr_value2).message
|
@@ -4461,15 +4433,15 @@ module Meteor
|
|
4461
4433
|
private :element_4
|
4462
4434
|
|
4463
4435
|
def edit_attrs_(elm, attr_name, attr_value)
|
4464
|
-
if is_match(SELECTED, attr_name) && is_match(OPTION, elm.
|
4436
|
+
if is_match(SELECTED, attr_name) && is_match(OPTION, elm.tag)
|
4465
4437
|
edit_attrs_5(elm, attr_name, attr_value, @@pattern_selected_m, @@pattern_selected_r)
|
4466
|
-
elsif is_match(MULTIPLE, attr_name) && is_match(SELECT, elm.
|
4438
|
+
elsif is_match(MULTIPLE, attr_name) && is_match(SELECT, elm.tag)
|
4467
4439
|
edit_attrs_5(elm, attr_name, attr_value, @@pattern_multiple_m, @@pattern_multiple_r)
|
4468
|
-
elsif is_match(DISABLED, attr_name) && is_match(DISABLE_ELEMENT, elm.
|
4440
|
+
elsif is_match(DISABLED, attr_name) && is_match(DISABLE_ELEMENT, elm.tag)
|
4469
4441
|
edit_attrs_5(elm, attr_name, attr_value, @@pattern_disabled_m, @@pattern_disabled_r)
|
4470
|
-
elsif is_match(CHECKED, attr_name) && is_match(INPUT, elm.
|
4442
|
+
elsif is_match(CHECKED, attr_name) && is_match(INPUT, elm.tag) && is_match(RADIO, get_type(elm))
|
4471
4443
|
edit_attrs_5(elm, attr_name, attr_value, @@pattern_checked_m, @@pattern_checked_r)
|
4472
|
-
elsif is_match(READONLY, attr_name) && (is_match(TEXTAREA, elm.
|
4444
|
+
elsif is_match(READONLY, attr_name) && (is_match(TEXTAREA, elm.tag) || (is_match(INPUT, elm.tag) && is_match(READONLY_TYPE, get_type(elm))))
|
4473
4445
|
edit_attrs_5(elm, attr_name, attr_value, @@pattern_readonly_m, @@pattern_readonly_r)
|
4474
4446
|
else
|
4475
4447
|
super(elm, attr_name, attr_value)
|
@@ -4480,11 +4452,11 @@ module Meteor
|
|
4480
4452
|
|
4481
4453
|
def edit_attrs_5(elm, attr_name, attr_value, match_p, replace)
|
4482
4454
|
|
4483
|
-
if true.equal?(attr_value) || is_match(TRUE, attr_value)
|
4455
|
+
if true.equal?(attr_value) || is_match(TRUE, attr_value)
|
4484
4456
|
@res = match_p.match(elm.attributes)
|
4485
4457
|
|
4486
|
-
if !@res
|
4487
|
-
if !EMPTY.eql?(elm.attributes) && !EMPTY.eql?(elm.attributes.strip)
|
4458
|
+
if !@res
|
4459
|
+
if !EMPTY.eql?(elm.attributes) && !EMPTY.eql?(elm.attributes.strip)
|
4488
4460
|
elm.attributes = '' << SPACE << elm.attributes.strip
|
4489
4461
|
else
|
4490
4462
|
elm.attributes = ''
|
@@ -4492,7 +4464,7 @@ module Meteor
|
|
4492
4464
|
elm.attributes << SPACE << attr_name
|
4493
4465
|
#else
|
4494
4466
|
end
|
4495
|
-
elsif false.equal?(attr_value) || is_match(FALSE, attr_value)
|
4467
|
+
elsif false.equal?(attr_value) || is_match(FALSE, attr_value)
|
4496
4468
|
elm.attributes.sub!(replace, EMPTY)
|
4497
4469
|
end
|
4498
4470
|
|
@@ -4507,15 +4479,15 @@ module Meteor
|
|
4507
4479
|
private :edit_document_1
|
4508
4480
|
|
4509
4481
|
def get_attr_value_(elm, attr_name)
|
4510
|
-
if is_match(SELECTED, attr_name) && is_match(OPTION, elm.
|
4482
|
+
if is_match(SELECTED, attr_name) && is_match(OPTION, elm.tag)
|
4511
4483
|
get_attr_value_r(elm, @@pattern_selected_m)
|
4512
|
-
elsif is_match(MULTIPLE, attr_name) && is_match(SELECT, elm.
|
4484
|
+
elsif is_match(MULTIPLE, attr_name) && is_match(SELECT, elm.tag)
|
4513
4485
|
get_attr_value_r(elm, @@pattern_multiple_m)
|
4514
|
-
elsif is_match(DISABLED, attr_name) && is_match(DISABLE_ELEMENT, elm.
|
4486
|
+
elsif is_match(DISABLED, attr_name) && is_match(DISABLE_ELEMENT, elm.tag)
|
4515
4487
|
get_attr_value_r(elm, @@pattern_disabled_m)
|
4516
|
-
elsif is_match(CHECKED, attr_name) && is_match(INPUT, elm.
|
4488
|
+
elsif is_match(CHECKED, attr_name) && is_match(INPUT, elm.tag) && is_match(RADIO, get_type(elm))
|
4517
4489
|
get_attr_value_r(elm, @@pattern_checked_m)
|
4518
|
-
elsif is_match(READONLY, attr_name) && (is_match(TEXTAREA, elm.
|
4490
|
+
elsif is_match(READONLY, attr_name) && (is_match(TEXTAREA, elm.tag) || (is_match(INPUT, elm.tag) && is_match(READONLY_TYPE, get_type(elm))))
|
4519
4491
|
get_attr_value_r(elm, @@pattern_readonly_m)
|
4520
4492
|
else
|
4521
4493
|
super(elm, attr_name)
|
@@ -4527,7 +4499,7 @@ module Meteor
|
|
4527
4499
|
def get_type(elm)
|
4528
4500
|
if !elm.type_value
|
4529
4501
|
elm.type_value = get_attr_value_(elm, TYPE_L)
|
4530
|
-
if !elm.type_value
|
4502
|
+
if !elm.type_value
|
4531
4503
|
elm.type_value = get_attr_value_(elm, TYPE_U)
|
4532
4504
|
end
|
4533
4505
|
end
|
@@ -4540,7 +4512,7 @@ module Meteor
|
|
4540
4512
|
|
4541
4513
|
@res = match_p.match(elm.attributes)
|
4542
4514
|
|
4543
|
-
if @res
|
4515
|
+
if @res
|
4544
4516
|
TRUE
|
4545
4517
|
else
|
4546
4518
|
FALSE
|
@@ -4595,7 +4567,7 @@ module Meteor
|
|
4595
4567
|
|
4596
4568
|
def remove_attrs_(elm, attr_name)
|
4597
4569
|
#検索対象属性の論理型是非判定
|
4598
|
-
if !is_match(@@attr_logic, attr_name)
|
4570
|
+
if !is_match(@@attr_logic, attr_name)
|
4599
4571
|
#属性検索用パターン
|
4600
4572
|
@pattern = Meteor::Core::Util::PatternCache.get('' << attr_name << ERASE_ATTR_1)
|
4601
4573
|
#@pattern = Meteor::Core::Util::PatternCache.get("#{attr_name}=\"[^\"]*\"\\s?")
|
@@ -4634,20 +4606,22 @@ module Meteor
|
|
4634
4606
|
#「&」<-「&」
|
4635
4607
|
content.gsub(@@pattern_unescape) do
|
4636
4608
|
case $1
|
4637
|
-
when AND_3
|
4609
|
+
when AND_3
|
4638
4610
|
AND_1
|
4639
|
-
when QO_3
|
4611
|
+
when QO_3
|
4640
4612
|
DOUBLE_QUATATION
|
4641
|
-
when AP_3
|
4613
|
+
when AP_3
|
4642
4614
|
AP_1
|
4643
|
-
when GT_3
|
4615
|
+
when GT_3
|
4644
4616
|
GT_1
|
4645
|
-
when LT_3
|
4617
|
+
when LT_3
|
4646
4618
|
LT_1
|
4647
|
-
when NBSP_3
|
4619
|
+
when NBSP_3
|
4648
4620
|
SPACE
|
4649
4621
|
end
|
4650
4622
|
end
|
4623
|
+
|
4624
|
+
content
|
4651
4625
|
end
|
4652
4626
|
|
4653
4627
|
private :unescape
|
@@ -4655,9 +4629,9 @@ module Meteor
|
|
4655
4629
|
def unescape_content(content, elm)
|
4656
4630
|
content_ = unescape(content)
|
4657
4631
|
|
4658
|
-
if elm.cx || !is_match(@@match_tag_2, elm.
|
4659
|
-
|
4660
|
-
|
4632
|
+
if elm.cx || !is_match(@@match_tag_2, elm.tag)
|
4633
|
+
if content.include?(BR_2)
|
4634
|
+
#「<br>」->「¥r?¥n」
|
4661
4635
|
content_.gsub!(@@pattern_br_2, @root.kaigyo_code)
|
4662
4636
|
end
|
4663
4637
|
end
|
@@ -4669,60 +4643,6 @@ module Meteor
|
|
4669
4643
|
|
4670
4644
|
end
|
4671
4645
|
|
4672
|
-
if RUBY_VERSION < RUBY_VERSION_1_9_0 then
|
4673
|
-
class ParserImpl
|
4674
|
-
@@pattern_and_1 = Regexp.new(AND_1)
|
4675
|
-
@@pattern_lt_1 = Regexp.new(LT_1)
|
4676
|
-
@@pattern_gt_1 = Regexp.new(GT_1)
|
4677
|
-
@@pattern_dq_1 = Regexp.new(DOUBLE_QUATATION)
|
4678
|
-
@@pattern_space_1 = Regexp.new(SPACE)
|
4679
|
-
@@pattern_br_1 = Regexp.new(BR_1)
|
4680
|
-
@@pattern_lt_2 = Regexp.new(LT_2)
|
4681
|
-
@@pattern_gt_2 = Regexp.new(GT_2)
|
4682
|
-
@@pattern_dq_2 = Regexp.new(QO_2)
|
4683
|
-
@@pattern_space_2 = Regexp.new(NBSP_2)
|
4684
|
-
@@pattern_and_2 = Regexp.new(AND_2)
|
4685
|
-
@@pattern_br_2 = Regexp.new(BR_2)
|
4686
|
-
|
4687
|
-
def escape(content)
|
4688
|
-
#特殊文字の置換
|
4689
|
-
#「&」->「&」
|
4690
|
-
if content.include?(AND_1) then
|
4691
|
-
content.gsub!(@@pattern_and_1, AND_2)
|
4692
|
-
end
|
4693
|
-
#「<」->「<」
|
4694
|
-
if content.include?(LT_1) then
|
4695
|
-
content.gsub!(@@pattern_lt_1, LT_2)
|
4696
|
-
end
|
4697
|
-
#「>」->「>」
|
4698
|
-
if content.include?(GT_1) then
|
4699
|
-
content.gsub!(@@pattern_gt_1, GT_2)
|
4700
|
-
end
|
4701
|
-
#「"」->「"l」
|
4702
|
-
if content.include?(DOUBLE_QUATATION) then
|
4703
|
-
content.gsub!(@@pattern_dq_1, QO_2)
|
4704
|
-
end
|
4705
|
-
#「 」->「 」
|
4706
|
-
if content.include?(SPACE) then
|
4707
|
-
content.gsub!(@@pattern_space_1, NBSP_2)
|
4708
|
-
end
|
4709
|
-
|
4710
|
-
content
|
4711
|
-
end
|
4712
|
-
|
4713
|
-
def escape_content(content, elm)
|
4714
|
-
content = escape(content)
|
4715
|
-
|
4716
|
-
if elm.cx || !is_match(@@match_tag_2, elm.name) then
|
4717
|
-
#「¥r?¥n」->「<br>」
|
4718
|
-
content.gsub!(@@pattern_br_1, BR_2)
|
4719
|
-
end
|
4720
|
-
|
4721
|
-
content
|
4722
|
-
end
|
4723
|
-
end
|
4724
|
-
end
|
4725
|
-
|
4726
4646
|
end
|
4727
4647
|
|
4728
4648
|
module Xhtml
|
@@ -4831,33 +4751,31 @@ module Meteor
|
|
4831
4751
|
#@@pattern_@@match_tag = Regexp.new(@@match_tag)
|
4832
4752
|
#@@pattern_@@match_tag2 = Regexp.new(@@match_tag_2)
|
4833
4753
|
|
4834
|
-
|
4835
|
-
|
4836
|
-
|
4837
|
-
|
4838
|
-
|
4839
|
-
|
4840
|
-
|
4841
|
-
|
4842
|
-
|
4843
|
-
|
4844
|
-
|
4845
|
-
|
4846
|
-
|
4847
|
-
|
4848
|
-
|
4849
|
-
|
4850
|
-
|
4851
|
-
|
4852
|
-
|
4853
|
-
|
4854
|
-
|
4855
|
-
|
4856
|
-
|
4857
|
-
|
4858
|
-
|
4859
|
-
@@pattern_escape_content = Regexp.new(PATTERN_ESCAPE_CONTENT)
|
4860
|
-
end
|
4754
|
+
TABLE_FOR_ESCAPE_ = {
|
4755
|
+
'&' => '&',
|
4756
|
+
'"' => '"',
|
4757
|
+
'\'' => ''',
|
4758
|
+
'<' => '<',
|
4759
|
+
'>' => '>',
|
4760
|
+
' ' => ' ',
|
4761
|
+
}
|
4762
|
+
|
4763
|
+
TABLE_FOR_ESCAPE_CONTENT_ = {
|
4764
|
+
'&' => '&',
|
4765
|
+
'"' => '"',
|
4766
|
+
'\'' => ''',
|
4767
|
+
'<' => '<',
|
4768
|
+
'>' => '>',
|
4769
|
+
' ' => ' ',
|
4770
|
+
"\r\n" => '<br/>',
|
4771
|
+
"\r" => '<br/>',
|
4772
|
+
"\n" => '<br/>',
|
4773
|
+
}
|
4774
|
+
|
4775
|
+
PATTERN_ESCAPE = '[&"\'<> ]'
|
4776
|
+
PATTERN_ESCAPE_CONTENT = '[&"\'<> \\n]'
|
4777
|
+
@@pattern_escape = Regexp.new(PATTERN_ESCAPE)
|
4778
|
+
@@pattern_escape_content = Regexp.new(PATTERN_ESCAPE_CONTENT)
|
4861
4779
|
|
4862
4780
|
#
|
4863
4781
|
# initializer (イニシャライザ)
|
@@ -4870,7 +4788,7 @@ module Meteor
|
|
4870
4788
|
@doc_type = Parser::XHTML
|
4871
4789
|
case args.length
|
4872
4790
|
when ZERO
|
4873
|
-
initialize_0
|
4791
|
+
#initialize_0
|
4874
4792
|
when ONE
|
4875
4793
|
initialize_1(args[0])
|
4876
4794
|
else
|
@@ -4881,10 +4799,10 @@ module Meteor
|
|
4881
4799
|
#
|
4882
4800
|
# initializer (イニシャライザ)
|
4883
4801
|
#
|
4884
|
-
def initialize_0
|
4885
|
-
end
|
4886
|
-
|
4887
|
-
private :initialize_0
|
4802
|
+
#def initialize_0
|
4803
|
+
#end
|
4804
|
+
#
|
4805
|
+
#private :initialize_0
|
4888
4806
|
|
4889
4807
|
#
|
4890
4808
|
# initializer (イニシャライザ)
|
@@ -4900,27 +4818,16 @@ module Meteor
|
|
4900
4818
|
private :initialize_1
|
4901
4819
|
|
4902
4820
|
#
|
4903
|
-
#
|
4904
|
-
# @param [String] document document (ドキュメント)
|
4821
|
+
# parse document (ドキュメントを解析する)
|
4905
4822
|
#
|
4906
|
-
def parse
|
4907
|
-
|
4908
|
-
analyze_ml()
|
4823
|
+
def parse
|
4824
|
+
analyze_ml
|
4909
4825
|
end
|
4910
4826
|
|
4911
|
-
#
|
4912
|
-
# read file , set in parser (ファイルを読み込み、パーサにセットする)
|
4913
|
-
# @param file_path file path (ファイルパス)
|
4914
|
-
# @param enc character encoding (エンコーディング)
|
4915
|
-
#
|
4916
|
-
#def read(file_path, enc)
|
4917
|
-
# super(file_path, enc)
|
4918
|
-
#end
|
4919
|
-
|
4920
4827
|
#
|
4921
4828
|
# analyze document (ドキュメントをパースする)
|
4922
4829
|
#
|
4923
|
-
def analyze_ml
|
4830
|
+
def analyze_ml
|
4924
4831
|
#content-typeの取得
|
4925
4832
|
analyze_content_type
|
4926
4833
|
#改行コードの取得
|
@@ -4934,7 +4841,7 @@ module Meteor
|
|
4934
4841
|
# get content type (コンテントタイプを取得する)
|
4935
4842
|
# @return [String] content type (コンテントタイプ)
|
4936
4843
|
#
|
4937
|
-
def content_type
|
4844
|
+
def content_type
|
4938
4845
|
@root.content_type
|
4939
4846
|
end
|
4940
4847
|
|
@@ -4944,11 +4851,11 @@ module Meteor
|
|
4944
4851
|
def analyze_content_type
|
4945
4852
|
element_3(META_S, HTTP_EQUIV, CONTENT_TYPE)
|
4946
4853
|
|
4947
|
-
if !@elm_
|
4854
|
+
if !@elm_
|
4948
4855
|
element_3(META, HTTP_EQUIV, CONTENT_TYPE)
|
4949
4856
|
end
|
4950
4857
|
|
4951
|
-
if @elm_
|
4858
|
+
if @elm_
|
4952
4859
|
@root.content_type = @elm_.attr(CONTENT)
|
4953
4860
|
else
|
4954
4861
|
@root.content_type = EMPTY
|
@@ -4960,17 +4867,11 @@ module Meteor
|
|
4960
4867
|
#
|
4961
4868
|
# analyze document , set newline (ドキュメントをパースし、改行コードをセットする)
|
4962
4869
|
#
|
4963
|
-
def analyze_kaigyo_code
|
4870
|
+
def analyze_kaigyo_code
|
4964
4871
|
#改行コード取得
|
4965
|
-
#@pattern = Regexp.new(KAIGYO_CODE)
|
4966
|
-
#@res = @pattern.match(@root.document)
|
4967
|
-
|
4968
|
-
#if @res then
|
4969
|
-
# @root.kaigyo_code = @res[0]
|
4970
|
-
#end
|
4971
4872
|
|
4972
4873
|
for a in KAIGYO_CODE
|
4973
|
-
if @root.document.include?(a)
|
4874
|
+
if @root.document.include?(a)
|
4974
4875
|
@root.kaigyo_code = a
|
4975
4876
|
end
|
4976
4877
|
end
|
@@ -4980,15 +4881,15 @@ module Meteor
|
|
4980
4881
|
|
4981
4882
|
def edit_attrs_(elm, attr_name, attr_value)
|
4982
4883
|
|
4983
|
-
if is_match(SELECTED, attr_name) && is_match(OPTION, elm.
|
4884
|
+
if is_match(SELECTED, attr_name) && is_match(OPTION, elm.tag)
|
4984
4885
|
edit_attrs_5(elm, attr_value, @@pattern_selected_m, @@pattern_selected_r, SELECTED_U)
|
4985
|
-
elsif is_match(MULTIPLE, attr_name) && is_match(SELECT, elm.
|
4886
|
+
elsif is_match(MULTIPLE, attr_name) && is_match(SELECT, elm.tag)
|
4986
4887
|
edit_attrs_5(elm, attr_value, @@pattern_multiple_m, @@pattern_multiple_r, MULTIPLE_U)
|
4987
|
-
elsif is_match(DISABLED, attr_name) && is_match(DISABLE_ELEMENT, elm.
|
4888
|
+
elsif is_match(DISABLED, attr_name) && is_match(DISABLE_ELEMENT, elm.tag)
|
4988
4889
|
edit_attrs_5(elm, attr_value, @@pattern_disabled_m, @@pattern_disabled_r, DISABLED_U)
|
4989
|
-
elsif is_match(CHECKED, attr_name) && is_match(INPUT, elm.
|
4890
|
+
elsif is_match(CHECKED, attr_name) && is_match(INPUT, elm.tag) && is_match(RADIO, get_type(elm))
|
4990
4891
|
edit_attrs_5(elm, attr_value, @@pattern_checked_m, @@pattern_checked_r, CHECKED_U)
|
4991
|
-
elsif is_match(READONLY, attr_name) && (is_match(TEXTAREA, elm.
|
4892
|
+
elsif is_match(READONLY, attr_name) && (is_match(TEXTAREA, elm.tag) || (is_match(INPUT, elm.tag) && is_match(READONLY_TYPE, get_type(elm))))
|
4992
4893
|
edit_attrs_5(elm, attr_value, @@pattern_readonly_m, @@pattern_readonly_r, READONLY_U)
|
4993
4894
|
else
|
4994
4895
|
super(elm, attr_name, attr_value)
|
@@ -5002,13 +4903,13 @@ module Meteor
|
|
5002
4903
|
|
5003
4904
|
#attr_value = escape(attr_value)
|
5004
4905
|
|
5005
|
-
if true.equal?(attr_value) || is_match(TRUE, attr_value)
|
4906
|
+
if true.equal?(attr_value) || is_match(TRUE, attr_value)
|
5006
4907
|
|
5007
4908
|
@res = match_p.match(elm.attributes)
|
5008
4909
|
|
5009
|
-
if !@res
|
4910
|
+
if !@res
|
5010
4911
|
#属性文字列の最後に新規の属性を追加する
|
5011
|
-
if elm.attributes != EMPTY
|
4912
|
+
if elm.attributes != EMPTY
|
5012
4913
|
elm.attributes = '' << SPACE << elm.attributes.strip
|
5013
4914
|
#else
|
5014
4915
|
end
|
@@ -5017,7 +4918,7 @@ module Meteor
|
|
5017
4918
|
#属性の置換
|
5018
4919
|
elm.attributes.gsub!(replace_regex, replace_update)
|
5019
4920
|
end
|
5020
|
-
elsif false.equal?(attr_value) || is_match(FALSE, attr_value)
|
4921
|
+
elsif false.equal?(attr_value) || is_match(FALSE, attr_value)
|
5021
4922
|
#attr_name属性が存在するなら削除
|
5022
4923
|
#属性の置換
|
5023
4924
|
elm.attributes.gsub!(replace_regex, EMPTY)
|
@@ -5028,15 +4929,15 @@ module Meteor
|
|
5028
4929
|
private :edit_attrs_5
|
5029
4930
|
|
5030
4931
|
def get_attr_value_(elm, attr_name)
|
5031
|
-
if is_match(SELECTED, attr_name) && is_match(OPTION, elm.
|
4932
|
+
if is_match(SELECTED, attr_name) && is_match(OPTION, elm.tag)
|
5032
4933
|
get_attr_value_r(elm, attr_name, @@pattern_selected_m1)
|
5033
|
-
elsif is_match(MULTIPLE, attr_name) && is_match(SELECT, elm.
|
4934
|
+
elsif is_match(MULTIPLE, attr_name) && is_match(SELECT, elm.tag)
|
5034
4935
|
get_attr_value_r(elm, attr_name, @@pattern_multiple_m1)
|
5035
|
-
elsif is_match(DISABLED, attr_name) && is_match(DISABLE_ELEMENT, elm.
|
4936
|
+
elsif is_match(DISABLED, attr_name) && is_match(DISABLE_ELEMENT, elm.tag)
|
5036
4937
|
get_attr_value_r(elm, attr_name, @@pattern_disabled_m1)
|
5037
|
-
elsif is_match(CHECKED, attr_name) && is_match(INPUT, elm.
|
4938
|
+
elsif is_match(CHECKED, attr_name) && is_match(INPUT, elm.tag) && is_match(RADIO, get_type(elm))
|
5038
4939
|
get_attr_value_r(elm, attr_name, @@pattern_checked_m1)
|
5039
|
-
elsif is_match(READONLY, attr_name) && (is_match(TEXTAREA, elm.
|
4940
|
+
elsif is_match(READONLY, attr_name) && (is_match(TEXTAREA, elm.tag) || (is_match(INPUT, elm.tag) && is_match(READONLY_TYPE, get_type(elm))))
|
5040
4941
|
get_attr_value_r(elm, attr_name, @@pattern_readonly_m1)
|
5041
4942
|
else
|
5042
4943
|
super(elm, attr_name)
|
@@ -5048,7 +4949,7 @@ module Meteor
|
|
5048
4949
|
def get_type(elm)
|
5049
4950
|
if !elm.type_value
|
5050
4951
|
elm.type_value = get_attr_value(elm, TYPE_L)
|
5051
|
-
if !elm.type_value
|
4952
|
+
if !elm.type_value
|
5052
4953
|
elm.type_value = get_attr_value(elm, TYPE_U)
|
5053
4954
|
end
|
5054
4955
|
end
|
@@ -5061,27 +4962,27 @@ module Meteor
|
|
5061
4962
|
|
5062
4963
|
@res = match_p.match(elm.attributes)
|
5063
4964
|
|
5064
|
-
if @res
|
5065
|
-
if @res[1]
|
5066
|
-
if attr_name == @res[1]
|
4965
|
+
if @res
|
4966
|
+
if @res[1]
|
4967
|
+
if attr_name == @res[1]
|
5067
4968
|
TRUE
|
5068
4969
|
else
|
5069
4970
|
@res[1]
|
5070
4971
|
end
|
5071
|
-
elsif @res[2]
|
5072
|
-
if attr_name == @res[2]
|
4972
|
+
elsif @res[2]
|
4973
|
+
if attr_name == @res[2]
|
5073
4974
|
TRUE
|
5074
4975
|
else
|
5075
4976
|
@res[2]
|
5076
4977
|
end
|
5077
|
-
elsif @res[3]
|
5078
|
-
if attr_name == @res[3]
|
4978
|
+
elsif @res[3]
|
4979
|
+
if attr_name == @res[3]
|
5079
4980
|
TRUE
|
5080
4981
|
else
|
5081
4982
|
@res[3]
|
5082
4983
|
end
|
5083
|
-
elsif @res[4]
|
5084
|
-
if attr_name == @res[4]
|
4984
|
+
elsif @res[4]
|
4985
|
+
if attr_name == @res[4]
|
5085
4986
|
TRUE
|
5086
4987
|
else
|
5087
4988
|
@res[4]
|
@@ -5103,7 +5004,7 @@ module Meteor
|
|
5103
5004
|
attrs = Meteor::AttributeMap.new
|
5104
5005
|
|
5105
5006
|
elm.attributes.scan(@@pattern_get_attrs_map) do |a, b|
|
5106
|
-
if is_match(@@attr_logic, a) && a==b
|
5007
|
+
if is_match(@@attr_logic, a) && a==b
|
5107
5008
|
attrs.store(a, TRUE)
|
5108
5009
|
else
|
5109
5010
|
attrs.store(a, unescape(b))
|
@@ -5141,20 +5042,22 @@ module Meteor
|
|
5141
5042
|
#「&」<-「&」
|
5142
5043
|
content.gsub(@@pattern_unescape) do
|
5143
5044
|
case $1
|
5144
|
-
when AND_3
|
5045
|
+
when AND_3
|
5145
5046
|
AND_1
|
5146
|
-
when QO_3
|
5047
|
+
when QO_3
|
5147
5048
|
DOUBLE_QUATATION
|
5148
|
-
when AP_3
|
5049
|
+
when AP_3
|
5149
5050
|
AP_1
|
5150
|
-
when GT_3
|
5051
|
+
when GT_3
|
5151
5052
|
GT_1
|
5152
|
-
when LT_3
|
5053
|
+
when LT_3
|
5153
5054
|
LT_1
|
5154
|
-
when NBSP_3
|
5055
|
+
when NBSP_3
|
5155
5056
|
SPACE
|
5156
5057
|
end
|
5157
5058
|
end
|
5059
|
+
|
5060
|
+
content
|
5158
5061
|
end
|
5159
5062
|
|
5160
5063
|
private :unescape
|
@@ -5162,11 +5065,9 @@ module Meteor
|
|
5162
5065
|
def unescape_content(content, elm)
|
5163
5066
|
content_ = unescape(content)
|
5164
5067
|
|
5165
|
-
if elm.cx || !is_match(@@match_tag_2, elm.
|
5166
|
-
|
5167
|
-
if content.include?(BR_2) then
|
5068
|
+
if (elm.cx || !is_match(@@match_tag_2, elm.tag)) && content.include?(BR_2)
|
5069
|
+
#「<br>」->「¥r?¥n」
|
5168
5070
|
content_.gsub!(@@pattern_br_2, @root.kaigyo_code)
|
5169
|
-
end
|
5170
5071
|
end
|
5171
5072
|
|
5172
5073
|
content_
|
@@ -5176,66 +5077,6 @@ module Meteor
|
|
5176
5077
|
|
5177
5078
|
end
|
5178
5079
|
|
5179
|
-
if RUBY_VERSION < RUBY_VERSION_1_9_0 then
|
5180
|
-
class ParserImpl
|
5181
|
-
@@pattern_and_1 = Regexp.new(AND_1)
|
5182
|
-
@@pattern_lt_1 = Regexp.new(LT_1)
|
5183
|
-
@@pattern_gt_1 = Regexp.new(GT_1)
|
5184
|
-
@@pattern_dq_1 = Regexp.new(DOUBLE_QUATATION)
|
5185
|
-
@@pattern_ap_1 = Regexp.new(AP_1)
|
5186
|
-
@@pattern_space_1 = Regexp.new(SPACE)
|
5187
|
-
@@pattern_br_1 = Regexp.new(BR_1)
|
5188
|
-
@@pattern_lt_2 = Regexp.new(LT_2)
|
5189
|
-
@@pattern_gt_2 = Regexp.new(GT_2)
|
5190
|
-
@@pattern_dq_2 = Regexp.new(QO_2)
|
5191
|
-
@@pattern_ap_2 = Regexp.new(AP_2)
|
5192
|
-
@@pattern_space_2 = Regexp.new(NBSP_2)
|
5193
|
-
@@pattern_and_2 = Regexp.new(AND_2)
|
5194
|
-
@@pattern_br_2 = Regexp.new(BR_3)
|
5195
|
-
|
5196
|
-
def escape(content)
|
5197
|
-
#特殊文字の置換
|
5198
|
-
#「&」->「&」
|
5199
|
-
if content.include?(AND_1) then
|
5200
|
-
content.gsub!(@@pattern_and_1, AND_2)
|
5201
|
-
end
|
5202
|
-
#「<」->「<」
|
5203
|
-
if content.include?(LT_1) then
|
5204
|
-
content.gsub!(@@pattern_lt_1, LT_2)
|
5205
|
-
end
|
5206
|
-
#「>」->「>」
|
5207
|
-
if content.include?(GT_1) then
|
5208
|
-
content.gsub!(@@pattern_gt_1, GT_2)
|
5209
|
-
end
|
5210
|
-
#「"」->「"l」
|
5211
|
-
if content.include?(DOUBLE_QUATATION) then
|
5212
|
-
content.gsub!(@@pattern_dq_1, QO_2)
|
5213
|
-
end
|
5214
|
-
#「'」->「'」
|
5215
|
-
if content.include?(AP_1) then
|
5216
|
-
content.gsub!(@@pattern_ap_1, AP_2)
|
5217
|
-
end
|
5218
|
-
#「 」->「 」
|
5219
|
-
if content.include?(SPACE) then
|
5220
|
-
content.gsub!(@@pattern_space_1, NBSP_2)
|
5221
|
-
end
|
5222
|
-
|
5223
|
-
content
|
5224
|
-
end
|
5225
|
-
|
5226
|
-
def escape_content(content, elm)
|
5227
|
-
content = escape(content)
|
5228
|
-
|
5229
|
-
if elm.cx || !is_match(@@match_tag_2, elm.name) then
|
5230
|
-
#「¥r?¥n」->「<br>」
|
5231
|
-
content.gsub!(@@pattern_br_1, BR_2)
|
5232
|
-
end
|
5233
|
-
|
5234
|
-
content
|
5235
|
-
end
|
5236
|
-
|
5237
|
-
end
|
5238
|
-
end
|
5239
5080
|
end
|
5240
5081
|
|
5241
5082
|
module Html5
|
@@ -5280,7 +5121,7 @@ module Meteor
|
|
5280
5121
|
@doc_type = Parser::HTML5
|
5281
5122
|
case args.length
|
5282
5123
|
when ZERO
|
5283
|
-
initialize_0
|
5124
|
+
#initialize_0
|
5284
5125
|
when ONE
|
5285
5126
|
initialize_1(args[0])
|
5286
5127
|
else
|
@@ -5288,6 +5129,14 @@ module Meteor
|
|
5288
5129
|
end
|
5289
5130
|
end
|
5290
5131
|
|
5132
|
+
#
|
5133
|
+
# initializer (イニシャライザ)
|
5134
|
+
#
|
5135
|
+
#def initialize_0
|
5136
|
+
#end
|
5137
|
+
#
|
5138
|
+
#private :initialize_0
|
5139
|
+
|
5291
5140
|
#
|
5292
5141
|
# initializer (イニシャライザ)
|
5293
5142
|
# @param [Meteor::Parser] ps parser (パーサ)
|
@@ -5308,14 +5157,14 @@ module Meteor
|
|
5308
5157
|
def analyze_content_type
|
5309
5158
|
element_3(META_S, HTTP_EQUIV, CONTENT_TYPE)
|
5310
5159
|
|
5311
|
-
if !@elm_
|
5160
|
+
if !@elm_
|
5312
5161
|
element_3(META, HTTP_EQUIV, CONTENT_TYPE)
|
5313
5162
|
end
|
5314
5163
|
|
5315
|
-
if @elm_
|
5164
|
+
if @elm_
|
5316
5165
|
@root.content_type = @elm_.attr(CONTENT)
|
5317
5166
|
@root.charset = @elm_.attr(CHARSET)
|
5318
|
-
if !@root.charset
|
5167
|
+
if !@root.charset
|
5319
5168
|
@root.charset = UTF8
|
5320
5169
|
end
|
5321
5170
|
else
|
@@ -5327,17 +5176,17 @@ module Meteor
|
|
5327
5176
|
private :analyze_content_type
|
5328
5177
|
|
5329
5178
|
def edit_attrs_(elm, attr_name, attr_value)
|
5330
|
-
if is_match(SELECTED, attr_name) && is_match(OPTION, elm.
|
5179
|
+
if is_match(SELECTED, attr_name) && is_match(OPTION, elm.tag)
|
5331
5180
|
edit_attrs_5(elm, attr_name, attr_value, @@pattern_selected_m, @@pattern_selected_r)
|
5332
|
-
elsif is_match(MULTIPLE, attr_name) && is_match(SELECT, elm.
|
5181
|
+
elsif is_match(MULTIPLE, attr_name) && is_match(SELECT, elm.tag)
|
5333
5182
|
edit_attrs_5(elm, attr_name, attr_value, @@pattern_multiple_m, @@pattern_multiple_r)
|
5334
|
-
elsif is_match(DISABLED, attr_name) && is_match(DISABLE_ELEMENT, elm.
|
5183
|
+
elsif is_match(DISABLED, attr_name) && is_match(DISABLE_ELEMENT, elm.tag)
|
5335
5184
|
edit_attrs_5(elm, attr_name, attr_value, @@pattern_disabled_m, @@pattern_disabled_r)
|
5336
|
-
elsif is_match(CHECKED, attr_name) && is_match(INPUT, elm.
|
5185
|
+
elsif is_match(CHECKED, attr_name) && is_match(INPUT, elm.tag) && is_match(RADIO, get_type(elm))
|
5337
5186
|
edit_attrs_5(elm, attr_name, attr_value, @@pattern_checked_m, @@pattern_checked_r)
|
5338
|
-
elsif is_match(READONLY, attr_name) && (is_match(TEXTAREA, elm.
|
5187
|
+
elsif is_match(READONLY, attr_name) && (is_match(TEXTAREA, elm.tag) || (is_match(INPUT, elm.tag) && is_match(READONLY_TYPE, get_type(elm))))
|
5339
5188
|
edit_attrs_5(elm, attr_name, attr_value, @@pattern_readonly_m, @@pattern_readonly_r)
|
5340
|
-
elsif is_match(REQUIRED, attr_name) && is_match(REQUIRE_ELEMENT, elm.
|
5189
|
+
elsif is_match(REQUIRED, attr_name) && is_match(REQUIRE_ELEMENT, elm.tag)
|
5341
5190
|
edit_attrs_5(elm, attr_name, attr_value, @@pattern_required_m, @@pattern_required_r)
|
5342
5191
|
else
|
5343
5192
|
super(elm, attr_name, attr_value)
|
@@ -5347,17 +5196,17 @@ module Meteor
|
|
5347
5196
|
private :edit_attrs_
|
5348
5197
|
|
5349
5198
|
def get_attr_value_(elm, attr_name)
|
5350
|
-
if is_match(SELECTED, attr_name) && is_match(OPTION, elm.
|
5199
|
+
if is_match(SELECTED, attr_name) && is_match(OPTION, elm.tag)
|
5351
5200
|
get_attr_value_r(elm, @@pattern_selected_m)
|
5352
|
-
elsif is_match(MULTIPLE, attr_name) && is_match(SELECT, elm.
|
5201
|
+
elsif is_match(MULTIPLE, attr_name) && is_match(SELECT, elm.tag)
|
5353
5202
|
get_attr_value_r(elm, @@pattern_multiple_m)
|
5354
|
-
elsif is_match(DISABLED, attr_name) && is_match(DISABLE_ELEMENT, elm.
|
5203
|
+
elsif is_match(DISABLED, attr_name) && is_match(DISABLE_ELEMENT, elm.tag)
|
5355
5204
|
get_attr_value_r(elm, @@pattern_disabled_m)
|
5356
|
-
elsif is_match(CHECKED, attr_name) && is_match(INPUT, elm.
|
5205
|
+
elsif is_match(CHECKED, attr_name) && is_match(INPUT, elm.tag) && is_match(RADIO, get_type(elm))
|
5357
5206
|
get_attr_value_r(elm, @@pattern_checked_m)
|
5358
|
-
elsif is_match(READONLY, attr_name) && (is_match(TEXTAREA, elm.
|
5207
|
+
elsif is_match(READONLY, attr_name) && (is_match(TEXTAREA, elm.tag) || (is_match(INPUT, elm.tag) && is_match(READONLY_TYPE, get_type(elm))))
|
5359
5208
|
get_attr_value_r(elm, @@pattern_readonly_m)
|
5360
|
-
elsif is_match(REQUIRED, attr_name) && is_match(REQUIRE_ELEMENT, elm.
|
5209
|
+
elsif is_match(REQUIRED, attr_name) && is_match(REQUIRE_ELEMENT, elm.tag)
|
5361
5210
|
get_attr_value_r(elm, @@pattern_required_m)
|
5362
5211
|
else
|
5363
5212
|
super(elm, attr_name)
|
@@ -5408,7 +5257,7 @@ module Meteor
|
|
5408
5257
|
@doc_type = Parser::XHTML5
|
5409
5258
|
case args.length
|
5410
5259
|
when ZERO
|
5411
|
-
initialize_0
|
5260
|
+
#initialize_0
|
5412
5261
|
when ONE
|
5413
5262
|
initialize_1(args[0])
|
5414
5263
|
else
|
@@ -5416,6 +5265,14 @@ module Meteor
|
|
5416
5265
|
end
|
5417
5266
|
end
|
5418
5267
|
|
5268
|
+
#
|
5269
|
+
# initializer (イニシャライザ)
|
5270
|
+
#
|
5271
|
+
#def initialize_0
|
5272
|
+
#end
|
5273
|
+
#
|
5274
|
+
#private :initialize_0
|
5275
|
+
|
5419
5276
|
#
|
5420
5277
|
# initializer (イニシャライザ)
|
5421
5278
|
# @param [Meteor::Parser] ps parser (パーサ)
|
@@ -5436,14 +5293,14 @@ module Meteor
|
|
5436
5293
|
def analyze_content_type
|
5437
5294
|
element_3(META_S, HTTP_EQUIV, CONTENT_TYPE)
|
5438
5295
|
|
5439
|
-
if !@elm_
|
5296
|
+
if !@elm_
|
5440
5297
|
element_3(META, HTTP_EQUIV, CONTENT_TYPE)
|
5441
5298
|
end
|
5442
5299
|
|
5443
|
-
if @elm_
|
5300
|
+
if @elm_
|
5444
5301
|
@root.content_type = @elm_.attr(CONTENT)
|
5445
5302
|
@root.charset = @elm_.attr(CHARSET)
|
5446
|
-
if !@root.charset
|
5303
|
+
if !@root.charset
|
5447
5304
|
@root.charset = UTF8
|
5448
5305
|
end
|
5449
5306
|
else
|
@@ -5456,17 +5313,17 @@ module Meteor
|
|
5456
5313
|
|
5457
5314
|
def edit_attrs_(elm, attr_name, attr_value)
|
5458
5315
|
|
5459
|
-
if is_match(SELECTED, attr_name) && is_match(OPTION, elm.
|
5316
|
+
if is_match(SELECTED, attr_name) && is_match(OPTION, elm.tag)
|
5460
5317
|
edit_attrs_5(elm, attr_value, @@pattern_selected_m, @@pattern_selected_r, SELECTED_U)
|
5461
|
-
elsif is_match(MULTIPLE, attr_name) && is_match(SELECT, elm.
|
5318
|
+
elsif is_match(MULTIPLE, attr_name) && is_match(SELECT, elm.tag)
|
5462
5319
|
edit_attrs_5(elm, attr_value, @@pattern_multiple_m, @@pattern_multiple_r, MULTIPLE_U)
|
5463
|
-
elsif is_match(DISABLED, attr_name) && is_match(DISABLE_ELEMENT, elm.
|
5320
|
+
elsif is_match(DISABLED, attr_name) && is_match(DISABLE_ELEMENT, elm.tag)
|
5464
5321
|
edit_attrs_5(elm, attr_value, @@pattern_disabled_m, @@pattern_disabled_r, DISABLED_U)
|
5465
|
-
elsif is_match(CHECKED, attr_name) && is_match(INPUT, elm.
|
5322
|
+
elsif is_match(CHECKED, attr_name) && is_match(INPUT, elm.tag) && is_match(RADIO, get_type(elm))
|
5466
5323
|
edit_attrs_5(elm, attr_value, @@pattern_checked_m, @@pattern_checked_r, CHECKED_U)
|
5467
|
-
elsif is_match(READONLY, attr_name) && (is_match(TEXTAREA, elm.
|
5324
|
+
elsif is_match(READONLY, attr_name) && (is_match(TEXTAREA, elm.tag) || (is_match(INPUT, elm.tag) && is_match(READONLY_TYPE, get_type(elm))))
|
5468
5325
|
edit_attrs_5(elm, attr_value, @@pattern_readonly_m, @@pattern_readonly_r, READONLY_U)
|
5469
|
-
elsif is_match(REQUIRED, attr_name) && is_match(REQUIRE_ELEMENT, elm.
|
5326
|
+
elsif is_match(REQUIRED, attr_name) && is_match(REQUIRE_ELEMENT, elm.tag)
|
5470
5327
|
edit_attrs_5(elm, attr_value, @@pattern_required_m, @@pattern_required_r, REQUIRED_U)
|
5471
5328
|
else
|
5472
5329
|
super(elm, attr_name, attr_value)
|
@@ -5477,17 +5334,17 @@ module Meteor
|
|
5477
5334
|
private :edit_attrs_
|
5478
5335
|
|
5479
5336
|
def get_attr_value_(elm, attr_name)
|
5480
|
-
if is_match(SELECTED, attr_name) && is_match(OPTION, elm.
|
5337
|
+
if is_match(SELECTED, attr_name) && is_match(OPTION, elm.tag)
|
5481
5338
|
get_attr_value_r(elm, attr_name, @@pattern_selected_m1)
|
5482
|
-
elsif is_match(MULTIPLE, attr_name) && is_match(SELECT, elm.
|
5339
|
+
elsif is_match(MULTIPLE, attr_name) && is_match(SELECT, elm.tag)
|
5483
5340
|
get_attr_value_r(elm, attr_name, @@pattern_multiple_m1)
|
5484
|
-
elsif is_match(DISABLED, attr_name) && is_match(DISABLE_ELEMENT, elm.
|
5341
|
+
elsif is_match(DISABLED, attr_name) && is_match(DISABLE_ELEMENT, elm.tag)
|
5485
5342
|
get_attr_value_r(elm, attr_name, @@pattern_disabled_m1)
|
5486
|
-
elsif is_match(CHECKED, attr_name) && is_match(INPUT, elm.
|
5343
|
+
elsif is_match(CHECKED, attr_name) && is_match(INPUT, elm.tag) && is_match(RADIO, get_type(elm))
|
5487
5344
|
get_attr_value_r(elm, attr_name, @@pattern_checked_m1)
|
5488
|
-
elsif is_match(READONLY, attr_name) && (is_match(TEXTAREA, elm.
|
5345
|
+
elsif is_match(READONLY, attr_name) && (is_match(TEXTAREA, elm.tag) || (is_match(INPUT, elm.tag) && is_match(READONLY_TYPE, get_type(elm))))
|
5489
5346
|
get_attr_value_r(elm, attr_name, @@pattern_readonly_m1)
|
5490
|
-
elsif is_match(REQUIRED, attr_name) && is_match(REQUIRE_ELEMENT, elm.
|
5347
|
+
elsif is_match(REQUIRED, attr_name) && is_match(REQUIRE_ELEMENT, elm.tag)
|
5491
5348
|
get_attr_value_r(elm, attr_name, @@pattern_required_m1)
|
5492
5349
|
else
|
5493
5350
|
super(elm, attr_name)
|
@@ -5511,18 +5368,15 @@ module Meteor
|
|
5511
5368
|
|
5512
5369
|
@@pattern_unescape = Regexp.new(PATTERN_UNESCAPE)
|
5513
5370
|
|
5514
|
-
|
5515
|
-
|
5516
|
-
|
5517
|
-
|
5518
|
-
|
5519
|
-
|
5520
|
-
|
5521
|
-
|
5522
|
-
|
5523
|
-
@@pattern_escape = Regexp.new(PATTERN_ESCAPE)
|
5524
|
-
|
5525
|
-
end
|
5371
|
+
TABLE_FOR_ESCAPE_ = {
|
5372
|
+
'&' => '&',
|
5373
|
+
'"' => '"',
|
5374
|
+
'\'' => ''',
|
5375
|
+
'<' => '<',
|
5376
|
+
'>' => '>',
|
5377
|
+
}
|
5378
|
+
PATTERN_ESCAPE = '[&\"\'<>]'
|
5379
|
+
@@pattern_escape = Regexp.new(PATTERN_ESCAPE)
|
5526
5380
|
|
5527
5381
|
#
|
5528
5382
|
# initializer (イニシャライザ)
|
@@ -5535,7 +5389,7 @@ module Meteor
|
|
5535
5389
|
@doc_type = Parser::XML
|
5536
5390
|
case args.length
|
5537
5391
|
when ZERO
|
5538
|
-
initialize_0
|
5392
|
+
#initialize_0
|
5539
5393
|
when ONE
|
5540
5394
|
initialize_1(args[0])
|
5541
5395
|
else
|
@@ -5546,10 +5400,12 @@ module Meteor
|
|
5546
5400
|
#
|
5547
5401
|
# initializer (イニシャライザ)
|
5548
5402
|
#
|
5549
|
-
def initialize_0
|
5550
|
-
end
|
5551
|
-
|
5552
|
-
private :initialize_0
|
5403
|
+
#def initialize_0
|
5404
|
+
#end
|
5405
|
+
#
|
5406
|
+
#private :initialize_0
|
5407
|
+
#
|
5408
|
+
#private :initialize_0
|
5553
5409
|
|
5554
5410
|
#
|
5555
5411
|
# initializer (イニシャライザ)
|
@@ -5562,27 +5418,10 @@ module Meteor
|
|
5562
5418
|
|
5563
5419
|
private :initialize_1
|
5564
5420
|
|
5565
|
-
#
|
5566
|
-
# set document in parser (ドキュメントをパーサにセットする)
|
5567
|
-
# @param [String] document document (ドキュメント)
|
5568
|
-
#
|
5569
|
-
#def parse(document)
|
5570
|
-
# @root.document = document
|
5571
|
-
#end
|
5572
|
-
|
5573
|
-
#
|
5574
|
-
# read file , set in parser (ファイルを読み込み、パーサにセットする)
|
5575
|
-
# @param file_path file path (ファイルパス)
|
5576
|
-
# @param enc character encoding (エンコーディング)
|
5577
|
-
#
|
5578
|
-
#def read(file_path, enc)
|
5579
|
-
# super(file_path, enc)
|
5580
|
-
#end
|
5581
|
-
|
5582
5421
|
# get content type (コンテントタイプを取得する)
|
5583
5422
|
# @return [Streing] content type (コンテントタイプ)
|
5584
5423
|
#
|
5585
|
-
def content_type
|
5424
|
+
def content_type
|
5586
5425
|
@root.content_type
|
5587
5426
|
end
|
5588
5427
|
|
@@ -5594,7 +5433,6 @@ module Meteor
|
|
5594
5433
|
content
|
5595
5434
|
end
|
5596
5435
|
|
5597
|
-
|
5598
5436
|
private :escape
|
5599
5437
|
|
5600
5438
|
def escape_content(*args)
|
@@ -5612,18 +5450,20 @@ module Meteor
|
|
5612
5450
|
#「&」<-「&」
|
5613
5451
|
content.gsub(@@pattern_unescape) do
|
5614
5452
|
case $1
|
5615
|
-
when AND_3
|
5453
|
+
when AND_3
|
5616
5454
|
AND_1
|
5617
|
-
when QO_3
|
5455
|
+
when QO_3
|
5618
5456
|
DOUBLE_QUATATION
|
5619
|
-
when AP_3
|
5457
|
+
when AP_3
|
5620
5458
|
AP_1
|
5621
|
-
when GT_3
|
5459
|
+
when GT_3
|
5622
5460
|
GT_1
|
5623
|
-
when LT_3
|
5461
|
+
when LT_3
|
5624
5462
|
LT_1
|
5625
5463
|
end
|
5626
5464
|
end
|
5465
|
+
|
5466
|
+
content
|
5627
5467
|
end
|
5628
5468
|
|
5629
5469
|
private :unescape
|
@@ -5636,46 +5476,6 @@ module Meteor
|
|
5636
5476
|
|
5637
5477
|
end
|
5638
5478
|
|
5639
|
-
if RUBY_VERSION < RUBY_VERSION_1_9_0 then
|
5640
|
-
class ParserImpl
|
5641
|
-
@@pattern_and_1 = Regexp.new(AND_1)
|
5642
|
-
@@pattern_lt_1 = Regexp.new(LT_1)
|
5643
|
-
@@pattern_gt_1 = Regexp.new(GT_1)
|
5644
|
-
@@pattern_dq_1 = Regexp.new(DOUBLE_QUATATION)
|
5645
|
-
@@pattern_ap_1 = Regexp.new(AP_1)
|
5646
|
-
@@pattern_lt_2 = Regexp.new(LT_2)
|
5647
|
-
@@pattern_gt_2 = Regexp.new(GT_2)
|
5648
|
-
@@pattern_dq_2 = Regexp.new(QO_2)
|
5649
|
-
@@pattern_ap_2 = Regexp.new(AP_2)
|
5650
|
-
@@pattern_and_2 = Regexp.new(AND_2)
|
5651
|
-
|
5652
|
-
def escape(content)
|
5653
|
-
#特殊文字の置換
|
5654
|
-
#「&」->「&」
|
5655
|
-
if content.include?(AND_1) then
|
5656
|
-
content.gsub!(@@pattern_and_1, AND_2)
|
5657
|
-
end
|
5658
|
-
#「<」->「<」
|
5659
|
-
if content.include?(LT_1) then
|
5660
|
-
content.gsub!(@@pattern_lt_1, LT_2)
|
5661
|
-
end
|
5662
|
-
#「>」->「>」
|
5663
|
-
if content.include?(GT_1) then
|
5664
|
-
content.gsub!(@@pattern_gt_1, GT_2)
|
5665
|
-
end
|
5666
|
-
#「"」->「"」
|
5667
|
-
if content.include?(DOUBLE_QUATATION) then
|
5668
|
-
content.gsub!(@@pattern_dq_1, QO_2)
|
5669
|
-
end
|
5670
|
-
#「'」->「'」
|
5671
|
-
if content.include?(AP_1) then
|
5672
|
-
content.gsub!(@@pattern_ap_1, AP_2)
|
5673
|
-
end
|
5674
|
-
|
5675
|
-
content
|
5676
|
-
end
|
5677
|
-
end
|
5678
|
-
end
|
5679
5479
|
end
|
5680
5480
|
end
|
5681
5481
|
|