khrl 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89751e1d56cf715d9ae66858a45e3b817922ad14
4
- data.tar.gz: 86cbf47d534c20944b8fc553abb5115b8755245a
3
+ metadata.gz: 2fb9bdce15853d19d0c9a6089963fa287c2993b9
4
+ data.tar.gz: 0c2beb89141ea5243ccfd14b606528754719c5db
5
5
  SHA512:
6
- metadata.gz: 5e25a733be3f10ab8ed835dd5c7b8e83708425a1f93d157db24ad84bea547a9e956b51141c60e89374173698395097fbcaa84f8e4304bdaec2c82a3aef71a67b
7
- data.tar.gz: 8fb4853aea4e2b7515246fe4f08c4fa5d8127783974452fdc71e559088cc88755ea261bd6609679e77e5ba27b26f8486b35b0a17c3e731f359a5fe7f9cb2ab02
6
+ metadata.gz: dfc544e01a065d065bc56ec2dbed88881ad3c18716f7dcfdbc801c5a77c51e3f8f9b9efe902b1e8b1d1aa27a0260884525bbb1aa0822a5187ea5e3980902eff1
7
+ data.tar.gz: 13464621ea4a1babd7eefa876c39f0758f5431b747fd05cb380174954090278d5293dddd37a766405f20b815ae33ef3af933c4ee5be23db03424c75574dc3abc
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'khrl'
3
- s.version = '0.0.5'
4
- s.date = '2015-04-22'
3
+ s.version = '0.0.6'
4
+ s.date = '2016-01-05'
5
5
  s.summary = "KHRL"
6
6
  s.description = "private ruby lib"
7
7
  s.authors = ["Koihik"]
@@ -3,3 +3,4 @@ require File.expand_path("../xml/kxml.rb",__FILE__)
3
3
 
4
4
  include KXML
5
5
 
6
+ puts Document.new(File.new("test.xml"))
@@ -1,7 +1,10 @@
1
1
  <Root>
2
2
  <NodeA
3
3
  a="1"
4
- b="2"/>
4
+ b="2"
5
+ c="a b c"
6
+ d="qwe=ddd"
7
+ />
5
8
 
6
9
  <NodeB>
7
10
  <NodeC c="qwe"/>
@@ -94,7 +94,7 @@ module KXML
94
94
  end
95
95
 
96
96
  def post_parse
97
- @__parser.end
97
+ @__parser.finish
98
98
 
99
99
  @__parser = nil
100
100
  @__tag_stack = nil
