termcolor 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/termcolor.rb +25 -5
- data/spec/termcolor_spec.rb +5 -2
- metadata +2 -2
data/lib/termcolor.rb
CHANGED
@@ -7,16 +7,12 @@ require 'rexml/parsers/baseparser'
|
|
7
7
|
require 'rexml/streamlistener'
|
8
8
|
|
9
9
|
module TermColor
|
10
|
-
VERSION = '0.2.
|
10
|
+
VERSION = '0.2.6'
|
11
11
|
include REXML
|
12
12
|
|
13
13
|
class ParseError < StandardError; end
|
14
14
|
|
15
15
|
class << self
|
16
|
-
def escape(text)
|
17
|
-
CGI.escapeHTML(text)
|
18
|
-
end
|
19
|
-
|
20
16
|
def parse(text)
|
21
17
|
listener = MyListener.new
|
22
18
|
REXML::Parsers::StreamParser.new(text, listener).parse
|
@@ -24,6 +20,30 @@ module TermColor
|
|
24
20
|
rescue REXML::ParseException => e
|
25
21
|
raise ParseError, e
|
26
22
|
end
|
23
|
+
|
24
|
+
def escape(text)
|
25
|
+
text.gsub(/[&<>'"]/) do | match |
|
26
|
+
case match
|
27
|
+
when '&' then '&'
|
28
|
+
when '<' then '<'
|
29
|
+
when '>' then '>'
|
30
|
+
when "'" then '''
|
31
|
+
when '"' then '"e;'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def unescape(text)
|
37
|
+
text.gsub(/&(lt|gt|amp|quote|apos);/) do | match |
|
38
|
+
case match
|
39
|
+
when '&' then '&'
|
40
|
+
when '<' then '<'
|
41
|
+
when '>' then '>'
|
42
|
+
when ''' then "'"
|
43
|
+
when '"e;' then '"'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
27
47
|
end
|
28
48
|
|
29
49
|
class MyListener
|
data/spec/termcolor_spec.rb
CHANGED
@@ -36,8 +36,11 @@ module TermColor
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'should escape text' do
|
39
|
-
|
40
|
-
|
39
|
+
TermColor.escape('<>&"\'').should == "<>&"e;'"
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should unescape text' do
|
43
|
+
TermColor.unescape("<>&"e;'").should == '<>&"\''
|
41
44
|
end
|
42
45
|
|
43
46
|
it 'should convert to escape sequence' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: termcolor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jugyo
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02
|
12
|
+
date: 2009-03-02 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|