meteor 0.9.7.3 → 0.9.7.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/meteor.rb +314 -286
- metadata +5 -4
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-2013 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,12 +18,12 @@
|
|
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.7.
|
21
|
+
# @version 0.9.7.4
|
22
22
|
#
|
23
23
|
|
24
24
|
module Meteor
|
25
25
|
|
26
|
-
VERSION = "0.9.7.
|
26
|
+
VERSION = "0.9.7.4"
|
27
27
|
|
28
28
|
RUBY_VERSION_1_9_0 = '1.9.0'
|
29
29
|
|
@@ -42,6 +42,12 @@ module Meteor
|
|
42
42
|
SIX = 6
|
43
43
|
SEVEN = 7
|
44
44
|
|
45
|
+
HTML = ZERO
|
46
|
+
XHTML = ONE
|
47
|
+
HTML5 = TWO
|
48
|
+
XHTML5 = THREE
|
49
|
+
XML = FOUR
|
50
|
+
|
45
51
|
#
|
46
52
|
# Element Class (要素クラス)
|
47
53
|
#
|
@@ -49,8 +55,8 @@ module Meteor
|
|
49
55
|
|
50
56
|
#
|
51
57
|
# initializer (イニシャライザ)
|
52
|
-
# @overload initialize(
|
53
|
-
# @param [String]
|
58
|
+
# @overload initialize(tag)
|
59
|
+
# @param [String] tag tag name (タグ名)
|
54
60
|
# @overload initialize(elm)
|
55
61
|
# @param [Meteor::Element] elm element (要素)
|
56
62
|
# @overload initialize(elm,ps)
|
@@ -81,6 +87,7 @@ module Meteor
|
|
81
87
|
#@usable = false
|
82
88
|
@origin = args[0]
|
83
89
|
args[0].copy = self
|
90
|
+
when ZERO
|
84
91
|
else
|
85
92
|
raise ArgumentError
|
86
93
|
end
|
@@ -88,10 +95,10 @@ module Meteor
|
|
88
95
|
|
89
96
|
#
|
90
97
|
# initializer (イニシャライザ)
|
91
|
-
# @param [String]
|
98
|
+
# @param [String] tag tag name (タグ名)
|
92
99
|
#
|
93
|
-
def initialize_s(
|
94
|
-
@name =
|
100
|
+
def initialize_s(tag)
|
101
|
+
@name = tag
|
95
102
|
#@attributes = nil
|
96
103
|
#@mixed_content = nil
|
97
104
|
#@pattern = nil
|
@@ -173,7 +180,7 @@ module Meteor
|
|
173
180
|
end
|
174
181
|
end
|
175
182
|
|
176
|
-
attr_accessor :name #[String]
|
183
|
+
attr_accessor :name #[String] tag name (要素名)
|
177
184
|
attr_accessor :attributes #[String] attributes (属性群)
|
178
185
|
attr_accessor :mixed_content #[String] content (内容)
|
179
186
|
attr_accessor :pattern #[String] pattern (パターン)
|
@@ -241,23 +248,23 @@ module Meteor
|
|
241
248
|
# get element (要素を取得する)
|
242
249
|
# @overload element()
|
243
250
|
# get element (要素を取得する)
|
244
|
-
# @return [Meteor::Element] element (要素)
|
245
|
-
# @overload element(
|
246
|
-
# get element using
|
247
|
-
# @param [String]
|
251
|
+
# @return [Meteor::Element,NilClass] element (要素)
|
252
|
+
# @overload element(tag)
|
253
|
+
# get element using tag name (要素のタグ名で要素を取得する)
|
254
|
+
# @param [String] tag tag name (タグ名)
|
248
255
|
# @return [Meteor::Element] 要素
|
249
|
-
# @overload element(
|
250
|
-
# get element using
|
251
|
-
# @param [String]
|
256
|
+
# @overload element(tag,attrs)
|
257
|
+
# get element using tag name and attribute map (要素のタグ名と属性(属性名="属性値")あるいは属性1・属性2(属性名="属性値")で要素を取得する)
|
258
|
+
# @param [String] tag tag name (タグ名)
|
252
259
|
# @param [Hash] attrs attribute map (属性マップ)
|
253
260
|
# @return [Meteor::Element] element (要素)
|
254
261
|
# @overload element(attrs)
|
255
262
|
# get element using attribute map (属性(属性名="属性値")あるいは属性1・属性2(属性名="属性値")で要素を取得する)
|
256
263
|
# @param [Hash] attrs attribute map (属性マップ)
|
257
264
|
# @return [Meteor::Element] 要素
|
258
|
-
# @overload element(
|
259
|
-
# get element using
|
260
|
-
# @param [String]
|
265
|
+
# @overload element(tag,attr_name,attr_value)
|
266
|
+
# get element using tag name and attribute(name="value") (要素のタグ名と属性(属性名="属性値")で要素を取得する)
|
267
|
+
# @param [String] tag tag name (タグ名)
|
261
268
|
# @param [String] attr_name attribute name (属性名)
|
262
269
|
# @param [String] attr_value attribute value (属性値)
|
263
270
|
# @return [Meteor::Element] element (要素)
|
@@ -266,9 +273,9 @@ module Meteor
|
|
266
273
|
# @param [String] attr_name 属性名
|
267
274
|
# @param [String] attr_value 属性値
|
268
275
|
# @return [Meteor::Element] 要素
|
269
|
-
# @overload element(
|
270
|
-
# get element using
|
271
|
-
# @param [String]
|
276
|
+
# @overload element(tag,attr_name1,attr_value1,attr_name2,attr_value2)
|
277
|
+
# get element using tag name and attribute1,2(name="value") (要素のタグ名と属性1・属性2(属性名="属性値")で要素を取得する)
|
278
|
+
# @param [String] tag tag name (タグ名)
|
272
279
|
# @param [String] attr_name1 attribute name1 (属性名1)
|
273
280
|
# @param [String] attr_value1 attribute value1 (属性値1)
|
274
281
|
# @param [String] attr_name2 attribute name2 (属性名2)
|
@@ -299,19 +306,22 @@ module Meteor
|
|
299
306
|
alias child element
|
300
307
|
|
301
308
|
#
|
302
|
-
# get child element using selector (
|
309
|
+
# get child element using selector like css3(CSS3のようにセレクタを用いて子要素を取得する)
|
310
|
+
# CSS3 selector partial support (CSS3セレクタの部分的サポート)
|
303
311
|
# @param selector [String] selector (セレクタ)
|
304
312
|
# @return [Meteor::Element] element (要素)
|
305
313
|
#
|
306
|
-
def
|
307
|
-
@parser.
|
314
|
+
def css(selector)
|
315
|
+
@parser.css(selector)
|
308
316
|
end
|
309
317
|
|
318
|
+
alias :find :css
|
319
|
+
|
310
320
|
#
|
311
321
|
# get cx(comment extension) tag (CX(コメント拡張)タグを取得する)
|
312
|
-
# @overload cxtag(
|
313
|
-
#
|
314
|
-
# @param [String]
|
322
|
+
# @overload cxtag(tag,id)
|
323
|
+
# 要素のタグ名とID属性(id="ID属性値")でCX(コメント拡張)タグを取得する
|
324
|
+
# @param [String] tag タグ名
|
315
325
|
# @param [String] id ID属性値
|
316
326
|
# @return [Meteor::Element] 要素
|
317
327
|
# @overload cxtag(id)
|
@@ -446,17 +456,17 @@ module Meteor
|
|
446
456
|
|
447
457
|
EMPTY = ''
|
448
458
|
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
def initialize()
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
end
|
459
|
+
##
|
460
|
+
## イニシャライザ
|
461
|
+
##
|
462
|
+
#def initialize()
|
463
|
+
# #コンテントタイプ
|
464
|
+
# #@contentType = ''
|
465
|
+
# #改行コード
|
466
|
+
# #@kaigyoCode = ''
|
467
|
+
# #文字コード
|
468
|
+
# #@character_encoding=''
|
469
|
+
#end
|
460
470
|
|
461
471
|
attr_accessor :content_type #[String] content type (コンテントタイプ)
|
462
472
|
attr_accessor :kaigyo_code #[String] newline (改行コード)
|
@@ -1057,13 +1067,13 @@ module Meteor
|
|
1057
1067
|
|
1058
1068
|
#
|
1059
1069
|
# initializer (イニシャライザ)
|
1060
|
-
# @overload initialize(
|
1061
|
-
# @param [String]
|
1070
|
+
# @overload initialize(tag)
|
1071
|
+
# @param [String] tag tag name (タグ名)
|
1062
1072
|
# @overload initialize(attr_name,attr_value)
|
1063
1073
|
# @param [String] attr_name attribute name (属性名)
|
1064
1074
|
# @param [String] attr_value attribute value (属性値)
|
1065
|
-
# @overload initialize(
|
1066
|
-
# @param [String]
|
1075
|
+
# @overload initialize(tag,attr_name,attr_value)
|
1076
|
+
# @param [String] tag tag name (タグ名)
|
1067
1077
|
# @param [String] attr_name attribute name (属性名)
|
1068
1078
|
# @param [String] attr_value attribute value (属性値)
|
1069
1079
|
# @overload initialize(attr_name1,attr_value1,attr_name2,attr_value2)
|
@@ -1071,8 +1081,8 @@ module Meteor
|
|
1071
1081
|
# @param [String] attr_value1 attribute value1 (属性値1)
|
1072
1082
|
# @param [String] attr_name2 attribute name2 (属性名2)
|
1073
1083
|
# @param [String] attr_value2 attribute value2 (属性値2)
|
1074
|
-
# @overload initialize(
|
1075
|
-
# @param [String]
|
1084
|
+
# @overload initialize(tag,attr_name1,attr_value1,attr_name2,attr_value2)
|
1085
|
+
# @param [String] tag tag name (タグ名)
|
1076
1086
|
# @param [String] attr_name1 attribute name1 (属性名1)
|
1077
1087
|
# @param [String] attr_value1 attribute value1 (属性値1)
|
1078
1088
|
# @param [String] attr_name2 attribute name2 (属性名2)
|
@@ -1093,8 +1103,8 @@ module Meteor
|
|
1093
1103
|
end
|
1094
1104
|
end
|
1095
1105
|
|
1096
|
-
def initialize_1(
|
1097
|
-
self.message="element not found : #{
|
1106
|
+
def initialize_1(tag)
|
1107
|
+
self.message="element not found : #{tag}"
|
1098
1108
|
end
|
1099
1109
|
|
1100
1110
|
private :initialize_1
|
@@ -1105,8 +1115,8 @@ module Meteor
|
|
1105
1115
|
|
1106
1116
|
private :initialize_2
|
1107
1117
|
|
1108
|
-
def initialize_3(
|
1109
|
-
self.message="element not found : #{
|
1118
|
+
def initialize_3(tag, attr_name, attr_value)
|
1119
|
+
self.message="element not found : #{tag}[#{attr_name}=#{attr_value}]"
|
1110
1120
|
end
|
1111
1121
|
|
1112
1122
|
private :initialize_3
|
@@ -1117,8 +1127,8 @@ module Meteor
|
|
1117
1127
|
|
1118
1128
|
private :initialize_4
|
1119
1129
|
|
1120
|
-
def initialize_5(
|
1121
|
-
self.message="element not found : #{
|
1130
|
+
def initialize_5(tag, attr_name1, attr_value1, attr_name2, attr_value2)
|
1131
|
+
self.message="element not found : #{tag}[#{attr_name1}=#{attr_value1}][#{attr_name2}=#{attr_value2}]"
|
1122
1132
|
end
|
1123
1133
|
|
1124
1134
|
private :initialize_5
|
@@ -1229,15 +1239,19 @@ module Meteor
|
|
1229
1239
|
PATTERN_FIND_2_1 = '^#([^\\.,\\[\\]#][^,\\[\\]#]*)$'
|
1230
1240
|
PATTERN_FIND_2_2 = '^\\.([^\\.,\\[\\]#][^,\\[\\]#]*)$'
|
1231
1241
|
PATTERN_FIND_2_3 = '^\\[([^\\[\\],]+)=([^\\[\\],]+)\\]$'
|
1232
|
-
|
1242
|
+
PATTERN_FIND_3_1 = '^([^\\.,\\[\\]#][^,\\[\\]#]+)\\[([^,\\[\\]]+)=([^,\\[\\]]+)\\]$'
|
1243
|
+
PATTERN_FIND_3_2 = '^([^\\.,\\[\\]#][^,\\[\\]#]+)#([^\\.,\\[\\]#][^,\\[\\]#]*)$'
|
1244
|
+
PATTERN_FIND_3_3 = '^([^\\.,\\[\\]#][^,\\[\\]#]+)\\.([^\\.,\\[\\]#][^,\\[\\]#]*)$'
|
1233
1245
|
PATTERN_FIND_4 = '^\\[([^,]+)=([^,]+)\\]\\[([^,]+)=([^,]+)\\]$'
|
1234
|
-
PATTERN_FIND_5 = '^([^\\.,\\[\\]#][^,\\[\\]#]
|
1246
|
+
PATTERN_FIND_5 = '^([^\\.,\\[\\]#][^,\\[\\]#]+)\\[([^,]+)=([^,]+)\\]\\[([^,]+)=([^,]+)\\]$'
|
1235
1247
|
|
1236
1248
|
@@pattern_find_1 = Regexp.new(PATTERN_FIND_1)
|
1237
1249
|
@@pattern_find_2_1 = Regexp.new(PATTERN_FIND_2_1)
|
1238
1250
|
@@pattern_find_2_2 = Regexp.new(PATTERN_FIND_2_2)
|
1239
1251
|
@@pattern_find_2_3 = Regexp.new(PATTERN_FIND_2_3)
|
1240
|
-
@@
|
1252
|
+
@@pattern_find_3_1 = Regexp.new(PATTERN_FIND_3_1)
|
1253
|
+
@@pattern_find_3_2 = Regexp.new(PATTERN_FIND_3_2)
|
1254
|
+
@@pattern_find_3_3 = Regexp.new(PATTERN_FIND_3_3)
|
1241
1255
|
@@pattern_find_4 = Regexp.new(PATTERN_FIND_4)
|
1242
1256
|
@@pattern_find_5 = Regexp.new(PATTERN_FIND_5)
|
1243
1257
|
|
@@ -1360,6 +1374,9 @@ module Meteor
|
|
1360
1374
|
MODE_BF = 'r:'
|
1361
1375
|
MODE_AF = ':utf-8'
|
1362
1376
|
|
1377
|
+
CSS_ID = 'id'
|
1378
|
+
CSS_CLASS = 'class'
|
1379
|
+
|
1363
1380
|
#
|
1364
1381
|
# initializer (イニシャライザ)
|
1365
1382
|
#
|
@@ -1450,22 +1467,22 @@ module Meteor
|
|
1450
1467
|
|
1451
1468
|
#
|
1452
1469
|
# get element (要素を取得する)
|
1453
|
-
# @overload element(
|
1454
|
-
# get element using
|
1455
|
-
# @param [String]
|
1470
|
+
# @overload element(tag)
|
1471
|
+
# get element using tag name (要素のタグ名で要素を取得する)
|
1472
|
+
# @param [String] tag tag name (タグ名)
|
1456
1473
|
# @return [Meteor::Element] element(要素)
|
1457
|
-
# @overload element(
|
1458
|
-
#
|
1459
|
-
# @param [String]
|
1474
|
+
# @overload element(tag,attrs)
|
1475
|
+
# 要素のタグ名と属性(属性名="属性値")あるいは属性1・属性2(属性名="属性値")で要素を取得する
|
1476
|
+
# @param [String] tag タグ名
|
1460
1477
|
# @param [Hash] attrs 属性マップ
|
1461
1478
|
# @return [Meteor::Element] 要素
|
1462
1479
|
# @overload element(attrs)
|
1463
|
-
# get element using
|
1480
|
+
# get element using tag name and attribute map (属性(属性名="属性値")あるいは属性1・属性2(属性名="属性値")で要素を取得する)
|
1464
1481
|
# @param [Hash] attrs attribute map (属性マップ)
|
1465
1482
|
# @return [Meteor::Element] element (要素)
|
1466
|
-
# @overload element(
|
1467
|
-
# get element using
|
1468
|
-
# @param [String]
|
1483
|
+
# @overload element(tag,attr_name,attr_value)
|
1484
|
+
# get element using tag name and attribute(name="value") (要素のタグ名と属性(属性名="属性値")で要素を取得する)
|
1485
|
+
# @param [String] tag tag name (タグ名)
|
1469
1486
|
# @param [String] attr_name attribute name (属性名)
|
1470
1487
|
# @param [String] attr_value attribute value (属性値)
|
1471
1488
|
# @return [Meteor::Element] element (要素)
|
@@ -1474,9 +1491,9 @@ module Meteor
|
|
1474
1491
|
# @param [String] attr_name attribute name (属性名)
|
1475
1492
|
# @param [String] attr_value attribute value (属性値)
|
1476
1493
|
# @return [Meteor::Element] element (要素)
|
1477
|
-
# @overload element(
|
1478
|
-
# get element using
|
1479
|
-
# @param [String]
|
1494
|
+
# @overload element(tag,attr_name1,attr_value1,attr_name2,attr_value2)
|
1495
|
+
# get element using tag name and attribute1,2(name="value") (要素のタグ名と属性1・属性2(属性名="属性値")で要素を取得する)
|
1496
|
+
# @param [String] tag tag name (タグ名)
|
1480
1497
|
# @param [String] attr_name1 attribute name1 (属性名1)
|
1481
1498
|
# @param [String] attr_value1 attribute value1 (属性値1)
|
1482
1499
|
# @param [String] attr_name2 attribute name2 (属性名2)
|
@@ -1568,11 +1585,12 @@ module Meteor
|
|
1568
1585
|
end
|
1569
1586
|
|
1570
1587
|
#
|
1571
|
-
# get element using selector (
|
1588
|
+
# get element using selector like CSS3 (CSS3のようにセレクタを用いて要素を取得する)
|
1589
|
+
# CSS3 selector partial support (CSS3セレクタの部分的サポート)
|
1572
1590
|
# @param [String] selector selector (セレクタ)
|
1573
1591
|
# @return [Meteor::Element] element (要素)
|
1574
1592
|
#
|
1575
|
-
def
|
1593
|
+
def css(selector)
|
1576
1594
|
#puts selector
|
1577
1595
|
if @res = @@pattern_find_1.match(selector) then
|
1578
1596
|
element_1(@res[1])
|
@@ -1580,15 +1598,25 @@ module Meteor
|
|
1580
1598
|
@element_cache.store(@elm_.object_id, @elm_)
|
1581
1599
|
end
|
1582
1600
|
elsif @res = @@pattern_find_2_1.match(selector) then
|
1583
|
-
element_2(
|
1601
|
+
element_2(CSS_ID, @res[1])
|
1584
1602
|
if @elm_ then
|
1585
1603
|
@element_cache.store(@elm_.object_id, @elm_)
|
1586
1604
|
end
|
1587
|
-
elsif @res = @@
|
1605
|
+
elsif @res = @@pattern_find_3_1.match(selector) then
|
1588
1606
|
element_3(@res[1], @res[2], @res[3])
|
1589
1607
|
if @elm_ then
|
1590
1608
|
@element_cache.store(@elm_.object_id, @elm_)
|
1591
1609
|
end
|
1610
|
+
elsif @res = @@pattern_find_3_2.match(selector) then
|
1611
|
+
element_3(@res[1], CSS_ID, @res[2])
|
1612
|
+
if @elm_ then
|
1613
|
+
@element_cache.store(@elm_.object_id, @elm_)
|
1614
|
+
end
|
1615
|
+
elsif @res = @@pattern_find_3_3.match(selector) then
|
1616
|
+
element_3(@res[1], CSS_CLASS, @res[2])
|
1617
|
+
if @elm_ then
|
1618
|
+
@element_cache.store(@elm_.object_id, @elm_)
|
1619
|
+
end
|
1592
1620
|
elsif @res = @@pattern_find_5.match(selector) then
|
1593
1621
|
element_5(@res[1], @res[2], @res[3], @res[4], @res[5])
|
1594
1622
|
if @elm_ then
|
@@ -1605,7 +1633,7 @@ module Meteor
|
|
1605
1633
|
@element_cache.store(@elm_.object_id, @elm_)
|
1606
1634
|
end
|
1607
1635
|
elsif @res = @@pattern_find_2_2.match(selector) then
|
1608
|
-
element_2(
|
1636
|
+
element_2(CSS_CLASS, @res[1])
|
1609
1637
|
if @elm_ then
|
1610
1638
|
@element_cache.store(@elm_.object_id, @elm_)
|
1611
1639
|
end
|
@@ -1615,16 +1643,16 @@ module Meteor
|
|
1615
1643
|
end
|
1616
1644
|
|
1617
1645
|
#
|
1618
|
-
# get element using
|
1619
|
-
# @param [String]
|
1646
|
+
# get element using tag name (タグ名で検索し、要素を取得する)
|
1647
|
+
# @param [String] tag tag name (タグ名)
|
1620
1648
|
# @return [Meteor::Element] element(要素)
|
1621
1649
|
#
|
1622
|
-
def element_1(
|
1650
|
+
def element_1(tag)
|
1623
1651
|
|
1624
|
-
@
|
1652
|
+
@_tag = Regexp.quote(tag)
|
1625
1653
|
|
1626
1654
|
#要素検索用パターン
|
1627
|
-
@pattern_cc = "<#{@
|
1655
|
+
@pattern_cc = "<#{@_tag}(|\\s[^<>]*)\\/>|<#{@_tag}((?:|\\s[^<>]*))>(((?!(#{@_tag}[^<>]*>)).)*)<\\/#{@_tag}>"
|
1628
1656
|
|
1629
1657
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
1630
1658
|
#内容あり要素検索
|
@@ -1632,9 +1660,9 @@ module Meteor
|
|
1632
1660
|
|
1633
1661
|
if @res
|
1634
1662
|
if @res[1]
|
1635
|
-
element_without_1(
|
1663
|
+
element_without_1(tag)
|
1636
1664
|
else
|
1637
|
-
element_with_1(
|
1665
|
+
element_with_1(tag)
|
1638
1666
|
end
|
1639
1667
|
else
|
1640
1668
|
|
@@ -1645,9 +1673,9 @@ module Meteor
|
|
1645
1673
|
|
1646
1674
|
private :element_1
|
1647
1675
|
|
1648
|
-
def element_with_1(
|
1676
|
+
def element_with_1(tag)
|
1649
1677
|
|
1650
|
-
@elm_ = Element.new(
|
1678
|
+
@elm_ = Element.new(tag)
|
1651
1679
|
#属性
|
1652
1680
|
@elm_.attributes = @res[2]
|
1653
1681
|
#内容
|
@@ -1655,9 +1683,9 @@ module Meteor
|
|
1655
1683
|
#全体
|
1656
1684
|
@elm_.document = @res[0]
|
1657
1685
|
|
1658
|
-
#@pattern_cc = '' << TAG_OPEN << @
|
1659
|
-
#@pattern_cc << TAG_SEARCH_NC_1_2 << @
|
1660
|
-
@pattern_cc = "<#{@
|
1686
|
+
#@pattern_cc = '' << TAG_OPEN << @_tag << TAG_SEARCH_NC_1_1 << @_tag
|
1687
|
+
#@pattern_cc << TAG_SEARCH_NC_1_2 << @_tag << TAG_CLOSE
|
1688
|
+
@pattern_cc = "<#{@_tag}(?:|\\s[^<>]*)>((?!(#{@_tag}[^<>]*>)).)*<\\/#{@_tag}>"
|
1661
1689
|
|
1662
1690
|
#内容あり要素検索用パターン
|
1663
1691
|
@elm_.pattern = @pattern_cc
|
@@ -1671,16 +1699,16 @@ module Meteor
|
|
1671
1699
|
|
1672
1700
|
private :element_with_1
|
1673
1701
|
|
1674
|
-
def element_without_1(
|
1702
|
+
def element_without_1(tag)
|
1675
1703
|
#要素
|
1676
|
-
@elm_ = Element.new(
|
1704
|
+
@elm_ = Element.new(tag)
|
1677
1705
|
#属性
|
1678
1706
|
@elm_.attributes = @res[1]
|
1679
1707
|
#全体
|
1680
1708
|
@elm_.document = @res[0]
|
1681
1709
|
#空要素検索用パターン
|
1682
|
-
@pattern_cc = '' << TAG_OPEN << @
|
1683
|
-
#@pattern_cc = "<#{@
|
1710
|
+
@pattern_cc = '' << TAG_OPEN << @_tag << TAG_SEARCH_NC_1_3
|
1711
|
+
#@pattern_cc = "<#{@_tag}(?:|\\s[^<>]*)\\/>"
|
1684
1712
|
@elm_.pattern = @pattern_cc
|
1685
1713
|
|
1686
1714
|
@elm_.empty = false
|
@@ -1693,19 +1721,19 @@ module Meteor
|
|
1693
1721
|
private :element_without_1
|
1694
1722
|
|
1695
1723
|
#
|
1696
|
-
# get element using
|
1697
|
-
# @param [String]
|
1724
|
+
# get element using tag name and attribute(name="value") (要素のタグ名と属性(属性名="属性値")で検索し、要素を取得する)
|
1725
|
+
# @param [String] tag tag name (タグ名)
|
1698
1726
|
# @param [String] attrName attribute name (属性名)
|
1699
1727
|
# @param [String] attr_value attribute value (属性値)
|
1700
1728
|
# @return [Meteor::Element] element (要素)
|
1701
|
-
def element_3(
|
1729
|
+
def element_3(tag, attr_name, attr_value)
|
1702
1730
|
|
1703
|
-
@
|
1731
|
+
@_tag = Regexp.quote(tag)
|
1704
1732
|
@_attr_name = Regexp.quote(attr_name)
|
1705
1733
|
@_attr_value = Regexp.quote(attr_value)
|
1706
1734
|
|
1707
1735
|
|
1708
|
-
@pattern_cc_1 = "<#{@
|
1736
|
+
@pattern_cc_1 = "<#{@_tag}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*)\\/>|<#{@_tag}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*)>(((?!(#{@_tag}[^<>]*>)).)*)<\\/#{@_tag}>"
|
1709
1737
|
|
1710
1738
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc_1)
|
1711
1739
|
@res1 = @pattern.match(@root.document)
|
@@ -1723,29 +1751,29 @@ module Meteor
|
|
1723
1751
|
@res = @res1
|
1724
1752
|
#@pattern_cc = @pattern_cc_1
|
1725
1753
|
if @res[1]
|
1726
|
-
element_without_3(
|
1754
|
+
element_without_3(tag)
|
1727
1755
|
else
|
1728
|
-
element_with_3_1(
|
1756
|
+
element_with_3_1(tag)
|
1729
1757
|
end
|
1730
1758
|
elsif @res1.begin(0) > @res2.begin(0)
|
1731
1759
|
@res = @res2
|
1732
1760
|
#@pattern_cc = @pattern_cc_2
|
1733
|
-
element_with_3_1(
|
1761
|
+
element_with_3_1(tag)
|
1734
1762
|
end
|
1735
1763
|
elsif @res1 && !@res2 then
|
1736
1764
|
@res = @res1
|
1737
1765
|
#@pattern_cc = @pattern_cc_1
|
1738
1766
|
if @res[1]
|
1739
|
-
element_without_3(
|
1767
|
+
element_without_3(tag)
|
1740
1768
|
else
|
1741
|
-
element_with_3_1(
|
1769
|
+
element_with_3_1(tag)
|
1742
1770
|
end
|
1743
1771
|
elsif @res2 && !@res1 then
|
1744
1772
|
@res = @res2
|
1745
1773
|
#@pattern_cc = @pattern_cc_2
|
1746
|
-
element_with_3_1(
|
1774
|
+
element_with_3_1(tag)
|
1747
1775
|
else
|
1748
|
-
puts Meteor::Exception::NoSuchElementException.new(
|
1776
|
+
puts Meteor::Exception::NoSuchElementException.new(tag, attr_name, attr_value).message
|
1749
1777
|
@elm_ = nil
|
1750
1778
|
end
|
1751
1779
|
|
@@ -1754,11 +1782,11 @@ module Meteor
|
|
1754
1782
|
|
1755
1783
|
private :element_3
|
1756
1784
|
|
1757
|
-
def element_with_3_1(
|
1785
|
+
def element_with_3_1(tag)
|
1758
1786
|
case @res.captures.length
|
1759
1787
|
when FOUR
|
1760
1788
|
#要素
|
1761
|
-
@elm_ = Element.new(
|
1789
|
+
@elm_ = Element.new(tag)
|
1762
1790
|
#属性
|
1763
1791
|
@elm_.attributes = @res[1]
|
1764
1792
|
#内容
|
@@ -1766,10 +1794,10 @@ module Meteor
|
|
1766
1794
|
#全体
|
1767
1795
|
@elm_.document = @res[0]
|
1768
1796
|
#内容あり要素検索用パターン
|
1769
|
-
#@pattern_cc = ''<< TAG_OPEN << @
|
1770
|
-
#@pattern_cc << @_attr_value << TAG_SEARCH_NC_2_2 << @
|
1771
|
-
#@pattern_cc << TAG_SEARCH_NC_1_2 << @
|
1772
|
-
@pattern_cc = "<#{@
|
1797
|
+
#@pattern_cc = ''<< TAG_OPEN << @_tag << TAG_SEARCH_NC_2_1 << @_attr_name << ATTR_EQ
|
1798
|
+
#@pattern_cc << @_attr_value << TAG_SEARCH_NC_2_2 << @_tag
|
1799
|
+
#@pattern_cc << TAG_SEARCH_NC_1_2 << @_tag << TAG_CLOSE
|
1800
|
+
@pattern_cc = "<#{@_tag}\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*>((?!(#{@_tag}[^<>]*>)).)*<\\/#{@_tag}>"
|
1773
1801
|
|
1774
1802
|
@elm_.pattern = @pattern_cc
|
1775
1803
|
|
@@ -1779,7 +1807,7 @@ module Meteor
|
|
1779
1807
|
|
1780
1808
|
when FIVE
|
1781
1809
|
#要素
|
1782
|
-
@elm_ = Element.new(
|
1810
|
+
@elm_ = Element.new(tag)
|
1783
1811
|
#属性
|
1784
1812
|
@elm_.attributes = @res[2]
|
1785
1813
|
#内容
|
@@ -1787,10 +1815,10 @@ module Meteor
|
|
1787
1815
|
#全体
|
1788
1816
|
@elm_.document = @res[0]
|
1789
1817
|
#内容あり要素検索用パターン
|
1790
|
-
#@pattern_cc = ''<< TAG_OPEN << @
|
1791
|
-
#@pattern_cc << @_attr_value << TAG_SEARCH_NC_2_2 << @
|
1792
|
-
#@pattern_cc << TAG_SEARCH_NC_1_2 << @
|
1793
|
-
@pattern_cc = "<#{@
|
1818
|
+
#@pattern_cc = ''<< TAG_OPEN << @_tag << TAG_SEARCH_NC_2_1 << @_attr_name << ATTR_EQ
|
1819
|
+
#@pattern_cc << @_attr_value << TAG_SEARCH_NC_2_2 << @_tag
|
1820
|
+
#@pattern_cc << TAG_SEARCH_NC_1_2 << @_tag << TAG_CLOSE
|
1821
|
+
@pattern_cc = "<#{@_tag}\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*>((?!(#{@_tag}[^<>]*>)).)*<\\/#{@_tag}>"
|
1794
1822
|
|
1795
1823
|
@elm_.pattern = @pattern_cc
|
1796
1824
|
|
@@ -1800,7 +1828,7 @@ module Meteor
|
|
1800
1828
|
|
1801
1829
|
when THREE,SIX
|
1802
1830
|
#内容
|
1803
|
-
@elm_ = Element.new(
|
1831
|
+
@elm_ = Element.new(tag)
|
1804
1832
|
#属性
|
1805
1833
|
@elm_.attributes = @res[1].chop
|
1806
1834
|
#内容
|
@@ -1821,29 +1849,29 @@ module Meteor
|
|
1821
1849
|
|
1822
1850
|
def element_with_3_2
|
1823
1851
|
|
1824
|
-
#@pattern_cc_1 = '' << TAG_OPEN << @
|
1852
|
+
#@pattern_cc_1 = '' << TAG_OPEN << @_tag << TAG_SEARCH_2_1 << @_attr_name << ATTR_EQ
|
1825
1853
|
#@pattern_cc_1 << @_attr_value << TAG_SEARCH_2_4_2
|
1826
|
-
@pattern_cc_1 = "<#{@
|
1854
|
+
@pattern_cc_1 = "<#{@_tag}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}(?:[^<>\\/]*>|(?:(?!([^<>]*\\/>))[^<>]*>)))"
|
1827
1855
|
|
1828
|
-
@pattern_cc_1b = '' << TAG_OPEN << @
|
1829
|
-
#@pattern_cc_1b = "<#{@
|
1856
|
+
@pattern_cc_1b = '' << TAG_OPEN << @_tag << TAG_SEARCH_1_4
|
1857
|
+
#@pattern_cc_1b = "<#{@_tag}(\\s[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))"
|
1830
1858
|
|
1831
|
-
#@pattern_cc_1_1 = '' << TAG_OPEN << @
|
1859
|
+
#@pattern_cc_1_1 = '' << TAG_OPEN << @_tag << TAG_SEARCH_2_1 << @_attr_name << ATTR_EQ
|
1832
1860
|
#@pattern_cc_1_1 << @_attr_value << TAG_SEARCH_4_7
|
1833
|
-
@pattern_cc_1_1 = "<#{@
|
1861
|
+
@pattern_cc_1_1 = "<#{@_tag}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"(?:[^<>\\/]*>|(?!([^<>]*\\/>))[^<>]*>))("
|
1834
1862
|
|
1835
|
-
@pattern_cc_1_2 = '' << TAG_SEARCH_4_2 << @
|
1836
|
-
#@pattern_cc_1_2 = ".*?<#{@
|
1863
|
+
@pattern_cc_1_2 = '' << TAG_SEARCH_4_2 << @_tag << TAG_SEARCH_4_3
|
1864
|
+
#@pattern_cc_1_2 = ".*?<#{@_tag}(\\s[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))"
|
1837
1865
|
|
1838
1866
|
|
1839
|
-
@pattern_cc_2 = '' << TAG_SEARCH_4_4 << @
|
1840
|
-
#@pattern_cc_2 = '' << "<\\/#{@
|
1867
|
+
@pattern_cc_2 = '' << TAG_SEARCH_4_4 << @_tag << TAG_CLOSE
|
1868
|
+
#@pattern_cc_2 = '' << "<\\/#{@_tag}>"
|
1841
1869
|
|
1842
|
-
@pattern_cc_2_1 = '' << TAG_SEARCH_4_5 << @
|
1843
|
-
#@pattern_cc_2_1 = ".*?<\\/#{@
|
1870
|
+
@pattern_cc_2_1 = '' << TAG_SEARCH_4_5 << @_tag << TAG_CLOSE
|
1871
|
+
#@pattern_cc_2_1 = ".*?<\\/#{@_tag}>"
|
1844
1872
|
|
1845
|
-
@pattern_cc_2_2 = '' << TAG_SEARCH_4_6 << @
|
1846
|
-
#@pattern_cc_2_2 = ".*?)<\\/#{@
|
1873
|
+
@pattern_cc_2_2 = '' << TAG_SEARCH_4_6 << @_tag << TAG_CLOSE
|
1874
|
+
#@pattern_cc_2_2 = ".*?)<\\/#{@_tag}>"
|
1847
1875
|
|
1848
1876
|
#内容あり要素検索
|
1849
1877
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc_1)
|
@@ -1871,23 +1899,23 @@ module Meteor
|
|
1871
1899
|
|
1872
1900
|
private :element_with_3_2
|
1873
1901
|
|
1874
|
-
def element_without_3(
|
1875
|
-
element_without_3_1(
|
1902
|
+
def element_without_3(tag)
|
1903
|
+
element_without_3_1(tag, TAG_SEARCH_NC_2_3_2)
|
1876
1904
|
end
|
1877
1905
|
|
1878
1906
|
private :element_without_3
|
1879
1907
|
|
1880
|
-
def element_without_3_1(
|
1908
|
+
def element_without_3_1(tag, closer)
|
1881
1909
|
|
1882
1910
|
#要素
|
1883
|
-
@elm_ = Element.new(
|
1911
|
+
@elm_ = Element.new(tag)
|
1884
1912
|
#属性
|
1885
1913
|
@elm_.attributes = @res[1]
|
1886
1914
|
#全体
|
1887
1915
|
@elm_.document = @res[0]
|
1888
1916
|
#空要素検索用パターン
|
1889
|
-
@pattern_cc = '' << TAG_OPEN << @
|
1890
|
-
#@pattern_cc = "<#{@
|
1917
|
+
@pattern_cc = '' << TAG_OPEN << @_tag << TAG_SEARCH_NC_2_1 << @_attr_name << ATTR_EQ << @_attr_value << closer
|
1918
|
+
#@pattern_cc = "<#{@_tag}\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}#{closer}"
|
1891
1919
|
@elm_.pattern = @pattern_cc
|
1892
1920
|
|
1893
1921
|
@elm_.parser = self
|
@@ -1980,9 +2008,9 @@ module Meteor
|
|
1980
2008
|
#puts @res.captures.length
|
1981
2009
|
case @res.captures.length
|
1982
2010
|
when FOUR
|
1983
|
-
@
|
2011
|
+
@_tag = @res[1]
|
1984
2012
|
#要素
|
1985
|
-
@elm_ = Element.new(@
|
2013
|
+
@elm_ = Element.new(@_tag)
|
1986
2014
|
#属性
|
1987
2015
|
@elm_.attributes = @res[2]
|
1988
2016
|
#内容
|
@@ -1990,10 +2018,10 @@ module Meteor
|
|
1990
2018
|
#全体
|
1991
2019
|
@elm_.document = @res[0]
|
1992
2020
|
#内容あり要素検索用パターン
|
1993
|
-
#@pattern_cc = ''<< TAG_OPEN << @
|
1994
|
-
#@pattern_cc << @_attr_value << TAG_SEARCH_NC_2_2 << @
|
1995
|
-
#@pattern_cc << TAG_SEARCH_NC_1_2 << @
|
1996
|
-
@pattern_cc = "<#{@
|
2021
|
+
#@pattern_cc = ''<< TAG_OPEN << @_tag << TAG_SEARCH_NC_2_1 << @_attr_name << ATTR_EQ
|
2022
|
+
#@pattern_cc << @_attr_value << TAG_SEARCH_NC_2_2 << @_tag
|
2023
|
+
#@pattern_cc << TAG_SEARCH_NC_1_2 << @_tag << TAG_CLOSE
|
2024
|
+
@pattern_cc = "<#{@_tag}\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*>((?!(#{@_tag}[^<>]*>)).)*<\\/#{@_tag}>"
|
1997
2025
|
|
1998
2026
|
@elm_.pattern = @pattern_cc
|
1999
2027
|
|
@@ -2002,9 +2030,9 @@ module Meteor
|
|
2002
2030
|
@elm_.parser = self
|
2003
2031
|
|
2004
2032
|
when FIVE,SEVEN
|
2005
|
-
@
|
2033
|
+
@_tag = @res[3]
|
2006
2034
|
#要素
|
2007
|
-
@elm_ = Element.new(@
|
2035
|
+
@elm_ = Element.new(@_tag)
|
2008
2036
|
#属性
|
2009
2037
|
@elm_.attributes = @res[4]
|
2010
2038
|
#内容
|
@@ -2012,10 +2040,10 @@ module Meteor
|
|
2012
2040
|
#全体
|
2013
2041
|
@elm_.document = @res[0]
|
2014
2042
|
#内容あり要素検索用パターン
|
2015
|
-
#@pattern_cc = ''<< TAG_OPEN << @
|
2016
|
-
#@pattern_cc << @_attr_value << TAG_SEARCH_NC_2_2 << @
|
2017
|
-
#@pattern_cc << TAG_SEARCH_NC_1_2 << @
|
2018
|
-
@pattern_cc = "<#{@
|
2043
|
+
#@pattern_cc = ''<< TAG_OPEN << @_tag << TAG_SEARCH_NC_2_1 << @_attr_name << ATTR_EQ
|
2044
|
+
#@pattern_cc << @_attr_value << TAG_SEARCH_NC_2_2 << @_tag
|
2045
|
+
#@pattern_cc << TAG_SEARCH_NC_1_2 << @_tag << TAG_CLOSE
|
2046
|
+
@pattern_cc = "<#{@_tag}\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*>((?!(#{@_tag}[^<>]*>)).)*<\\/#{@_tag}>"
|
2019
2047
|
|
2020
2048
|
@elm_.pattern = @pattern_cc
|
2021
2049
|
|
@@ -2026,9 +2054,9 @@ module Meteor
|
|
2026
2054
|
when THREE,SIX
|
2027
2055
|
#puts @res[1]
|
2028
2056
|
#puts @res[3]
|
2029
|
-
#@
|
2057
|
+
#@_tag = @res[1]
|
2030
2058
|
#内容
|
2031
|
-
@elm_ = Element.new(@
|
2059
|
+
@elm_ = Element.new(@_tag)
|
2032
2060
|
#属性
|
2033
2061
|
@elm_.attributes = @res[1].chop
|
2034
2062
|
#内容
|
@@ -2049,7 +2077,7 @@ module Meteor
|
|
2049
2077
|
|
2050
2078
|
def element_with_2_2
|
2051
2079
|
|
2052
|
-
#@pattern_cc_1 = '' << TAG_OPEN << @
|
2080
|
+
#@pattern_cc_1 = '' << TAG_OPEN << @_tag << TAG_SEARCH_2_1 << @_attr_name << ATTR_EQ
|
2053
2081
|
#@pattern_cc_1 << @_attr_value << TAG_SEARCH_2_4_2
|
2054
2082
|
@pattern_cc_1 = "<([^<>\"]*)(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}(?:[^<>\\/]*>|(?:(?!([^<>]*\\/>))[^<>]*>)))"
|
2055
2083
|
|
@@ -2078,21 +2106,21 @@ module Meteor
|
|
2078
2106
|
|
2079
2107
|
def create_pattern_2(args_cnt)
|
2080
2108
|
|
2081
|
-
#puts @
|
2109
|
+
#puts @_tag
|
2082
2110
|
|
2083
|
-
@pattern_cc_1b = '' << TAG_OPEN << @
|
2111
|
+
@pattern_cc_1b = '' << TAG_OPEN << @_tag << TAG_SEARCH_1_4
|
2084
2112
|
|
2085
|
-
#@pattern_cc_1_1 = '' << TAG_OPEN << @
|
2113
|
+
#@pattern_cc_1_1 = '' << TAG_OPEN << @_tag << TAG_SEARCH_2_1 << @_attr_name << ATTR_EQ
|
2086
2114
|
#@pattern_cc_1_1 << @_attr_value << TAG_SEARCH_4_7
|
2087
|
-
@pattern_cc_1_1 = "<#{@
|
2115
|
+
@pattern_cc_1_1 = "<#{@_tag}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"(?:[^<>\\/]*>|(?!([^<>]*\\/>))[^<>]*>))("
|
2088
2116
|
|
2089
|
-
@pattern_cc_1_2 = '' << TAG_SEARCH_4_2 << @
|
2117
|
+
@pattern_cc_1_2 = '' << TAG_SEARCH_4_2 << @_tag << TAG_SEARCH_4_3
|
2090
2118
|
|
2091
|
-
@pattern_cc_2 = '' << TAG_SEARCH_4_4 << @
|
2119
|
+
@pattern_cc_2 = '' << TAG_SEARCH_4_4 << @_tag << TAG_CLOSE
|
2092
2120
|
|
2093
|
-
@pattern_cc_2_1 = '' << TAG_SEARCH_4_5 << @
|
2121
|
+
@pattern_cc_2_1 = '' << TAG_SEARCH_4_5 << @_tag << TAG_CLOSE
|
2094
2122
|
|
2095
|
-
@pattern_cc_2_2 = '' << TAG_SEARCH_4_6 << @
|
2123
|
+
@pattern_cc_2_2 = '' << TAG_SEARCH_4_6 << @_tag << TAG_CLOSE
|
2096
2124
|
|
2097
2125
|
@pattern_2 = Meteor::Core::Util::PatternCache.get(@pattern_cc_2)
|
2098
2126
|
@pattern_1b = Meteor::Core::Util::PatternCache.get(@pattern_cc_1b)
|
@@ -2114,7 +2142,7 @@ module Meteor
|
|
2114
2142
|
#全体
|
2115
2143
|
@elm_.document = @res[0]
|
2116
2144
|
#空要素検索用パターン
|
2117
|
-
@pattern_cc = '' << TAG_OPEN << @
|
2145
|
+
@pattern_cc = '' << TAG_OPEN << @_tag << TAG_SEARCH_NC_2_1 << @_attr_name << ATTR_EQ << @_attr_value << closer
|
2118
2146
|
@elm_.pattern = @pattern_cc
|
2119
2147
|
|
2120
2148
|
@elm_.parser = self
|
@@ -2126,24 +2154,24 @@ module Meteor
|
|
2126
2154
|
=end
|
2127
2155
|
|
2128
2156
|
#
|
2129
|
-
# get element using
|
2130
|
-
# @param [String]
|
2157
|
+
# get element using tag name and attribute1,2(name="value") (要素のタグ名と属性1・属性2(属性名="属性値")で検索し、要素を取得する)
|
2158
|
+
# @param [String] tag tag name (タグ名)
|
2131
2159
|
# @param [String] attr_name1 attribute name1 (属性名1)
|
2132
2160
|
# @param [String] attr_value1 attribute value1 (属性値1)
|
2133
2161
|
# @param [String] attr_name2 attribute name2 (属性名2)
|
2134
2162
|
# @param [String] attr_value2 attribute value2 (属性値2)
|
2135
2163
|
# @return [Meteor::Element] element (要素)
|
2136
2164
|
#
|
2137
|
-
def element_5(
|
2165
|
+
def element_5(tag, attr_name1, attr_value1, attr_name2, attr_value2)
|
2138
2166
|
|
2139
|
-
@
|
2167
|
+
@_tag = Regexp.quote(tag)
|
2140
2168
|
@_attr_name1 = Regexp.quote(attr_name1)
|
2141
2169
|
@_attr_name2 = Regexp.quote(attr_name2)
|
2142
2170
|
@_attr_value1 = Regexp.quote(attr_value1)
|
2143
2171
|
@_attr_value2 = Regexp.quote(attr_value2)
|
2144
2172
|
|
2145
2173
|
|
2146
|
-
@pattern_cc_1 = "<#{@
|
2174
|
+
@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}>"
|
2147
2175
|
|
2148
2176
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc_1)
|
2149
2177
|
@res1 = @pattern.match(@root.document)
|
@@ -2161,29 +2189,29 @@ module Meteor
|
|
2161
2189
|
@res = @res1
|
2162
2190
|
#@pattern_cc = @pattern_cc_1
|
2163
2191
|
if @res[1]
|
2164
|
-
element_without_5(
|
2192
|
+
element_without_5(tag)
|
2165
2193
|
else
|
2166
|
-
element_with_5_1(
|
2194
|
+
element_with_5_1(tag)
|
2167
2195
|
end
|
2168
2196
|
elsif @res1.begin(0) > @res2.begin(0)
|
2169
2197
|
@res = @res2
|
2170
2198
|
#@pattern_cc = @pattern_cc_2
|
2171
|
-
element_with_5_1(
|
2199
|
+
element_with_5_1(tag)
|
2172
2200
|
end
|
2173
2201
|
elsif @res1 && !@res2 then
|
2174
2202
|
@res = @res1
|
2175
2203
|
#@pattern_cc = @pattern_cc_1
|
2176
2204
|
if @res[1]
|
2177
|
-
element_without_5(
|
2205
|
+
element_without_5(tag)
|
2178
2206
|
else
|
2179
|
-
element_with_5_1(
|
2207
|
+
element_with_5_1(tag)
|
2180
2208
|
end
|
2181
2209
|
elsif @res2 && !@res1 then
|
2182
2210
|
@res = @res2
|
2183
2211
|
#@pattern_cc = @pattern_cc_2
|
2184
|
-
element_with_5_1(
|
2212
|
+
element_with_5_1(tag)
|
2185
2213
|
else
|
2186
|
-
puts Meteor::Exception::NoSuchElementException.new(
|
2214
|
+
puts Meteor::Exception::NoSuchElementException.new(tag, attr_name, attr_value).message
|
2187
2215
|
@elm_ = nil
|
2188
2216
|
end
|
2189
2217
|
|
@@ -2192,13 +2220,13 @@ module Meteor
|
|
2192
2220
|
|
2193
2221
|
private :element_5
|
2194
2222
|
|
2195
|
-
def element_with_5_1(
|
2223
|
+
def element_with_5_1(tag)
|
2196
2224
|
|
2197
2225
|
#puts @res.captures.length
|
2198
2226
|
case @res.captures.length
|
2199
2227
|
when FOUR
|
2200
2228
|
#要素
|
2201
|
-
@elm_ = Element.new(
|
2229
|
+
@elm_ = Element.new(tag)
|
2202
2230
|
#属性
|
2203
2231
|
@elm_.attributes = @res[1]
|
2204
2232
|
#内容
|
@@ -2206,13 +2234,13 @@ module Meteor
|
|
2206
2234
|
#全体
|
2207
2235
|
@elm_.document = @res[0]
|
2208
2236
|
#内容あり要素検索用パターン
|
2209
|
-
#@pattern_cc = '' << TAG_OPEN << @
|
2237
|
+
#@pattern_cc = '' << TAG_OPEN << @_tag << TAG_SEARCH_NC_2_1_2 << @_attr_name1 << ATTR_EQ
|
2210
2238
|
#@pattern_cc << @_attr_value1 << TAG_SEARCH_NC_2_6 << @_attr_name2 << ATTR_EQ
|
2211
2239
|
#@pattern_cc << @_attr_value2 << TAG_SEARCH_NC_2_7 << @_attr_name2 << ATTR_EQ
|
2212
2240
|
#@pattern_cc << @_attr_value2 << TAG_SEARCH_NC_2_6 << @_attr_name1 << ATTR_EQ
|
2213
|
-
#@pattern_cc << @_attr_value1 << TAG_SEARCH_NC_2_2_2 << @
|
2214
|
-
#@pattern_cc << TAG_SEARCH_NC_1_2 << @
|
2215
|
-
@pattern_cc = "<#{@
|
2241
|
+
#@pattern_cc << @_attr_value1 << TAG_SEARCH_NC_2_2_2 << @_tag
|
2242
|
+
#@pattern_cc << TAG_SEARCH_NC_1_2 << @_tag << TAG_CLOSE
|
2243
|
+
@pattern_cc = "<#{@_tag}\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")[^<>]*>((?!(#{@_tag}[^<>]*>)).)*<\\/#{@_tag}>"
|
2216
2244
|
|
2217
2245
|
@elm_.pattern = @pattern_cc
|
2218
2246
|
#
|
@@ -2221,7 +2249,7 @@ module Meteor
|
|
2221
2249
|
@elm_.parser = self
|
2222
2250
|
when FIVE
|
2223
2251
|
#要素
|
2224
|
-
@elm_ = Element.new(
|
2252
|
+
@elm_ = Element.new(tag)
|
2225
2253
|
#属性
|
2226
2254
|
@elm_.attributes = @res[2]
|
2227
2255
|
#内容
|
@@ -2229,13 +2257,13 @@ module Meteor
|
|
2229
2257
|
#全体
|
2230
2258
|
@elm_.document = @res[0]
|
2231
2259
|
#内容あり要素検索用パターン
|
2232
|
-
#@pattern_cc = '' << TAG_OPEN << @
|
2260
|
+
#@pattern_cc = '' << TAG_OPEN << @_tag << TAG_SEARCH_NC_2_1_2 << @_attr_name1 << ATTR_EQ
|
2233
2261
|
#@pattern_cc << @_attr_value1 << TAG_SEARCH_NC_2_6 << @_attr_name2 << ATTR_EQ
|
2234
2262
|
#@pattern_cc << @_attr_value2 << TAG_SEARCH_NC_2_7 << @_attr_name2 << ATTR_EQ
|
2235
2263
|
#@pattern_cc << @_attr_value2 << TAG_SEARCH_NC_2_6 << @_attr_name1 << ATTR_EQ
|
2236
|
-
#@pattern_cc << @_attr_value1 << TAG_SEARCH_NC_2_2_2 << @
|
2237
|
-
#@pattern_cc << TAG_SEARCH_NC_1_2 << @
|
2238
|
-
@pattern_cc = "<#{@
|
2264
|
+
#@pattern_cc << @_attr_value1 << TAG_SEARCH_NC_2_2_2 << @_tag
|
2265
|
+
#@pattern_cc << TAG_SEARCH_NC_1_2 << @_tag << TAG_CLOSE
|
2266
|
+
@pattern_cc = "<#{@_tag}\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")[^<>]*>((?!(#{@_tag}[^<>]*>)).)*<\\/#{@_tag}>"
|
2239
2267
|
|
2240
2268
|
@elm_.pattern = @pattern_cc
|
2241
2269
|
#
|
@@ -2245,7 +2273,7 @@ module Meteor
|
|
2245
2273
|
|
2246
2274
|
when THREE,SIX
|
2247
2275
|
#要素
|
2248
|
-
@elm_ = Element.new(
|
2276
|
+
@elm_ = Element.new(tag)
|
2249
2277
|
#属性
|
2250
2278
|
@elm_.attributes = @res[1].chop
|
2251
2279
|
#要素
|
@@ -2266,38 +2294,38 @@ module Meteor
|
|
2266
2294
|
|
2267
2295
|
def element_with_5_2
|
2268
2296
|
|
2269
|
-
#@pattern_cc_1 = '' << TAG_OPEN << @
|
2297
|
+
#@pattern_cc_1 = '' << TAG_OPEN << @_tag << TAG_SEARCH_2_1_2 << @_attr_name1 << ATTR_EQ
|
2270
2298
|
#@pattern_cc_1 << @_attr_value1 << TAG_SEARCH_2_6 << @_attr_name2 << ATTR_EQ
|
2271
2299
|
#@pattern_cc_1 << @_attr_value2 << TAG_SEARCH_2_7 << @_attr_name2 << ATTR_EQ
|
2272
2300
|
#@pattern_cc_1 << @_attr_value2 << TAG_SEARCH_2_6 << @_attr_name1 << ATTR_EQ
|
2273
2301
|
#@pattern_cc_1 << @_attr_value1 << TAG_SEARCH_2_4_2_2
|
2274
|
-
@pattern_cc_1 = "<#{@
|
2302
|
+
@pattern_cc_1 = "<#{@_tag}(\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")([^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>)))"
|
2275
2303
|
|
2276
|
-
@pattern_cc_1b = '' << TAG_OPEN << @
|
2277
|
-
#@pattern_cc_1b = "<#{@
|
2304
|
+
@pattern_cc_1b = '' << TAG_OPEN << @_tag << TAG_SEARCH_1_4
|
2305
|
+
#@pattern_cc_1b = "<#{@_tag}(\\s[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))"
|
2278
2306
|
|
2279
|
-
#@pattern_cc_1_1 = '' << TAG_OPEN << @
|
2307
|
+
#@pattern_cc_1_1 = '' << TAG_OPEN << @_tag << TAG_SEARCH_2_1_2 << @_attr_name1 << ATTR_EQ
|
2280
2308
|
#@pattern_cc_1_1 << @_attr_value1 << TAG_SEARCH_2_6 << @_attr_name2 << ATTR_EQ
|
2281
2309
|
#@pattern_cc_1_1 << @_attr_value2 << TAG_SEARCH_2_7 << @_attr_name2 << ATTR_EQ
|
2282
2310
|
#@pattern_cc_1_1 << @_attr_value2 << TAG_SEARCH_2_6 << @_attr_name1 << ATTR_EQ
|
2283
2311
|
#@pattern_cc_1_1 << @_attr_value1 << TAG_SEARCH_4_7_2
|
2284
|
-
@pattern_cc_1_1 = "<#{@
|
2312
|
+
@pattern_cc_1_1 = "<#{@_tag}(\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")(?:[^<>\\/]*>|(?!([^<>]*\\/>))[^<>]*>))("
|
2285
2313
|
|
2286
|
-
@pattern_cc_1_2 = '' << TAG_SEARCH_4_2 << @
|
2314
|
+
@pattern_cc_1_2 = '' << TAG_SEARCH_4_2 << @_tag << TAG_SEARCH_4_3
|
2287
2315
|
|
2288
|
-
@pattern_cc_2 = '' << TAG_SEARCH_4_4 << @
|
2316
|
+
@pattern_cc_2 = '' << TAG_SEARCH_4_4 << @_tag << TAG_CLOSE
|
2289
2317
|
|
2290
|
-
@pattern_cc_2_1 = '' << TAG_SEARCH_4_5 << @
|
2318
|
+
@pattern_cc_2_1 = '' << TAG_SEARCH_4_5 << @_tag << TAG_CLOSE
|
2291
2319
|
|
2292
|
-
@pattern_cc_2_2 = '' << TAG_SEARCH_4_6 << @
|
2320
|
+
@pattern_cc_2_2 = '' << TAG_SEARCH_4_6 << @_tag << TAG_CLOSE
|
2293
2321
|
|
2294
|
-
#@pattern_cc_1_2 = ".*?<#{@
|
2322
|
+
#@pattern_cc_1_2 = ".*?<#{@_tag}(\\s[^<>\\/]*>|((?!([^<>]*\\/>))[^<>]*>))"
|
2295
2323
|
#
|
2296
|
-
#@pattern_cc_2 = '' << "<\\/#{@
|
2324
|
+
#@pattern_cc_2 = '' << "<\\/#{@_tag}>"
|
2297
2325
|
#
|
2298
|
-
#@pattern_cc_2_1 = ".*?<\\/#{@
|
2326
|
+
#@pattern_cc_2_1 = ".*?<\\/#{@_tag}>"
|
2299
2327
|
#
|
2300
|
-
#@pattern_cc_2_2 = ".*?)<\\/#{@
|
2328
|
+
#@pattern_cc_2_2 = ".*?)<\\/#{@_tag}>"
|
2301
2329
|
|
2302
2330
|
#内容あり要素検索
|
2303
2331
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc_1)
|
@@ -2325,27 +2353,27 @@ module Meteor
|
|
2325
2353
|
|
2326
2354
|
private :element_with_5_2
|
2327
2355
|
|
2328
|
-
def element_without_5(
|
2329
|
-
element_without_5_1(
|
2356
|
+
def element_without_5(tag)
|
2357
|
+
element_without_5_1(tag, TAG_SEARCH_NC_2_3_2_2)
|
2330
2358
|
end
|
2331
2359
|
|
2332
2360
|
private :element_without_5
|
2333
2361
|
|
2334
|
-
def element_without_5_1(
|
2362
|
+
def element_without_5_1(tag, closer)
|
2335
2363
|
|
2336
2364
|
#要素
|
2337
|
-
@elm_ = Element.new(
|
2365
|
+
@elm_ = Element.new(tag)
|
2338
2366
|
#属性
|
2339
2367
|
@elm_.attributes = @res[1]
|
2340
2368
|
#全体
|
2341
2369
|
@elm_.document = @res[0]
|
2342
2370
|
#空要素検索用パターン
|
2343
|
-
#@pattern_cc = '' << TAG_OPEN << @
|
2371
|
+
#@pattern_cc = '' << TAG_OPEN << @_tag << TAG_SEARCH_NC_2_1_2 << @_attr_name1 << ATTR_EQ
|
2344
2372
|
#@pattern_cc << @_attr_value1 << TAG_SEARCH_NC_2_6 << @_attr_name2 << ATTR_EQ
|
2345
2373
|
#@pattern_cc << @_attr_value2 << TAG_SEARCH_NC_2_7 << @_attr_name2 << ATTR_EQ
|
2346
2374
|
#@pattern_cc << @_attr_value2 << TAG_SEARCH_NC_2_6 << @_attr_name1 << ATTR_EQ
|
2347
2375
|
#@pattern_cc << @_attr_value1 << closer
|
2348
|
-
@pattern_cc = "<#{@
|
2376
|
+
@pattern_cc = "<#{@_tag}\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}#{closer}"
|
2349
2377
|
|
2350
2378
|
@elm_.pattern = @pattern_cc
|
2351
2379
|
|
@@ -2526,7 +2554,7 @@ module Meteor
|
|
2526
2554
|
else
|
2527
2555
|
@position = @res.end(0)
|
2528
2556
|
|
2529
|
-
@
|
2557
|
+
@_tag = @res[1]
|
2530
2558
|
|
2531
2559
|
create_pattern_2(args_cnt)
|
2532
2560
|
|
@@ -2883,9 +2911,9 @@ module Meteor
|
|
2883
2911
|
|
2884
2912
|
#
|
2885
2913
|
# get cx(comment extension) tag (CX(コメント拡張)タグを取得する)
|
2886
|
-
# @overload cxtag(
|
2887
|
-
# get cx(comment extension) tag using
|
2888
|
-
# @param [String]
|
2914
|
+
# @overload cxtag(tag,id)
|
2915
|
+
# get cx(comment extension) tag using tag name and id attribute (要素のタグ名とID属性(id="ID属性値")でCX(コメント拡張)タグを取得する)
|
2916
|
+
# @param [String] tag tag name (タグ名)
|
2889
2917
|
# @param [String] id value of id attribute (ID属性値)
|
2890
2918
|
# @return [Meteor::Element] element (要素)
|
2891
2919
|
# @overload cxtag(id)
|
@@ -2911,21 +2939,21 @@ module Meteor
|
|
2911
2939
|
end
|
2912
2940
|
|
2913
2941
|
#
|
2914
|
-
# get cx(comment extension) tag using
|
2915
|
-
# @param [String]
|
2942
|
+
# get cx(comment extension) tag using tag name and id attribute (要素のタグ名とID属性(id="ID属性値")でCX(コメント拡張)タグを取得する)
|
2943
|
+
# @param [String] tag tag name (タグ名)
|
2916
2944
|
# @param [String] id value of id attribute (ID属性値)
|
2917
2945
|
# @return [Meteor::Element] element (要素)
|
2918
2946
|
#
|
2919
|
-
def cxtag_2(
|
2947
|
+
def cxtag_2(tag, id)
|
2920
2948
|
|
2921
|
-
@
|
2949
|
+
@_tag = Regexp.quote(tag)
|
2922
2950
|
@_id = Regexp.quote(id)
|
2923
2951
|
|
2924
2952
|
#CXタグ検索用パターン
|
2925
|
-
#@pattern_cc = '' << SEARCH_CX_1 << @
|
2926
|
-
#@pattern_cc << id << SEARCH_CX_3 << @
|
2927
|
-
#@pattern_cc = "<!--\\s@#{
|
2928
|
-
@pattern_cc = "<!--\\s@#{@
|
2953
|
+
#@pattern_cc = '' << SEARCH_CX_1 << @_tag << SEARCH_CX_2
|
2954
|
+
#@pattern_cc << id << SEARCH_CX_3 << @_tag << SEARCH_CX_4 << @_tag << SEARCH_CX_5
|
2955
|
+
#@pattern_cc = "<!--\\s@#{tag}\\s([^<>]*id=\"#{id}\"[^<>]*)-->(((?!(<!--\\s\\/@#{tag})).)*)<!--\\s\\/@#{tag}\\s-->"
|
2956
|
+
@pattern_cc = "<!--\\s@#{@_tag}\\s([^<>]*id=\"#{@_id}\"[^<>]*)-->(((?!(<!--\\s/@#{@_tag})).)*)<!--\\s/@#{@_tag}\\s-->"
|
2929
2957
|
|
2930
2958
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
2931
2959
|
#CXタグ検索
|
@@ -2933,7 +2961,7 @@ module Meteor
|
|
2933
2961
|
|
2934
2962
|
if @res then
|
2935
2963
|
#要素
|
2936
|
-
@elm_ = Element.new(
|
2964
|
+
@elm_ = Element.new(tag)
|
2937
2965
|
|
2938
2966
|
@elm_.cx = true
|
2939
2967
|
#属性
|
@@ -3031,27 +3059,27 @@ module Meteor
|
|
3031
3059
|
private :edit_document_1
|
3032
3060
|
|
3033
3061
|
def edit_document_2(elm, closer)
|
3034
|
-
if !elm.cx then
|
3035
|
-
|
3036
|
-
|
3037
|
-
|
3038
|
-
|
3039
|
-
|
3040
|
-
|
3041
|
-
|
3042
|
-
|
3043
|
-
|
3044
|
-
|
3045
|
-
|
3046
|
-
|
3047
|
-
|
3048
|
-
else
|
3049
|
-
|
3050
|
-
|
3051
|
-
|
3052
|
-
|
3053
|
-
|
3054
|
-
end
|
3062
|
+
#if !elm.cx then
|
3063
|
+
# @_attributes = elm.attributes
|
3064
|
+
#
|
3065
|
+
# if elm.empty then
|
3066
|
+
# #内容あり要素の場合
|
3067
|
+
# @_content = elm.mixed_content
|
3068
|
+
#
|
3069
|
+
# elm.document = '' << TAG_OPEN << elm.name << @_attributes << TAG_CLOSE << @_content << TAG_OPEN3 << elm.name << TAG_CLOSE
|
3070
|
+
# #elm.document = "<#{elm.name}#{@_attributes}>#{@_content}</#{elm.name}>"
|
3071
|
+
# else
|
3072
|
+
# #空要素の場合
|
3073
|
+
# elm.document = '' << TAG_OPEN << elm.name << @_attributes << closer
|
3074
|
+
# #elm.document = "<#{elm.name}#{@_attributes}#{closer}"
|
3075
|
+
# end
|
3076
|
+
#else
|
3077
|
+
# @_content = elm.mixed_content
|
3078
|
+
#
|
3079
|
+
# #elm.document = '' << SET_CX_1 << elm.name << SPACE << elm.attributes << SET_CX_2
|
3080
|
+
# #elm.document << @_content << SET_CX_3 << elm.name << SET_CX_4
|
3081
|
+
# elm.document = "<!-- @#{elm.name} #{elm.attributes}-->#{@_content}<!-- /@#{elm.name} -->"
|
3082
|
+
#end
|
3055
3083
|
|
3056
3084
|
#タグ置換
|
3057
3085
|
@pattern = Meteor::Core::Util::PatternCache.get(elm.pattern)
|
@@ -3745,40 +3773,40 @@ module Meteor
|
|
3745
3773
|
private :analyze_kaigyo_code
|
3746
3774
|
|
3747
3775
|
#
|
3748
|
-
# get element using
|
3749
|
-
# @param [String]
|
3776
|
+
# get element using tag name (要素のタグ名で検索し、要素を取得する)
|
3777
|
+
# @param [String] tag tag name (タグ名)
|
3750
3778
|
# @return [Meteor::Element] element (要素)
|
3751
3779
|
#
|
3752
|
-
def element_1(
|
3753
|
-
@
|
3780
|
+
def element_1(tag)
|
3781
|
+
@_tag = Regexp.quote(tag)
|
3754
3782
|
|
3755
3783
|
#空要素の場合(<->内容あり要素の場合)
|
3756
|
-
if is_match(@@match_tag,
|
3784
|
+
if is_match(@@match_tag, tag) then
|
3757
3785
|
#空要素検索用パターン
|
3758
|
-
@pattern_cc = '' << TAG_OPEN << @
|
3759
|
-
#@pattern_cc = "<#{@
|
3786
|
+
@pattern_cc = '' << TAG_OPEN << @_tag << TAG_SEARCH_1_4_2
|
3787
|
+
#@pattern_cc = "<#{@_tag}(|\\s[^<>]*)>"
|
3760
3788
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
3761
3789
|
@res = @pattern.match(@root.document)
|
3762
3790
|
if @res then
|
3763
|
-
element_without_1(
|
3791
|
+
element_without_1(tag)
|
3764
3792
|
else
|
3765
|
-
puts Meteor::Exception::NoSuchElementException.new(
|
3793
|
+
puts Meteor::Exception::NoSuchElementException.new(tag).message
|
3766
3794
|
@elm_ = nil
|
3767
3795
|
end
|
3768
3796
|
else
|
3769
3797
|
#内容あり要素検索用パターン
|
3770
|
-
#@pattern_cc = '' << TAG_OPEN << @
|
3771
|
-
#@pattern_cc << TAG_SEARCH_1_2 << @
|
3772
|
-
@pattern_cc = "<#{
|
3798
|
+
#@pattern_cc = '' << TAG_OPEN << @_tag << TAG_SEARCH_1_1 << tag
|
3799
|
+
#@pattern_cc << TAG_SEARCH_1_2 << @_tag << TAG_CLOSE
|
3800
|
+
@pattern_cc = "<#{tag}(|\\s[^<>]*)>(((?!(#{tag}[^<>]*>)).)*)<\\/#{tag}>"
|
3773
3801
|
|
3774
3802
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
3775
3803
|
#内容あり要素検索
|
3776
3804
|
@res = @pattern.match(@root.document)
|
3777
3805
|
#内容あり要素の場合
|
3778
3806
|
if @res then
|
3779
|
-
element_with_1(
|
3807
|
+
element_with_1(tag)
|
3780
3808
|
else
|
3781
|
-
puts Meteor::Exception::NoSuchElementException.new(
|
3809
|
+
puts Meteor::Exception::NoSuchElementException.new(tag).message
|
3782
3810
|
@elm_ = nil
|
3783
3811
|
end
|
3784
3812
|
end
|
@@ -3788,8 +3816,8 @@ module Meteor
|
|
3788
3816
|
|
3789
3817
|
private :element_1
|
3790
3818
|
|
3791
|
-
def element_without_1(
|
3792
|
-
@elm_ = Element.new(
|
3819
|
+
def element_without_1(tag)
|
3820
|
+
@elm_ = Element.new(tag)
|
3793
3821
|
#属性
|
3794
3822
|
@elm_.attributes = @res[1]
|
3795
3823
|
#空要素検索用パターン
|
@@ -3803,53 +3831,53 @@ module Meteor
|
|
3803
3831
|
private :element_without_1
|
3804
3832
|
|
3805
3833
|
#
|
3806
|
-
# get element using
|
3807
|
-
# @param [String]
|
3834
|
+
# get element using tag name and attribute(name="value") (要素のタグ名、属性(属性名="属性値")で検索し、要素を取得する)
|
3835
|
+
# @param [String] tag tag name (タグ名)
|
3808
3836
|
# @param [String] attr_name attribute name (属性名)
|
3809
3837
|
# @param [String] attr_value attribute value (属性値)
|
3810
3838
|
# @return [Meteor::Element] element (要素)
|
3811
3839
|
#
|
3812
|
-
def element_3(
|
3840
|
+
def element_3(tag, attr_name, attr_value)
|
3813
3841
|
|
3814
|
-
@
|
3842
|
+
@_tag = Regexp.quote(tag)
|
3815
3843
|
@_attr_name = Regexp.quote(attr_name)
|
3816
3844
|
@_attr_value = Regexp.quote(attr_value)
|
3817
3845
|
|
3818
3846
|
#空要素の場合(<->内容あり要素の場合)
|
3819
|
-
if is_match(@@match_tag,
|
3847
|
+
if is_match(@@match_tag, tag) then
|
3820
3848
|
#空要素検索パターン
|
3821
|
-
#@pattern_cc = '' << TAG_OPEN << @
|
3849
|
+
#@pattern_cc = '' << TAG_OPEN << @_tag << TAG_SEARCH_2_1 << @_attr_name << ATTR_EQ
|
3822
3850
|
#@pattern_cc << @_attr_value << TAG_SEARCH_2_4_3
|
3823
|
-
@pattern_cc = "<#{@
|
3851
|
+
@pattern_cc = "<#{@_tag}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*)>"
|
3824
3852
|
|
3825
3853
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
3826
3854
|
#空要素検索
|
3827
3855
|
@res = @pattern.match(@root.document)
|
3828
3856
|
if @res then
|
3829
|
-
element_without_3(
|
3857
|
+
element_without_3(tag)
|
3830
3858
|
else
|
3831
|
-
puts Meteor::Exception::NoSuchElementException.new(
|
3859
|
+
puts Meteor::Exception::NoSuchElementException.new(tag, attr_name, attr_value).message
|
3832
3860
|
@elm_ = nil
|
3833
3861
|
end
|
3834
3862
|
else
|
3835
3863
|
#内容あり要素検索パターン
|
3836
|
-
#@pattern_cc = '' << TAG_OPEN << @
|
3837
|
-
#@pattern_cc << @_attr_value << TAG_SEARCH_2_2 << @
|
3838
|
-
#@pattern_cc << TAG_SEARCH_1_2 << @
|
3839
|
-
@pattern_cc = "<#{@
|
3864
|
+
#@pattern_cc = '' << TAG_OPEN << @_tag << TAG_SEARCH_2_1 << @_attr_name << ATTR_EQ
|
3865
|
+
#@pattern_cc << @_attr_value << TAG_SEARCH_2_2 << @_tag
|
3866
|
+
#@pattern_cc << TAG_SEARCH_1_2 << @_tag << TAG_CLOSE
|
3867
|
+
@pattern_cc = "<#{@_tag}(\\s[^<>]*#{@_attr_name}=\"#{@_attr_value}\"[^<>]*)>(((?!(#{@_tag}[^<>]*>)).)*)<\\/#{@_tag}>"
|
3840
3868
|
|
3841
3869
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
3842
3870
|
#内容あり要素検索
|
3843
3871
|
@res = @pattern.match(@root.document)
|
3844
3872
|
|
3845
|
-
if !@res && !is_match(@@match_tag_sng,
|
3873
|
+
if !@res && !is_match(@@match_tag_sng, tag) then
|
3846
3874
|
@res = element_with_3_2
|
3847
3875
|
end
|
3848
3876
|
|
3849
3877
|
if @res then
|
3850
|
-
element_with_3_1(
|
3878
|
+
element_with_3_1(tag)
|
3851
3879
|
else
|
3852
|
-
puts Meteor::Exception::NoSuchElementException.new(
|
3880
|
+
puts Meteor::Exception::NoSuchElementException.new(tag, attr_name, attr_value).message
|
3853
3881
|
@elm_ = nil
|
3854
3882
|
end
|
3855
3883
|
end
|
@@ -3859,8 +3887,8 @@ module Meteor
|
|
3859
3887
|
|
3860
3888
|
private :element_3
|
3861
3889
|
|
3862
|
-
def element_without_3(
|
3863
|
-
element_without_3_1(
|
3890
|
+
def element_without_3(tag)
|
3891
|
+
element_without_3_1(tag, TAG_SEARCH_NC_2_4_3)
|
3864
3892
|
end
|
3865
3893
|
|
3866
3894
|
private :element_without_3
|
@@ -3895,64 +3923,64 @@ module Meteor
|
|
3895
3923
|
private :element_2
|
3896
3924
|
|
3897
3925
|
#
|
3898
|
-
# get element using
|
3899
|
-
# @param [String]
|
3926
|
+
# get element using tag name and attribute1,2(name="value") (要素のタグ名と属性1・属性2(属性名="属性値")で検索し、要素を取得する)
|
3927
|
+
# @param [String] tag tag name (タグ名)
|
3900
3928
|
# @param [String] attr_name1 attribute name1 (属性名1)
|
3901
3929
|
# @param [String] attr_value1 attribute value1 (属性値1)
|
3902
3930
|
# @param [String] attr_name2 attribute name2 (属性名2)
|
3903
3931
|
# @param [String] attr_value2 attribute value2 (属性値2)
|
3904
3932
|
# @return [Meteor::Element] element (要素)
|
3905
3933
|
#
|
3906
|
-
def element_5(
|
3934
|
+
def element_5(tag, attr_name1, attr_value1, attr_name2, attr_value2)
|
3907
3935
|
|
3908
|
-
@
|
3936
|
+
@_tag = Regexp.quote(tag)
|
3909
3937
|
@_attr_name1 = Regexp.quote(attr_name1)
|
3910
3938
|
@_attr_value1 = Regexp.quote(attr_value1)
|
3911
3939
|
@_attr_name2 = Regexp.quote(attr_name2)
|
3912
3940
|
@_attr_value2 = Regexp.quote(attr_value2)
|
3913
3941
|
|
3914
3942
|
#空要素の場合(<->内容あり要素の場合)
|
3915
|
-
if is_match(@@match_tag,
|
3943
|
+
if is_match(@@match_tag, tag) then
|
3916
3944
|
#空要素検索パターン
|
3917
|
-
#@pattern_cc = '' << TAG_OPEN << @
|
3945
|
+
#@pattern_cc = '' << TAG_OPEN << @_tag << TAG_SEARCH_2_1_2 << @_attr_name1 << ATTR_EQ
|
3918
3946
|
#@pattern_cc << @_attr_value1 << TAG_SEARCH_2_6 << @_attr_name2 << ATTR_EQ
|
3919
3947
|
#@pattern_cc << @_attr_value2 << TAG_SEARCH_2_7 << @_attr_name2 << ATTR_EQ
|
3920
3948
|
#@pattern_cc << @_attr_value2 << TAG_SEARCH_2_6 << @_attr_name1 << ATTR_EQ
|
3921
3949
|
#@pattern_cc << @_attr_value1 << TAG_SEARCH_2_4_3_2
|
3922
|
-
@pattern_cc = "<#{@
|
3950
|
+
@pattern_cc = "<#{@_tag}(\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")[^<>]*)>"
|
3923
3951
|
|
3924
3952
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
3925
3953
|
#空要素検索
|
3926
3954
|
@res = @pattern.match(@root.document)
|
3927
3955
|
|
3928
3956
|
if @res then
|
3929
|
-
element_without_5(
|
3957
|
+
element_without_5(tag)
|
3930
3958
|
else
|
3931
|
-
puts Meteor::Exception::NoSuchElementException.new(
|
3959
|
+
puts Meteor::Exception::NoSuchElementException.new(tag, attr_name1, attr_value1, attr_name2, attr_value2).message
|
3932
3960
|
@elm_ = nil
|
3933
3961
|
end
|
3934
3962
|
else
|
3935
3963
|
#内容あり要素検索パターン
|
3936
|
-
#@pattern_cc = '' << TAG_OPEN << @
|
3964
|
+
#@pattern_cc = '' << TAG_OPEN << @_tag << TAG_SEARCH_2_1_2 << @_attr_name1 << ATTR_EQ
|
3937
3965
|
#@pattern_cc << @_attr_value1 << TAG_SEARCH_2_6 << @_attr_name2 << ATTR_EQ
|
3938
3966
|
#@pattern_cc << @_attr_value2 << TAG_SEARCH_2_7 << @_attr_name2 << ATTR_EQ
|
3939
3967
|
#@pattern_cc << @_attr_value2 << TAG_SEARCH_2_6 << @_attr_name1 << ATTR_EQ
|
3940
|
-
#@pattern_cc << @_attr_value1 << TAG_SEARCH_2_2_2 << @
|
3941
|
-
#@pattern_cc << TAG_SEARCH_1_2 << @
|
3942
|
-
@pattern_cc = "<#{@
|
3968
|
+
#@pattern_cc << @_attr_value1 << TAG_SEARCH_2_2_2 << @_tag
|
3969
|
+
#@pattern_cc << TAG_SEARCH_1_2 << @_tag << TAG_CLOSE
|
3970
|
+
@pattern_cc = "<#{@_tag}(\\s[^<>]*(?:#{@_attr_name1}=\"#{@_attr_value1}\"[^<>]*#{@_attr_name2}=\"#{@_attr_value2}\"|#{@_attr_name2}=\"#{@_attr_value2}\"[^<>]*#{@_attr_name1}=\"#{@_attr_value1}\")[^<>]*)>(((?!(#{@_tag}[^<>]*>)).)*)<\\/#{@_tag}>"
|
3943
3971
|
|
3944
3972
|
@pattern = Meteor::Core::Util::PatternCache.get(@pattern_cc)
|
3945
3973
|
#内容あり要素検索
|
3946
3974
|
@res = @pattern.match(@root.document)
|
3947
3975
|
|
3948
|
-
if !@res && !is_match(@@match_tag_sng,
|
3976
|
+
if !@res && !is_match(@@match_tag_sng, tag) then
|
3949
3977
|
@res = element_with_5_2
|
3950
3978
|
end
|
3951
3979
|
|
3952
3980
|
if @res then
|
3953
|
-
element_with_5_1(
|
3981
|
+
element_with_5_1(tag)
|
3954
3982
|
else
|
3955
|
-
puts Meteor::Exception::NoSuchElementException.new(
|
3983
|
+
puts Meteor::Exception::NoSuchElementException.new(tag, attr_name1, attr_value1, attr_name2, attr_value2).message
|
3956
3984
|
@elm_ = nil
|
3957
3985
|
end
|
3958
3986
|
end
|
@@ -3962,8 +3990,8 @@ module Meteor
|
|
3962
3990
|
|
3963
3991
|
private :element_5
|
3964
3992
|
|
3965
|
-
def element_without_5(
|
3966
|
-
element_without_5_1(
|
3993
|
+
def element_without_5(tag)
|
3994
|
+
element_without_5_1(tag, TAG_SEARCH_NC_2_4_3_2)
|
3967
3995
|
end
|
3968
3996
|
|
3969
3997
|
private :element_without_5
|