unicode-tools 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4e05d62c46b9719b21c9948d09839218ae0b987c
4
+ data.tar.gz: efd5a84c44ed55899af1fbaaf7977abfdf439c24
5
+ SHA512:
6
+ metadata.gz: 8ee83292371cf5d714ab80f3617842d105d5a167d92848fd686dde2f91e7753bbcfef0d355aa0f2f7eeafd1a23f32c93ea62a95ae649c4fedd0ce0535e765762
7
+ data.tar.gz: 6be9d74ba8b3decd9cd131c4cdd504d925ade86071b48b891ef1e51d799276d63c593fac0b48d67b4fb590a1b00e8ca4b9005a16ec38b71e425c32d4b0ffd877
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ source 'https://rubygems.org'
5
+
6
+ # Specify your gem's dependencies in confo.gemspec
7
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Yaroslav Konoplov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ ## Gemfile
2
+ ```ruby
3
+ gem 'unicode-tools', '~> 1.0'
4
+ ```
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'rake/testtask'
5
+ require 'bundler/gem_tasks'
6
+
7
+ Rake::TestTask.new { |t| t.libs << 'test' }
8
+
9
+ desc 'Run test suite'
10
+ task :default => :test
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ # Override ActiveSupport's String#squish
5
+ begin
6
+ require 'active_support/core_ext/string'
7
+ rescue LoadError
8
+ end
9
+
10
+ require 'unicode-tools/whitespace'
11
+ require 'unicode-tools/string_ext/base'
12
+ require 'unicode-tools/string_ext/trim'
13
+ require 'unicode-tools/string_ext/squish'
14
+ require 'unicode-tools/bidi'
15
+
16
+ class String
17
+ include UnicodeTools::StringExt::Base
18
+ include UnicodeTools::StringExt::Trim
19
+ include UnicodeTools::StringExt::Squish
20
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module UnicodeTools
5
+ BIDI_OVERRIDE_CHARS_REGEX = /\u00E2\u0080[\u008E\u008F\u00AA-\u00AE]/.freeze
6
+
7
+ class << self
8
+ def has_bidi_override?(string)
9
+ !!(string =~ BIDI_OVERRIDE_CHARS_REGEX)
10
+ end
11
+
12
+ def strip_bidi_override_chars(string)
13
+ string.gsub(BIDI_OVERRIDE_CHARS_REGEX, '')
14
+ end
15
+
16
+ def strip_bidi_override_chars!(string)
17
+ string.gsub!(BIDI_OVERRIDE_CHARS_REGEX, '')
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module UnicodeTools
5
+ module StringExt
6
+ module Base
7
+ def has_whitespace?
8
+ !!(self =~ WHITESPACE_REGEX)
9
+ end
10
+
11
+ def replace_whitespace(replacement = nil, &block)
12
+ gsub(WHITESPACE_REGEX, replacement, &block)
13
+ end
14
+
15
+ def replace_whitespace!(replacement = nil, &block)
16
+ gsub!(WHITESPACE_REGEX, replacement, &block)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module UnicodeTools
5
+ module StringExt
6
+ module Squish
7
+
8
+ # Removes leading, trailing whitespace and
9
+ # collapses remaining whitespace into one group each.
10
+ #
11
+ # string = " Hello\f\n\r\t\v​\u00A0\u1680​\u180e\u2000​
12
+ # \u2001\u2002​\u2003\u2004​\u2005\u2006
13
+ # ​\u2007\u2008​\u2009\u200a​\u2028\u2029​
14
+ # \u2028\u2029​\u202f\u205f​\u3000 World! "
15
+ # string.squish => "Hello World!"
16
+ def squish
17
+ dup.squish!
18
+ end
19
+
20
+ def squish!
21
+ gsub!(SURROUNDING_WHITESPACE_REGEX, '')
22
+ gsub!(WHITESPACE_REGEX, ' ')
23
+ self
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module UnicodeTools
5
+ module StringExt
6
+ module Trim
7
+
8
+ # Removes leading and trailing whitespace.
9
+ #
10
+ # string = "\f\n\r\t\v​\u00A0\u1680​\u180e\u2000​
11
+ # \u2001\u2002​\u2003\u2004​\u2005\u2006​
12
+ # \u2007\u2008​\u2009\u200a​\u2028\u2029
13
+ # ​\u2028\u2029​\u202f\u205f​\u3000"
14
+ # string.trim => ""
15
+ def trim
16
+ gsub(SURROUNDING_WHITESPACE_REGEX, '')
17
+ end
18
+
19
+ def trim!
20
+ gsub!(SURROUNDING_WHITESPACE_REGEX, '')
21
+ end
22
+
23
+ def ltrim
24
+ gsub(LEADING_WHITESPACE_REGEX, '')
25
+ end
26
+
27
+ def ltrim!
28
+ gsub!(LEADING_WHITESPACE_REGEX, '')
29
+ end
30
+
31
+ def rtrim
32
+ gsub(TRAILING_WHITESPACE_REGEX, '')
33
+ end
34
+
35
+ def rtrim!
36
+ gsub!(TRAILING_WHITESPACE_REGEX, '')
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module UnicodeTools
5
+ # http://unicode.org/charts/uca/
6
+ WHITESPACE_CHARS = %w( \u0009-\u000D \u0085 \u2028 \u2029​​
7
+ \u0020 \u3000 \u1680 \u2000-\u200A
8
+ \u205F \u00A0 \u202F \u180E ).freeze
9
+
10
+ WHITESPACE_REGEX = /[#{WHITESPACE_CHARS.join('')}]+/.freeze
11
+ LEADING_WHITESPACE_REGEX = /\A#{WHITESPACE_REGEX.source}+/.freeze
12
+ TRAILING_WHITESPACE_REGEX = /#{WHITESPACE_REGEX.source}+\z/.freeze
13
+ SURROUNDING_WHITESPACE_REGEX = /(\A#{WHITESPACE_REGEX.source})|(#{WHITESPACE_REGEX.source}\z)/.freeze
14
+
15
+ class << self
16
+ def has_whitespace?(string)
17
+ string.has_whitespace?
18
+ end
19
+
20
+ def trim(string)
21
+ string.trim
22
+ end
23
+
24
+ def trim!(string)
25
+ string.trim!
26
+ end
27
+
28
+ def squish(string)
29
+ string.squish
30
+ end
31
+
32
+ def squish!(string)
33
+ string.squish!
34
+ end
35
+
36
+ def replace_whitespace(string, replacement = nil, &block)
37
+ string.replace_whitespace(replacement, &block)
38
+ end
39
+
40
+ def replace_whitespace!(string, replacement = nil, &block)
41
+ string.replace_whitespace!(replacement, &block)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'unicode-tools'
5
+ require 'test/unit'
6
+
7
+ class UnicodeToolsTest < Test::Unit::TestCase
8
+ def test_trim
9
+ s = ["\f\n\r\t\v​\u00A0\u1680​\u180e\u2000​\u2001",
10
+ "\u2002​\u2003\u2004​\u2005\u2006​\u2007\u2008​",
11
+ "\u2009\u200a​\u2028\u2029​\u2028\u2029​\u202f\u205f​\u3000"].join('')
12
+ assert_equal(s.trim, '')
13
+ assert_equal(UnicodeTools.trim(s), '')
14
+ end
15
+
16
+ def test_squish
17
+ s = ["Hello\f\n\r\t\v​\u00A0\u1680​\u180e\u2000​\u2001",
18
+ "\u2002​\u2003\u2004​\u2005\u2006​\u2007\u2008​",
19
+ "\u2009\u200a​\u2028\u2029​\u2028\u2029​\u202f\u205f​\u3000 world!"].join('')
20
+ assert_equal(s.squish, 'Hello world!')
21
+ assert_equal(UnicodeTools.squish(s), 'Hello world!')
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'unicode-tools'
6
+ s.version = '1.0.1'
7
+ s.authors = ['Yaroslav Konoplov']
8
+ s.email = ['eahome00@gmail.com']
9
+ s.summary = 'Unicode Tools'
10
+ s.description = 'Unicode Tools'
11
+ s.homepage = 'http://github.com/yivo/unicode-tools'
12
+ s.license = 'MIT'
13
+
14
+ s.executables = `git ls-files -z -- bin/*`.split("\x0").map{ |f| File.basename(f) }
15
+ s.files = `git ls-files -z`.split("\x0")
16
+ s.test_files = `git ls-files -z -- {test,spec,features}/*`.split("\x0")
17
+ s.require_paths = ['lib']
18
+
19
+ s.add_development_dependency 'rake', '~> 10.0'
20
+ s.add_development_dependency 'test-unit', '~> 3.1.8'
21
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unicode-tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yaroslav Konoplov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-unit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.1.8
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.1.8
41
+ description: Unicode Tools
42
+ email:
43
+ - eahome00@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/unicode-tools.rb
54
+ - lib/unicode-tools/bidi.rb
55
+ - lib/unicode-tools/string_ext/base.rb
56
+ - lib/unicode-tools/string_ext/squish.rb
57
+ - lib/unicode-tools/string_ext/trim.rb
58
+ - lib/unicode-tools/whitespace.rb
59
+ - test/test_unicode_tools.rb
60
+ - unicode-tools.gemspec
61
+ homepage: http://github.com/yivo/unicode-tools
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.5.1
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Unicode Tools
85
+ test_files:
86
+ - test/test_unicode_tools.rb