jjdecoder 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/jjdecoder.gemspec +25 -0
- data/lib/jjdecoder.rb +363 -0
- data/lib/jjdecoder/version.rb +3 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 830693f92b4aa1022cb022ad665a3968e94a57e6
|
4
|
+
data.tar.gz: 5ae23ec154222e116ac058ad2390db268b4acecf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 13b086ec04867d557061e0c58a584c7c207d06792fc9ee8bc2142b071410ab868fcf09e9008f02d2f5f71d0d844c40d23a89eec4e9d9960e053dec05d50793d3
|
7
|
+
data.tar.gz: 331295505a7e0042fbe134b1e0076519f9c7b5bab5bb3d909278803414bfedf8a1b7d261844a56a13755baa93fb188ccebaed52845da7363884b9ea74ffa85d1
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at anton.linux@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Anton Maminov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# JJDecoder
|
2
|
+
|
3
|
+
Ruby version of the jjdecode function for JJEncoded string.
|
4
|
+
|
5
|
+
[JJEncode](http://utf-8.jp/public/jjencode.html) is originally made by @hasegawayosuke.
|
6
|
+
|
7
|
+
Is a Ruby port of the https://github.com/jacobsoo/Decoder-JJEncode library.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'jjdecoder'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
```
|
20
|
+
$ bundle
|
21
|
+
```
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
```
|
26
|
+
$ gem install jjdecoder
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
encoded_str = '-encode-string-'
|
33
|
+
jj = JJDecoder.new(encoded_str)
|
34
|
+
decoded_str = jj.decode
|
35
|
+
```
|
36
|
+
|
37
|
+
## Development
|
38
|
+
|
39
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
40
|
+
|
41
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mamantoha/jjdecoder. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
46
|
+
|
47
|
+
|
48
|
+
## License and Author
|
49
|
+
|
50
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
51
|
+
|
52
|
+
Copyright (c) 2016 by Anton Maminov
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "jjdecoder"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/jjdecoder.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jjdecoder/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jjdecoder"
|
8
|
+
spec.version = JJDecoder::VERSION
|
9
|
+
spec.authors = ["Anton Maminov"]
|
10
|
+
spec.email = ["anton.linux@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby decoder for jjencode.}
|
13
|
+
spec.description = %q{Ruby version of the jjdecode function for JJEncoded string.}
|
14
|
+
spec.homepage = "https://github.com/mamantoha/jjdecoder"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
25
|
+
end
|
data/lib/jjdecoder.rb
ADDED
@@ -0,0 +1,363 @@
|
|
1
|
+
require "jjdecoder/version"
|
2
|
+
|
3
|
+
class JJDecoder
|
4
|
+
def initialize(jj_encoded_data)
|
5
|
+
@encoded_str = jj_encoded_data
|
6
|
+
end
|
7
|
+
|
8
|
+
def decode
|
9
|
+
clean
|
10
|
+
startpos, endpos, gv = check_palindrome
|
11
|
+
|
12
|
+
if startpos == endpos
|
13
|
+
raise 'No data!'
|
14
|
+
end
|
15
|
+
|
16
|
+
data = @encoded_str[startpos...endpos]
|
17
|
+
|
18
|
+
# ex decode string
|
19
|
+
b = ['___+', '__$+', '_$_+', '_$$+', '$__+', '$_$+', '$$_+', '$$$+', '$___+', '$__$+', '$_$_+', '$_$$+', '$$__+', '$$_$+', '$$$_+', '$$$$+']
|
20
|
+
|
21
|
+
# lotu
|
22
|
+
str_l = '(![]+"")[' + gv + '._$_]+'
|
23
|
+
str_o = gv + '._$+'
|
24
|
+
str_t = gv + '.__+'
|
25
|
+
str_u = gv + '._+'
|
26
|
+
|
27
|
+
# 0123456789abcdef
|
28
|
+
str_hex = gv + '.'
|
29
|
+
|
30
|
+
# s
|
31
|
+
str_s = '"'
|
32
|
+
gvsig = gv + '.'
|
33
|
+
|
34
|
+
str_quote = '\\\\\\"'
|
35
|
+
str_slash = '\\\\\\\\'
|
36
|
+
|
37
|
+
str_lower = '\\\\"+'
|
38
|
+
str_upper = '\\\\"+' + gv + '._+'
|
39
|
+
|
40
|
+
str_end = '"+' # end of s loop
|
41
|
+
|
42
|
+
out = ''
|
43
|
+
while data != ''
|
44
|
+
|
45
|
+
# l o t u
|
46
|
+
if data.index(str_l) == 0
|
47
|
+
data = data[str_l.size..-1]
|
48
|
+
out += 'l'
|
49
|
+
next
|
50
|
+
elsif data.index(str_o) == 0
|
51
|
+
data = data[str_o.size..-1]
|
52
|
+
out += 'o'
|
53
|
+
next
|
54
|
+
elsif data.index(str_t) == 0
|
55
|
+
data = data[str_t.size..-1]
|
56
|
+
out += 't'
|
57
|
+
next
|
58
|
+
elsif data.index(str_u) == 0
|
59
|
+
data = data[str_u.size..-1]
|
60
|
+
out += 'u'
|
61
|
+
next
|
62
|
+
end
|
63
|
+
|
64
|
+
# 0123456789abcdef
|
65
|
+
if data.index(str_hex) == 0
|
66
|
+
data = data[str_hex.size..-1]
|
67
|
+
|
68
|
+
# check every element of hex decode string for a match
|
69
|
+
b.size.times do |i|
|
70
|
+
if data.index(b[i]) == 0
|
71
|
+
data = data[b[i].size..-1]
|
72
|
+
out += i.to_s(16)
|
73
|
+
break
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
next
|
78
|
+
end
|
79
|
+
|
80
|
+
# start of s block
|
81
|
+
if data.index(str_s) == 0
|
82
|
+
data = data[str_s.size..-1]
|
83
|
+
|
84
|
+
# check if "R
|
85
|
+
if data.index(str_upper) == 0 # r4 n >= 128
|
86
|
+
data = data[str_upper.size..-1] # skip sig
|
87
|
+
|
88
|
+
ch_str = ''
|
89
|
+
2.times do |i| # shouldn't be more than 2 hex chars
|
90
|
+
# gv + "."+b[ c ]
|
91
|
+
if data.index(gvsig) == 0
|
92
|
+
data = data[gvsig.size..-1] # skip gvsig
|
93
|
+
|
94
|
+
b.size.times do |k| # for every entry in b
|
95
|
+
if data.index(b[k]) == 0
|
96
|
+
data = data[b[k].size..-1]
|
97
|
+
ch_str = k.to_s(16)
|
98
|
+
break
|
99
|
+
end
|
100
|
+
end
|
101
|
+
else
|
102
|
+
break # done
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
out += ch_str.to_i(16).chr
|
107
|
+
next
|
108
|
+
elsif data.index(str_lower) == 0 # r3 check if "R // n < 128
|
109
|
+
data = data[str_lower.size..-1] # skip sig
|
110
|
+
|
111
|
+
ch_str = ''
|
112
|
+
ch_lotux = ''
|
113
|
+
temp = ''
|
114
|
+
b_check_r1 = 0
|
115
|
+
3.times do |j| # shouldn't be more than 3 octal chars
|
116
|
+
if j > 1 # lotu check
|
117
|
+
if data.index(str_l) == 0
|
118
|
+
data = data[str_l.size..-1]
|
119
|
+
ch_lotux = 'l'
|
120
|
+
break
|
121
|
+
elsif data.index(str_o) == 0
|
122
|
+
data = data[str_o.size..-1]
|
123
|
+
ch_lotux = 'o'
|
124
|
+
break
|
125
|
+
elsif data.index(str_t) == 0
|
126
|
+
data = data[str_t.size..-1]
|
127
|
+
ch_lotux = 't'
|
128
|
+
break
|
129
|
+
elsif data.index(str_u) == 0
|
130
|
+
data = data[str_u.size..-1]
|
131
|
+
ch_lotux = 'u'
|
132
|
+
break
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# gv + "."+b[ c ]
|
137
|
+
if data.index(gvsig) == 0
|
138
|
+
temp = data[gvsig.size..-1]
|
139
|
+
8.times do |k| # for every entry in b octal
|
140
|
+
if temp.index(b[k]) == 0
|
141
|
+
if (ch_str + k.to_s).to_i(8) > 128
|
142
|
+
b_check_r1 = 1
|
143
|
+
break
|
144
|
+
end
|
145
|
+
|
146
|
+
ch_str += k.to_s
|
147
|
+
data = data[gvsig.size..-1] # skip gvsig
|
148
|
+
data = data[b[k].size..-1]
|
149
|
+
break
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
if b_check_r1 == 1
|
154
|
+
if data.index(str_hex) == 0 # 0123456789abcdef
|
155
|
+
data = data[str_hex.size..-1]
|
156
|
+
|
157
|
+
# check every element of hex decode string for a match
|
158
|
+
b.size.times do |i|
|
159
|
+
if data.index(b[i]) == 0
|
160
|
+
data = data[b[i].size..-1]
|
161
|
+
ch_lotux = i.to_s(16)
|
162
|
+
break
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
break
|
167
|
+
end
|
168
|
+
end
|
169
|
+
else
|
170
|
+
break # done
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
out += ch_str.to_i(8).chr + ch_lotux
|
175
|
+
next # step out of the while loop
|
176
|
+
else # "S ----> "SR or "S+
|
177
|
+
# if there is, loop s until R 0r +
|
178
|
+
# if there is no matching s block, throw error
|
179
|
+
|
180
|
+
match = 0
|
181
|
+
n = nil
|
182
|
+
|
183
|
+
# searching for matching pure s block
|
184
|
+
while true
|
185
|
+
n = data[0].ord
|
186
|
+
if data.index(str_quote) == 0
|
187
|
+
data = data[str_quote.size..-1]
|
188
|
+
out += '"'
|
189
|
+
match += 1
|
190
|
+
next
|
191
|
+
elsif data.index(str_slash) == 0
|
192
|
+
data = data[str_slash.size..-1]
|
193
|
+
out += '\\'
|
194
|
+
match += 1
|
195
|
+
next
|
196
|
+
elsif data.index(str_end) == 0 # reached end off S block ? +
|
197
|
+
if match == 0
|
198
|
+
raise '+ no match S block: ' + data
|
199
|
+
end
|
200
|
+
data = data[str_end.size..-1]
|
201
|
+
break # step out of the while loop
|
202
|
+
elsif data.index(str_upper) == 0 # r4 reached end off S block ? - check if "R n >= 128
|
203
|
+
if match == 0
|
204
|
+
raise 'no match S block n>128: ' + data
|
205
|
+
end
|
206
|
+
|
207
|
+
data = data[str_upper.size..-1] # skip sig
|
208
|
+
|
209
|
+
ch_str = ''
|
210
|
+
ch_lotux = ''
|
211
|
+
|
212
|
+
10.times do |j| # shouldn't be more than 10 hex chars
|
213
|
+
if j > 1 # lotu check
|
214
|
+
if data.index(str_l) == 0
|
215
|
+
data = data[str_l.size..-1]
|
216
|
+
ch_lotux = 'l'
|
217
|
+
break
|
218
|
+
elsif data.index(str_o) == 0
|
219
|
+
data = data[str_o.size..-1]
|
220
|
+
ch_lotux = 'o'
|
221
|
+
break
|
222
|
+
elsif data.index(str_t) == 0
|
223
|
+
data = data[str_t.size..-1]
|
224
|
+
ch_lotux = 't'
|
225
|
+
break
|
226
|
+
elsif data.index(str_u) == 0
|
227
|
+
data = data[str_u.size..-1]
|
228
|
+
ch_lotux = 'u'
|
229
|
+
break
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
# gv + "."+b[ c ]
|
234
|
+
if data.index(gvsig) == 0
|
235
|
+
data = data[gvsig.size..-1] # skip gvsig
|
236
|
+
b.size.times do |k| # for every entry in b
|
237
|
+
if data.index(b[k]) == 0
|
238
|
+
data = data[b[k].size..-1]
|
239
|
+
ch_str += k.to_s(16)
|
240
|
+
break
|
241
|
+
end
|
242
|
+
end
|
243
|
+
else
|
244
|
+
break # done
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
out += ch_str.to_i(16).chr
|
249
|
+
break # step out of the while loop
|
250
|
+
elsif data.index(str_lower) == 0 # r3 check if "R // n < 128
|
251
|
+
if match == 0
|
252
|
+
raise 'no match S block n<128: ' + data
|
253
|
+
end
|
254
|
+
|
255
|
+
data = data[str_lower.size..-1] # skip sig
|
256
|
+
|
257
|
+
ch_str = ''
|
258
|
+
ch_lotux = ''
|
259
|
+
temp = ''
|
260
|
+
b_check_r1 = 0
|
261
|
+
|
262
|
+
3.times do |j| # shouldn't be more than 3 octal chars
|
263
|
+
if j > 1 # lotu check
|
264
|
+
if data.index(str_l) == 0
|
265
|
+
data = data[str_l.size..-1]
|
266
|
+
ch_lotux = 'l'
|
267
|
+
break
|
268
|
+
elsif data.index(str_o) == 0
|
269
|
+
data = data[str_o.size..-1]
|
270
|
+
ch_lotux = 'o'
|
271
|
+
break
|
272
|
+
elsif data.index(str_t) == 0
|
273
|
+
data = data[str_t.size..-1]
|
274
|
+
ch_lotux = 't'
|
275
|
+
break
|
276
|
+
elsif data.index(str_u) == 0
|
277
|
+
data = data[str_u.size..-1]
|
278
|
+
ch_lotux = 'u'
|
279
|
+
break
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
# gv + "."+b[ c ]
|
284
|
+
if data.index(gvsig) == 0
|
285
|
+
temp = data[gvsig.size..-1]
|
286
|
+
8.times do |k| # for every entry in b octal
|
287
|
+
if temp.index(b[k]) == 0
|
288
|
+
if (ch_str + k.to_s).to_i(8) > 128
|
289
|
+
b_check_r1 = 1
|
290
|
+
break
|
291
|
+
end
|
292
|
+
|
293
|
+
ch_str += k.to_s
|
294
|
+
data = data[gvsig.size..-1] # skip gvsig
|
295
|
+
data = data[b[k].size..-1]
|
296
|
+
break
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
if b_check_r1 == 1
|
301
|
+
if data.index(str_hex) == 0 # 0123456789abcdef
|
302
|
+
data = data[str_hex.size..-1]
|
303
|
+
# check every element of hex decode string for a match
|
304
|
+
b.size.times do |i|
|
305
|
+
if data.index(b[i]) == 0
|
306
|
+
data = data[b[i].size..-1]
|
307
|
+
ch_lotux = i.to_s(16)
|
308
|
+
break
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
313
|
+
else
|
314
|
+
break # done
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
out += ch_str.to_i(8).chr + ch_lotux
|
319
|
+
break # step out of the while loop
|
320
|
+
elsif (0x21 <= n and n <= 0x2f) or (0x3A <= n and n <= 0x40) or ( 0x5b <= n and n <= 0x60 ) or ( 0x7b <= n and n <= 0x7f )
|
321
|
+
out += data[0]
|
322
|
+
data = data[1..-1]
|
323
|
+
match += 1
|
324
|
+
end
|
325
|
+
end
|
326
|
+
next
|
327
|
+
end
|
328
|
+
end
|
329
|
+
print 'No match : ' + data
|
330
|
+
break
|
331
|
+
end
|
332
|
+
|
333
|
+
return out
|
334
|
+
end
|
335
|
+
|
336
|
+
private
|
337
|
+
|
338
|
+
def clean
|
339
|
+
@encoded_str.sub!('^\s+|\s+$', '')
|
340
|
+
end
|
341
|
+
|
342
|
+
def check_palindrome
|
343
|
+
index = @encoded_str.index('"\'\\"+\'+",')
|
344
|
+
|
345
|
+
if index == 0 # palindrome check
|
346
|
+
# locate jjcode
|
347
|
+
startpos = @encoded_str.index('$$+"\\""+') + 8
|
348
|
+
endpos = @encoded_str.index('"\\"")())()')
|
349
|
+
|
350
|
+
# global variable name used by jjencode
|
351
|
+
gv = @encoded_str[@encoded_str.index('"\'\\"+\'+",')+9...@encoded_str.index('=~[]')]
|
352
|
+
else
|
353
|
+
# global variable name used by jjencode
|
354
|
+
gv = @encoded_str[0...@encoded_str.index('=')]
|
355
|
+
|
356
|
+
# locate jjcode
|
357
|
+
startpos = @encoded_str.index('"\\""+') + 5
|
358
|
+
endpos = @encoded_str.index('"\\"")())()')
|
359
|
+
end
|
360
|
+
|
361
|
+
return [startpos, endpos, gv]
|
362
|
+
end
|
363
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jjdecoder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anton Maminov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: Ruby version of the jjdecode function for JJEncoded string.
|
56
|
+
email:
|
57
|
+
- anton.linux@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- CODE_OF_CONDUCT.md
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- jjdecoder.gemspec
|
72
|
+
- lib/jjdecoder.rb
|
73
|
+
- lib/jjdecoder/version.rb
|
74
|
+
homepage: https://github.com/mamantoha/jjdecoder
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.5.1
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Ruby decoder for jjencode.
|
98
|
+
test_files: []
|