├── CHANGELOG.md ├── Manifest.txt ├── README.md ├── Rakefile ├── UnicodeData.txt ├── lib ├── widen.rb └── widen.rb.erb └── test └── test_widen.rb /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | === 1.0.0 / 2016-06-23 2 | 3 | * 1 major enhancement 4 | 5 | * Birthday! 6 | 7 | -------------------------------------------------------------------------------- /Manifest.txt: -------------------------------------------------------------------------------- 1 | CHANGELOG.md 2 | Manifest.txt 3 | README.md 4 | Rakefile 5 | UnicodeData.txt 6 | lib/widen.rb 7 | lib/widen.rb.erb 8 | test/test_widen.rb 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Widen 2 | 3 | * https://github.com/tenderlove/widen 4 | 5 | ## DESCRIPTION: 6 | 7 | We already have `String#upcase`, `String#downcase`. Now you can have 8 | `String#widen` and `String#narrowen`! 9 | 10 | ## FEATURES/PROBLEMS: 11 | 12 | * No features or problems 13 | 14 | ## SYNOPSIS: 15 | 16 | ```ruby 17 | 'abcde'.widen => 'ABCDE' 18 | 'ABCDE'.narrowen => 'abcde' 19 | ``` 20 | 21 | ## INSTALL: 22 | 23 | * gem install widen 24 | 25 | ## LICENSE: 26 | 27 | (The MIT License) 28 | 29 | Copyright (c) 2016 Aaron Patterson 30 | 31 | Permission is hereby granted, free of charge, to any person obtaining 32 | a copy of this software and associated documentation files (the 33 | 'Software'), to deal in the Software without restriction, including 34 | without limitation the rights to use, copy, modify, merge, publish, 35 | distribute, sublicense, and/or sell copies of the Software, and to 36 | permit persons to whom the Software is furnished to do so, subject to 37 | the following conditions: 38 | 39 | The above copyright notice and this permission notice shall be 40 | included in all copies or substantial portions of the Software. 41 | 42 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 43 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 44 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 45 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 46 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 47 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 48 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 49 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # -*- ruby -*- 2 | 3 | require 'rubygems' 4 | require 'hoe' 5 | 6 | Hoe.plugins.delete :rubyforge 7 | Hoe.plugin :minitest 8 | Hoe.plugin :gemspec # `gem install hoe-gemspec` 9 | Hoe.plugin :git # `gem install hoe-git` 10 | 11 | Hoe.spec 'widen' do 12 | developer('Aaron Patterson', 'tenderlove@ruby-lang.org') 13 | self.readme_file = 'README.md' 14 | self.history_file = 'CHANGELOG.md' 15 | self.extra_rdoc_files = FileList['*.rdoc'] 16 | license 'MIT' 17 | end 18 | 19 | def parse list 20 | list.map { |from,_,_,_,_,size| [from.to_i(16), size[/[0-9A-F]*$/].to_i(16)] } 21 | end 22 | 23 | file 'lib/widen.rb' do |t| 24 | require 'erb' 25 | narrows, wides = File.open 'UnicodeData.txt', 'r' do |f| 26 | f.each_line.map do |line| 27 | if line =~ /^FF01/ .. line =~ /^FFEE/ 28 | line.split(';') 29 | end 30 | end.compact.partition { |row| row[5] =~ /narrow/ } 31 | end 32 | 33 | small_to_big = parse(narrows) + parse(wides).map(&:reverse) 34 | narrow = small_to_big.map(&:first).pack('U*').gsub(/\\/, "\\\\\\\\") 35 | wide = small_to_big.map(&:last).pack 'U*' 36 | File.write 'lib/widen.rb', ERB.new(File.read('lib/widen.rb.erb')).result(binding) 37 | end 38 | 39 | # vim: syntax=ruby 40 | -------------------------------------------------------------------------------- /lib/widen.rb: -------------------------------------------------------------------------------- 1 | class String 2 | VERSION = '1.0.0' 3 | NARROW = "\u{ff61}\u{ff62}\u{ff63}\u{ff64}\u{ff65}\u{ff66}\u{ff67}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= "\u{3002}\u{300c}\u{300d}\u{3001}\u{30fb}\u{30f2}\u{30a1}\u{30a3}\u{30a5}\u{30a7}\u{30a9}\u{30e3}\u{30e5}\u{30e7}\u{30c3}\u{30fc}\u{30a2}\u{30a4}\u{30a6}\u{30a8}\u{30aa}\u{30ab}\u{30ad}\u{30af}\u{30b1}\u{30b3}\u{30b5}\u{30b7}\u{30b9}\u{30bb}\u{30bd}\u{30bf}\u{30c1}\u{30c4}\u{30c6}\u{30c8}\u{30ca}\u{30cb}\u{30cc}\u{30cd}\u{30ce}\u{30cf}\u{30d2}\u{30d5}\u{30d8}\u{30db}\u{30de}\u{30df}\u{30e0}\u{30e1}\u{30e2}\u{30e4}\u{30e6}\u{30e8}\u{30e9}\u{30ea}\u{30eb}\u{30ec}\u{30ed}\u{30ef}\u{30f3}\u{3099}\u{309a}\u{3164}\u{3131}\u{3132}\u{3133}\u{3134}\u{3135}\u{3136}\u{3137}\u{3138}\u{3139}\u{313a}\u{313b}\u{313c}\u{313d}\u{313e}\u{313f}\u{3140}\u{3141}\u{3142}\u{3143}\u{3144}\u{3145}\u{3146}\u{3147}\u{3148}\u{3149}\u{314a}\u{314b}\u{314c}\u{314d}\u{314e}\u{314f}\u{3150}\u{3151}\u{3152}\u{3153}\u{3154}\u{3155}\u{3156}\u{3157}\u{3158}\u{3159}\u{315a}\u{315b}\u{315c}\u{315d}\u{315e}\u{315f}\u{3160}\u{3161}\u{3162}\u{3163}\u{2502}\u{2190}\u{2191}\u{2192}\u{2193}\u{25a0}\u{25cb}\u{ff01}\u{ff02}\u{ff03}\u{ff04}\u{ff05}\u{ff06}\u{ff07}\u{ff08}\u{ff09}\u{ff0a}\u{ff0b}\u{ff0c}\u{ff0d}\u{ff0e}\u{ff0f}\u{ff10}\u{ff11}\u{ff12}\u{ff13}\u{ff14}\u{ff15}\u{ff16}\u{ff17}\u{ff18}\u{ff19}\u{ff1a}\u{ff1b}\u{ff1c}\u{ff1d}\u{ff1e}\u{ff1f}\u{ff20}\u{ff21}\u{ff22}\u{ff23}\u{ff24}\u{ff25}\u{ff26}\u{ff27}\u{ff28}\u{ff29}\u{ff2a}\u{ff2b}\u{ff2c}\u{ff2d}\u{ff2e}\u{ff2f}\u{ff30}\u{ff31}\u{ff32}\u{ff33}\u{ff34}\u{ff35}\u{ff36}\u{ff37}\u{ff38}\u{ff39}\u{ff3a}\u{ff3b}\u{ff3c}\u{ff3d}\u{ff3e}\u{ff3f}\u{ff40}\u{ff41}\u{ff42}\u{ff43}\u{ff44}\u{ff45}\u{ff46}\u{ff47}\u{ff48}\u{ff49}\u{ff4a}\u{ff4b}\u{ff4c}\u{ff4d}\u{ff4e}\u{ff4f}\u{ff50}\u{ff51}\u{ff52}\u{ff53}\u{ff54}\u{ff55}\u{ff56}\u{ff57}\u{ff58}\u{ff59}\u{ff5a}\u{ff5b}\u{ff5c}\u{ff5d}\u{ff5e}\u{ff5f}\u{ff60}\u{ffe0}\u{ffe1}\u{ffe2}\u{ffe3}\u{ffe4}\u{ffe5}\u{ffe6}" 5 | def widen; tr(NARROW, WIDE); end 6 | def narrowen; tr(WIDE, NARROW); end 7 | def widen!; tr!(NARROW, WIDE); end 8 | def narrowen!; tr!(WIDE, NARROW); end 9 | end 10 | -------------------------------------------------------------------------------- /lib/widen.rb.erb: -------------------------------------------------------------------------------- 1 | class String 2 | VERSION = '1.0.0' 3 | NARROW = <%= narrow.dump %> 4 | WIDE = <%= wide.dump %> 5 | def widen; tr(NARROW, WIDE); end 6 | def narrowen; tr(WIDE, NARROW); end 7 | def widen!; tr!(NARROW, WIDE); end 8 | def narrowen!; tr!(WIDE, NARROW); end 9 | end 10 | -------------------------------------------------------------------------------- /test/test_widen.rb: -------------------------------------------------------------------------------- 1 | require 'minitest/autorun' 2 | require 'widen' 3 | 4 | class TestWiden < Minitest::Test 5 | def test_no_mutation 6 | assert_equal 'ABCDE', 'abcde'.upcase.widen 7 | assert_equal 'abcde', 'ABCDE'.narrowen.downcase 8 | end 9 | 10 | def test_mutation 11 | x = 'abcde'.upcase 12 | x.widen! 13 | assert_equal 'ABCDE', x 14 | 15 | x = 'ABCDE'.downcase 16 | x.narrowen! 17 | assert_equal 'abcde', x 18 | end 19 | end 20 | --------------------------------------------------------------------------------