rexleparser 0.2.2 → 0.2.3
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.
- data/lib/rexleparser.rb +49 -36
- metadata +2 -2
data/lib/rexleparser.rb
CHANGED
@@ -5,8 +5,7 @@
|
|
5
5
|
|
6
6
|
class RexleParser
|
7
7
|
|
8
|
-
def initialize(s)
|
9
|
-
super()
|
8
|
+
def initialize(s)
|
10
9
|
@a = scan_element(s.sub(/<\?[^>]+>/,'').split(//))
|
11
10
|
end
|
12
11
|
|
@@ -23,55 +22,69 @@ class RexleParser
|
|
23
22
|
if a.length > 1 then
|
24
23
|
a.shift
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
name << a.shift while a[0] != ' ' and a[0] != '>' and a[0] != '/'
|
25
|
+
# CDATA ?
|
26
|
+
if a[0..1].join == '![' then
|
29
27
|
|
30
|
-
|
28
|
+
name = '!['
|
29
|
+
8.times{ a.shift }
|
30
|
+
value = ''
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
value << a.shift until a[0..2].join == ']]>' or a.length <= 1
|
33
|
+
a.slice!(0,3)
|
34
|
+
element = [name, value, {}]
|
35
|
+
else
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
a.shift until a[0] == '<' or a.length < 1
|
40
|
-
raw_values.strip!
|
37
|
+
name = ''
|
38
|
+
name << a.shift
|
39
|
+
name << a.shift while a[0] != ' ' and a[0] != '>' and a[0] != '/'
|
41
40
|
|
42
|
-
|
43
|
-
element = [name, '', attributes]
|
44
|
-
else
|
41
|
+
if name then
|
45
42
|
|
46
|
-
|
47
|
-
|
43
|
+
# find the closing tag
|
44
|
+
i = a.index('>')
|
45
|
+
raw_values = ''
|
48
46
|
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
# is it a self closing tag?
|
48
|
+
if a[i-1] == '/' then
|
49
|
+
raw_values << a.shift until a[0] == '/'
|
50
|
+
a.shift until a[0] == '<' or a.length < 1
|
51
|
+
raw_values.strip!
|
52
52
|
|
53
|
-
|
53
|
+
attributes = get_attributes(raw_values) if raw_values.length > 0
|
54
|
+
element = [name, '', attributes]
|
55
|
+
else
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
+
raw_values << a.shift until a[0] == '<'
|
58
|
+
value, attributes = get_value_and_attributes(raw_values) if raw_values.length > 0
|
57
59
|
|
58
|
-
|
60
|
+
element = [name, value, attributes]
|
61
|
+
|
62
|
+
tag = a[0, name.length + 3].join
|
59
63
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
if a.length > 0 then
|
65
|
+
|
66
|
+
children = true
|
67
|
+
children = false if tag == "</%s>" % name
|
68
|
+
|
69
|
+
if children == true then
|
70
|
+
|
71
|
+
(r = scan_element(a); element << r if r) until (a[0, name.length + 3].join == "</%s>" % [name]) or a.length < 2
|
72
|
+
a.slice!(0, name.length + 3) if a[0, name.length + 3].join == "</%s>" % name
|
73
|
+
a.shift until a[0] == '<' or a.length <= 1
|
74
|
+
else
|
75
|
+
#check for its end tag
|
76
|
+
a.slice!(0, name.length + 3) if a[0, name.length + 3].join == "</%s>" % name
|
77
|
+
a.shift until a[0] == '<' or a.length <= 1
|
78
|
+
end
|
67
79
|
end
|
80
|
+
|
68
81
|
end
|
69
|
-
|
70
|
-
end
|
71
82
|
|
72
|
-
|
83
|
+
return element
|
73
84
|
|
85
|
+
end
|
74
86
|
end
|
87
|
+
|
75
88
|
end
|
76
89
|
end
|
77
90
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rexleparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors: []
|
7
7
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2011-01-11 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|