@@ -1,114 +1,121 @@
1
- module KXML
2
- class SAXParser
3
- START_TAG = 'START_TAG'
4
- END_TAG = 'END_TAG'
5
- COMMENTS = 'COMMENTS'
6
- SELF_CLOSE_TAG = 'SELF_COLSE_TAG'
7
- DOCUMENT_STATEMENT = 'DOCUMENT_STATEMENT'
8
- CONTENT = 'CONTENT'
9
-
10
- attr_accessor :handler
11
- def initialize
12
- reset()
13
- end
14
-
15
- def reset
16
- @state = :NONE
17
- @temp_str = nil
18
- @is_start_tag = true
19
- @quote_state = nil
20
- @data = ''
21
- @end = false
22
- end
23
-
24
- def <<(data)
25
- push(data)
26
- end
27
-
28
- def push(data)
29
- @data += data
30
- parse()
31
- end
32
-
33
- def end
34
- @end = true
35
- parse()
36
- end
37
-
38
- private
39
-
40
- def parse
41
- raise "Cannot parse without handler" if @handler == nil
42
- return if @data == nil || @data == ''
43
-
44
- while(true)
45
- result = @data.match(/^<([\s\S.]*?)>/)
46
- if result !=nil && @data[0] == '<'
47
- dispath_tag(result.to_s)
48
- @data = @data[result[1].size+2,@data.size]
49
- next
50
- end
51
- result = @data.match(/([\s\S.]+?)</)
52
- if result !=nil
53
- dispath_content(result[1])
54
- @data = @data[result[1].size,@data.size]
55
- next
56
- end
57
- break
58
- end
59
- dispath_content(@data) if @end && @data != nil && @data != ''
60
- end
61
-
62
- def dispath_tag(data)
63
- if data =~ /<\?xml\s+(.*?)\?>/
64
- param = parse_tag("STATEMENT #{data.match(/<\?xml\s+(.*?)\?>/)[1]}")
65
- param[:type] = DOCUMENT_STATEMENT
66
- @handler.call(param)
67
- return
68
- end
69
- if data =~ /<([\s\S.]*?)\/>/
70
- param = parse_tag(data.match(/<([\s\S.]*?)\/>/)[1])
71
- param[:type] = SELF_CLOSE_TAG
72
- @handler.call(param)
73
- return
74
- end
75
- if data =~ /<\/([\s\S.]*?)>/
76
- param = parse_tag(data.match(/<\/([\s\S.]*?)>/)[1])
77
- param[:type] = END_TAG
78
- @handler.call(param)
79
- return
80
- end
81
- if data =~ /<\!--([\s\S.]*?)-->/
82
- @handler.call({:type => COMMENTS , :name => data.match(/<\!--([\s\S.]*?)-->/)[1]})
83
- return
84
- end
85
- param = parse_tag(data.match(/<([\s\S.]*?)>/)[1])
86
- param[:type] = START_TAG
87
- @handler.call(param)
88
- end
89
-
90
- def dispath_content(data)
91
- @handler.call({:type => CONTENT , :name => data})
92
- end
93
-
94
- def parse_tag(data)
95
- arr = data.split(' ')
96
- if arr.size == 1
97
- return {:name => arr[0]}
98
- else
99
- ret = {}
100
- ret[:name] = arr[0]
101
- ret[:attributes] = {}
102
- 1.upto(arr.size-1){|index|
103
- attribute = arr[index]
104
- attribute_arr = attribute.split('=')
105
- raise "Parse Attribute Failed : #{attribute}" if attribute_arr.size!=2 || !attribute_arr[1].match(/[\'\"](.*)[\'\"]/)
106
- ret[:attributes].store(attribute_arr[0],attribute_arr[1].match(/[\'\"](.*)[\'\"]/)[1])
107
- }
108
- return ret
109
- end
110
- end
111
-
112
- end
113
-
114
- end
1
+ module KXML
2
+ class SAXParser
3
+ START_TAG = 'START_TAG'
4
+ END_TAG = 'END_TAG'
5
+ COMMENTS = 'COMMENTS'
6
+ SELF_CLOSE_TAG = 'SELF_COLSE_TAG'
7
+ DOCUMENT_STATEMENT = 'DOCUMENT_STATEMENT'
8
+ CONTENT = 'CONTENT'
9
+
10
+ attr_accessor :handler
11
+ def initialize
12
+ reset()
13
+ end
14
+
15
+ def reset
16
+ @state = :NONE
17
+ @data = ''
18
+ @finish = false
19
+ end
20
+
21
+ def <<(data)
22
+ push(data)
23
+ end
24
+
25
+ def push(data)
26
+ @data += data
27
+ parse()
28
+ end
29
+
30
+ def finish
31
+ @finish = true
32
+ parse()
33
+ end
34
+
35
+ private
36
+
37
+ def parse
38
+ raise "Cannot parse without handler" if @handler == nil
39
+ return if @data == nil || @data == ''
40
+
41
+ while(true)
42
+ result = @data.match(/^<([\s\S.]*?)>/)
43
+ if result !=nil && @data[0] == '<'
44
+ dispath_tag(result.to_s)
45
+ @data = @data[result[1].size+2,@data.size]
46
+ next
47
+ end
48
+ result = @data.match(/([\s\S.]+?)</)
49
+ if result !=nil
50
+ dispath_content(result[1])
51
+ @data = @data[result[1].size,@data.size]
52
+ next
53
+ end
54
+ break
55
+ end
56
+ dispath_content(@data) if @finish && @data != nil && @data != ''
57
+ end
58
+
59
+ def dispath_tag(data)
60
+ if data =~ /<\?xml\s+(.*?)\?>/
61
+ param = parse_tag("STATEMENT #{data.match(/<\?xml\s+(.*?)\?>/)[1]}")
62
+ param[:type] = DOCUMENT_STATEMENT
63
+ @handler.call(param)
64
+ return
65
+ end
66
+ if data =~ /<([\s\S.]*?)\/>/
67
+ param = parse_tag(data.match(/<([\s\S.]*?)\/>/)[1])
68
+ param[:type] = SELF_CLOSE_TAG
69
+ @handler.call(param)
70
+ return
71
+ end
72
+ if data =~ /<\/([\s\S.]*?)>/
73
+ param = parse_tag(data.match(/<\/([\s\S.]*?)>/)[1])
74
+ param[:type] = END_TAG
75
+ @handler.call(param)
76
+ return
77
+ end
78
+ if data =~ /<\!--([\s\S.]*?)-->/
79
+ @handler.call({:type => COMMENTS , :name => data.match(/<\!--([\s\S.]*?)-->/)[1]})
80
+ return
81
+ end
82
+ param = parse_tag(data.match(/<([\s\S.]*?)>/)[1])
83
+ param[:type] = START_TAG
84
+ @handler.call(param)
85
+ end
86
+
87
+ def dispath_content(data)
88
+ @handler.call({:type => CONTENT , :name => data})
89
+ end
90
+
91
+ def parse_tag(data)
92
+ data.strip!
93
+ i = data.index(' ')
94
+ if i == nil then
95
+ return {:name => data}
96
+ else
97
+ ret = {}
98
+ ret[:name] = data[0,i]
99
+ ret[:attributes] = {}
100
+
101
+ data.scan(/[a-zA-Z0-9\_\-]+=\"[\w\W]*?\"/){|s|
102
+ k = /[a-zA-Z0-9\_\-]+(?=(\b*=))/.match(s).to_s
103
+ di = s.index('"')
104
+ si = s.index("'")
105
+ if di == nil then
106
+ i = si
107
+ elsif si == nil then
108
+ i = di
109
+ else
110
+ i = si < di ? si : di
111
+ end
112
+ v = s[i+1,s.size-i-2]
113
+ ret[:attributes][k] = v
114
+ }
115
+ return ret
116
+ end
117
+ end
118
+
119
+ end
120
+
121
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: khrl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koihik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-22 00:00:00.000000000 Z
11
+ date: 2016-01-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: private ruby lib
14
14
  email: koihik@hotmail.com
@@ -17,9 +17,9 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - khrl.gemspec
20
- - lib/Test.rb
21
20
  - lib/file/kfile.rb
22
21
  - lib/khrl.rb
22
+ - lib/Test.rb
23
23
  - lib/test.xml
24
24
  - lib/xml/kxml.rb
25
25
  - lib/xml/xml_parser.rb
@@ -43,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
43
43
  version: '0'
44
44
  requirements: []
45
45
  rubyforge_project:
46
- rubygems_version: 2.4.5
46
+ rubygems_version: 2.0.14
47
47
  signing_key:
48
48
  specification_version: 4
49
49
  summary: KHRL