str_quote 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.md +2 -0
- data/Rakefile +38 -0
- data/lib/str_quote/quote.rb +24 -0
- data/lib/str_quote/version.rb +3 -0
- data/lib/str_quote.rb +6 -0
- data/test/str_quote_test.rb +24 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 981b42aa024359166cac0fb27e711cfef694a2e2
|
4
|
+
data.tar.gz: afea6e3e2d3c96c74a591557136f5fd42a22c86f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 65f68e55665b296fb63374be1262ca3b8c9d7dacf6c0a708d4e7d358ccdb5a02c34e03581678871ac1291afd30fbc7d162aa2b1a33189a45be2f6e22564b76fb
|
7
|
+
data.tar.gz: 94d3269dccb956780642798b1591a321cb19a2301cd7a42dd694982767c35c25f0c1da047842202196ccce3769235585fd46ed6ef9476796d002c297d6204fd1
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 uceem
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
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, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'StrQuote'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
|
30
|
+
Rake::TestTask.new(:test) do |t|
|
31
|
+
t.libs << 'lib'
|
32
|
+
t.libs << 'test'
|
33
|
+
t.pattern = 'test/**/*_test.rb'
|
34
|
+
t.verbose = false
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
task :default => :test
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module StrQuote
|
2
|
+
module Quote
|
3
|
+
def quote(quote_char = '"', escape_char = '\\')
|
4
|
+
unless escape_char.nil?
|
5
|
+
e = self.gsub(quote_char, "#{escape_char}#{quote_char}")
|
6
|
+
else
|
7
|
+
e = self
|
8
|
+
end
|
9
|
+
"#{quote_char}#{e}#{quote_char}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def unquote(quote_char = '"', escape_char = '\\')
|
13
|
+
return self if self.length < 2 or self[0] != quote_char or self[-1] != quote_char
|
14
|
+
|
15
|
+
unless escape_char.nil?
|
16
|
+
self[1..-2].gsub("#{escape_char}#{quote_char}", quote_char)
|
17
|
+
else
|
18
|
+
self[1..-2]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
alias dequote unquote
|
23
|
+
end
|
24
|
+
end
|
data/lib/str_quote.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'str_quote'
|
3
|
+
|
4
|
+
class StrQuoteTest < Test::Unit::TestCase
|
5
|
+
def test_truth
|
6
|
+
assert_kind_of Module, StrQuote
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_quote
|
10
|
+
assert_equal 'Hello'.quote, '"Hello"'
|
11
|
+
assert_equal 'Hello world'.quote, '"Hello world"'
|
12
|
+
assert_equal 'Embed"ded'.quote, '"Embed\"ded"'
|
13
|
+
assert_equal "zz zz".quote("'"), "'zz zz'"
|
14
|
+
assert_equal "gr&t".quote('&','#'), '&gr#&t&'
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_dequote
|
18
|
+
assert_equal 'foobar', '"foobar"'.dequote
|
19
|
+
assert_equal '"Hello world"'.unquote, 'Hello world'
|
20
|
+
assert_equal '"Embed\"ded"'.unquote, 'Embed"ded'
|
21
|
+
assert_equal "'zz zz'".unquote("'"), "zz zz"
|
22
|
+
assert_equal '&gr#&t&'.dequote('&', '#'), "gr&t"
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: str_quote
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Doug Wiegley
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Quoting/unquoting of strings, including escaping
|
14
|
+
email:
|
15
|
+
- doug@uceem.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/str_quote/quote.rb
|
21
|
+
- lib/str_quote/version.rb
|
22
|
+
- lib/str_quote.rb
|
23
|
+
- Rakefile
|
24
|
+
- README.md
|
25
|
+
- LICENSE
|
26
|
+
- test/str_quote_test.rb
|
27
|
+
homepage: https://github.com/uceem/str_quote
|
28
|
+
licenses: []
|
29
|
+
metadata: {}
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubyforge_project:
|
46
|
+
rubygems_version: 2.0.6
|
47
|
+
signing_key:
|
48
|
+
specification_version: 4
|
49
|
+
summary: String quoting
|
50
|
+
test_files:
|
51
|
+
- test/str_quote_test.rb
|