charwidth 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rubocop.yml +127 -0
- data/CHANGELOG.md +27 -0
- data/Gemfile +11 -12
- data/Gemfile.lock +71 -25
- data/LICENSE.txt +3 -1
- data/README.md +46 -16
- data/Rakefile +1 -51
- data/bin/rspec +29 -0
- data/bin/rubocop +29 -0
- data/charwidth.gemspec +21 -58
- data/exe/charwidth +3 -0
- data/lib/charwidth.rb +88 -31
- data/lib/charwidth/active_model.rb +24 -0
- data/lib/charwidth/characters.rb +13 -13
- data/lib/charwidth/cli.rb +31 -0
- data/lib/charwidth/string.rb +8 -0
- data/lib/charwidth/version.rb +1 -7
- metadata +33 -94
- data/spec/charwidth_spec.rb +0 -44
- data/spec/spec_helper.rb +0 -12
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 133819f5ab71a842c32836111306f610641d82cfd4a77c00bbcec383ac981ea7
|
4
|
+
data.tar.gz: a6b8a19034123788ae3954034d71fa3b58f25debf9e5501868b23fd6b9df1030
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a3aaa79d412eb608c15d546c1b30e86b640ca9f3958665a656ca109fed36597879695d01dc39076088165ad00af307bfadd0a2f976edb502e23ad5b708b3ac1f
|
7
|
+
data.tar.gz: e02b783ac3c5b8d17488f2df375770232ad31b22c5bb43d7da0a946268a5a59b6188c34ca22ee310a144fb83405ec7ed1aa04c181ad5bdc84771162fa59fb7db
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- bin/*
|
4
|
+
- node_modules/**/*
|
5
|
+
NewCops: enable
|
6
|
+
|
7
|
+
Layout/CaseIndentation:
|
8
|
+
EnforcedStyle: end
|
9
|
+
|
10
|
+
Layout/EndAlignment:
|
11
|
+
EnforcedStyleAlignWith: variable
|
12
|
+
|
13
|
+
Layout/LineLength:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Layout/EmptyLinesAroundAccessModifier:
|
17
|
+
EnforcedStyle: only_before
|
18
|
+
|
19
|
+
Layout/SpaceInLambdaLiteral:
|
20
|
+
EnforcedStyle: require_space
|
21
|
+
|
22
|
+
Layout/SpaceInsideBlockBraces:
|
23
|
+
SpaceBeforeBlockParameters: false
|
24
|
+
|
25
|
+
Layout/SpaceInsideHashLiteralBraces:
|
26
|
+
EnforcedStyle: no_space
|
27
|
+
|
28
|
+
Metrics/AbcSize:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Metrics/BlockLength:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Metrics/ClassLength:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Metrics/CyclomaticComplexity:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Metrics/MethodLength:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Metrics/ModuleLength:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Metrics/PerceivedComplexity:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Naming/HeredocDelimiterNaming:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
Naming/MethodParameterName:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
Naming/PredicateName:
|
56
|
+
Enabled: false
|
57
|
+
|
58
|
+
Style/Alias:
|
59
|
+
EnforcedStyle: prefer_alias_method
|
60
|
+
|
61
|
+
Style/AsciiComments:
|
62
|
+
Enabled: false
|
63
|
+
|
64
|
+
Style/BlockDelimiters:
|
65
|
+
Enabled: false
|
66
|
+
|
67
|
+
Style/Documentation:
|
68
|
+
Enabled: false
|
69
|
+
|
70
|
+
Style/EmptyCaseCondition:
|
71
|
+
Enabled: false
|
72
|
+
|
73
|
+
Style/EmptyMethod:
|
74
|
+
EnforcedStyle: expanded
|
75
|
+
|
76
|
+
Style/FrozenStringLiteralComment:
|
77
|
+
Enabled: false
|
78
|
+
|
79
|
+
Style/HashSyntax:
|
80
|
+
Exclude:
|
81
|
+
- Rakefile
|
82
|
+
- "**/*.rake"
|
83
|
+
|
84
|
+
Style/Lambda:
|
85
|
+
EnforcedStyle: literal
|
86
|
+
|
87
|
+
Style/IfUnlessModifier:
|
88
|
+
Enabled: false
|
89
|
+
|
90
|
+
Style/MultilineBlockChain:
|
91
|
+
Enabled: false
|
92
|
+
|
93
|
+
Style/NumericLiterals:
|
94
|
+
Enabled: false
|
95
|
+
|
96
|
+
Style/NumericPredicate:
|
97
|
+
Enabled: false
|
98
|
+
|
99
|
+
Style/PercentLiteralDelimiters:
|
100
|
+
PreferredDelimiters:
|
101
|
+
'%i': '()'
|
102
|
+
'%w': '()'
|
103
|
+
'%r': '()'
|
104
|
+
|
105
|
+
Style/SpecialGlobalVars:
|
106
|
+
Enabled: false
|
107
|
+
|
108
|
+
Style/StringLiterals:
|
109
|
+
EnforcedStyle: double_quotes
|
110
|
+
|
111
|
+
Style/StringLiteralsInInterpolation:
|
112
|
+
EnforcedStyle: double_quotes
|
113
|
+
|
114
|
+
Style/SymbolArray:
|
115
|
+
Enabled: false
|
116
|
+
|
117
|
+
Style/TrailingCommaInArguments:
|
118
|
+
EnforcedStyleForMultiline: consistent_comma
|
119
|
+
|
120
|
+
Style/TrailingCommaInArrayLiteral:
|
121
|
+
EnforcedStyleForMultiline: consistent_comma
|
122
|
+
|
123
|
+
Style/TrailingCommaInHashLiteral:
|
124
|
+
EnforcedStyleForMultiline: consistent_comma
|
125
|
+
|
126
|
+
Style/ZeroLengthPredicate:
|
127
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
### v0.2.1
|
2
|
+
|
3
|
+
- Exclude dependency executables (rspec, rubocop). (Thank you @ta1kt0me for reporting an issue)
|
4
|
+
|
5
|
+
### v0.2.0
|
6
|
+
|
7
|
+
- Add `normalize_charwidth` method instead of problematic ActiveRecord integration.
|
8
|
+
|
9
|
+
### v0.1.5
|
10
|
+
|
11
|
+
- Fix active_record.rb to follow the change of AR after 5.2.
|
12
|
+
|
13
|
+
### v0.1.4
|
14
|
+
|
15
|
+
- Add Charwidth.to_full_width
|
16
|
+
|
17
|
+
### v0.1.3
|
18
|
+
|
19
|
+
- Change CLI behavier (Use ARGV as source text (not file name), show help for no augment with tty)
|
20
|
+
|
21
|
+
### v0.1.1
|
22
|
+
|
23
|
+
- Fix invalid convertion for harf-width katakana: TSU TE TO
|
24
|
+
|
25
|
+
### v0.1.0
|
26
|
+
|
27
|
+
- Initial release.
|
data/Gemfile
CHANGED
@@ -1,13 +1,12 @@
|
|
1
|
-
source "
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
1
|
+
source "https://rubygems.org"
|
5
2
|
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
# Specify your gem's dependencies in charwidth_template.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem "activemodel", ">= 3"
|
7
|
+
gem "bundler"
|
8
|
+
gem "byebug"
|
9
|
+
gem "rake"
|
10
|
+
gem "rspec"
|
11
|
+
gem "rspec-its"
|
12
|
+
gem "rubocop"
|
data/Gemfile.lock
CHANGED
@@ -1,32 +1,78 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
charwidth (0.2.1)
|
5
|
+
|
1
6
|
GEM
|
2
|
-
remote:
|
7
|
+
remote: https://rubygems.org/
|
3
8
|
specs:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
9
|
+
activemodel (6.1.3.2)
|
10
|
+
activesupport (= 6.1.3.2)
|
11
|
+
activesupport (6.1.3.2)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 1.6, < 2)
|
14
|
+
minitest (>= 5.1)
|
15
|
+
tzinfo (~> 2.0)
|
16
|
+
zeitwerk (~> 2.3)
|
17
|
+
ast (2.4.2)
|
18
|
+
byebug (11.1.3)
|
19
|
+
concurrent-ruby (1.1.8)
|
20
|
+
diff-lcs (1.4.4)
|
21
|
+
i18n (1.8.10)
|
22
|
+
concurrent-ruby (~> 1.0)
|
23
|
+
minitest (5.14.4)
|
24
|
+
parallel (1.20.1)
|
25
|
+
parser (3.0.0.0)
|
26
|
+
ast (~> 2.4.1)
|
27
|
+
rainbow (3.0.0)
|
28
|
+
rake (13.0.3)
|
29
|
+
regexp_parser (2.1.1)
|
30
|
+
rexml (3.2.4)
|
31
|
+
rspec (3.10.0)
|
32
|
+
rspec-core (~> 3.10.0)
|
33
|
+
rspec-expectations (~> 3.10.0)
|
34
|
+
rspec-mocks (~> 3.10.0)
|
35
|
+
rspec-core (3.10.1)
|
36
|
+
rspec-support (~> 3.10.0)
|
37
|
+
rspec-expectations (3.10.1)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.10.0)
|
40
|
+
rspec-its (1.3.0)
|
41
|
+
rspec-core (>= 3.0.0)
|
42
|
+
rspec-expectations (>= 3.0.0)
|
43
|
+
rspec-mocks (3.10.2)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.10.0)
|
46
|
+
rspec-support (3.10.2)
|
47
|
+
rubocop (1.10.0)
|
48
|
+
parallel (~> 1.10)
|
49
|
+
parser (>= 3.0.0.0)
|
50
|
+
rainbow (>= 2.2.2, < 4.0)
|
51
|
+
regexp_parser (>= 1.8, < 3.0)
|
52
|
+
rexml
|
53
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
54
|
+
ruby-progressbar (~> 1.7)
|
55
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
56
|
+
rubocop-ast (1.4.1)
|
57
|
+
parser (>= 2.7.1.5)
|
58
|
+
ruby-progressbar (1.11.0)
|
59
|
+
tzinfo (2.0.4)
|
60
|
+
concurrent-ruby (~> 1.0)
|
61
|
+
unicode-display_width (2.0.0)
|
62
|
+
zeitwerk (2.4.2)
|
24
63
|
|
25
64
|
PLATFORMS
|
26
65
|
ruby
|
27
66
|
|
28
67
|
DEPENDENCIES
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
68
|
+
activemodel (>= 3)
|
69
|
+
bundler
|
70
|
+
byebug
|
71
|
+
charwidth!
|
72
|
+
rake
|
73
|
+
rspec
|
74
|
+
rspec-its
|
75
|
+
rubocop
|
76
|
+
|
77
|
+
BUNDLED WITH
|
78
|
+
2.1.2
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,18 @@ Normalize Unicode fullwidth / halfwidth (zenkaku / hankaku) characters.
|
|
4
4
|
|
5
5
|
# Installation
|
6
6
|
|
7
|
-
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'charwidth'
|
10
|
+
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install charwidth
|
8
19
|
|
9
20
|
# Usage
|
10
21
|
|
@@ -19,19 +30,38 @@ Or extend String class.
|
|
19
30
|
"Hello, World!".normalize_charwidth # => "Hello, World!"
|
20
31
|
"Hello, World!".normalize_charwidth! # => destructive
|
21
32
|
"「ハローワールド」".normalize_charwidth # => "「ハローワールド」"
|
22
|
-
|
23
|
-
# Contributing to charwidth
|
24
|
-
|
25
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
26
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
27
|
-
* Fork the project
|
28
|
-
* Start a feature/bugfix branch
|
29
|
-
* Commit and push until you are happy with your contribution
|
30
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
31
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
32
|
-
|
33
|
-
# Copyright
|
34
|
-
|
35
|
-
Copyright (c) 2012 labocho. See LICENSE.txt for
|
36
|
-
further details.
|
37
33
|
|
34
|
+
# Rails integration
|
35
|
+
|
36
|
+
Add lines below to `app/models/application_record.rb`.
|
37
|
+
|
38
|
+
require "charwidth/active_model"
|
39
|
+
class ApplicationRecord < ActiveRecord::Base
|
40
|
+
include Charwidth::ActiveModel
|
41
|
+
end
|
42
|
+
|
43
|
+
And call `normalize_charwidth` class method in model class.
|
44
|
+
|
45
|
+
class Article < ActiveRecord::Base
|
46
|
+
normalize_charwidth :title, :body
|
47
|
+
end
|
48
|
+
|
49
|
+
a = Article.new(title: "Hello, World!")
|
50
|
+
a.title # => "Hello, World!"
|
51
|
+
|
52
|
+
# CLI
|
53
|
+
|
54
|
+
# Call charwidth command with arguments
|
55
|
+
$ charwidth "Hello, World!"
|
56
|
+
Hello, World!
|
57
|
+
# Or as STDIN
|
58
|
+
$ echo "Hello, World!" | charwidth
|
59
|
+
Hello, World!
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
1. Fork it
|
64
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
65
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
66
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
67
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
@@ -1,51 +1 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler'
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
require 'rake'
|
13
|
-
|
14
|
-
require 'jeweler'
|
15
|
-
require "#{File.dirname(__FILE__)}/lib/charwidth/version"
|
16
|
-
Jeweler::Tasks.new do |gem|
|
17
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
18
|
-
gem.name = "charwidth"
|
19
|
-
gem.version = Charwidth::Version::STRING
|
20
|
-
gem.homepage = "http://github.com/labocho/charwidth"
|
21
|
-
gem.license = "MIT"
|
22
|
-
gem.summary = %Q{Normalize Japanese / Korean fullwidth (zenkaku) and halfwidth (hankaku) characters}
|
23
|
-
gem.description = %Q{Normalize Japanese / Korean fullwidth (zenkaku) and halfwidth (hankaku) characters}
|
24
|
-
gem.email = "labocho@penguinlab.jp"
|
25
|
-
gem.authors = ["labocho"]
|
26
|
-
# dependencies defined in Gemfile
|
27
|
-
end
|
28
|
-
Jeweler::RubygemsDotOrgTasks.new
|
29
|
-
|
30
|
-
require 'rspec/core'
|
31
|
-
require 'rspec/core/rake_task'
|
32
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
33
|
-
spec.pattern = FileList['spec/**/*_spec.rb']
|
34
|
-
end
|
35
|
-
|
36
|
-
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
37
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
38
|
-
spec.rcov = true
|
39
|
-
end
|
40
|
-
|
41
|
-
task :default => :spec
|
42
|
-
|
43
|
-
require 'rake/rdoctask'
|
44
|
-
Rake::RDocTask.new do |rdoc|
|
45
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
46
|
-
|
47
|
-
rdoc.rdoc_dir = 'rdoc'
|
48
|
-
rdoc.title = "charwidth #{version}"
|
49
|
-
rdoc.rdoc_files.include('README*')
|
50
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
-
end
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/rspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/rubocop
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rubocop' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rubocop", "rubocop")
|
data/charwidth.gemspec
CHANGED
@@ -1,63 +1,26 @@
|
|
1
|
-
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
require_relative "lib/charwidth/version"
|
5
2
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "charwidth"
|
5
|
+
spec.version = Charwidth::VERSION
|
6
|
+
spec.authors = ["labocho"]
|
7
|
+
spec.email = ["labocho@penguinlab.jp"]
|
8
|
+
spec.description = "Normalize Japanese / Korean fullwidth (zenkaku) and halfwidth (hankaku) characters"
|
9
|
+
spec.summary = "Normalize Japanese / Korean fullwidth (zenkaku) and halfwidth (hankaku) characters"
|
10
|
+
spec.homepage = "https://github.com/labocho/charwidth"
|
11
|
+
spec.license = "MIT"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
s.description = "Normalize Japanese / Korean fullwidth (zenkaku) and halfwidth (hankaku) characters"
|
14
|
-
s.email = "labocho@penguinlab.jp"
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE.txt",
|
17
|
-
"README.md"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".cleancode",
|
21
|
-
".document",
|
22
|
-
".rspec",
|
23
|
-
"Gemfile",
|
24
|
-
"Gemfile.lock",
|
25
|
-
"LICENSE.txt",
|
26
|
-
"README.md",
|
27
|
-
"Rakefile",
|
28
|
-
"charwidth.gemspec",
|
29
|
-
"lib/charwidth.rb",
|
30
|
-
"lib/charwidth/characters.rb",
|
31
|
-
"lib/charwidth/string.rb",
|
32
|
-
"lib/charwidth/version.rb",
|
33
|
-
"spec/charwidth_spec.rb",
|
34
|
-
"spec/spec_helper.rb"
|
35
|
-
]
|
36
|
-
s.homepage = "http://github.com/labocho/charwidth"
|
37
|
-
s.licenses = ["MIT"]
|
38
|
-
s.require_paths = ["lib"]
|
39
|
-
s.rubygems_version = "1.8.23"
|
40
|
-
s.summary = "Normalize Japanese / Korean fullwidth (zenkaku) and halfwidth (hankaku) characters"
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
16
|
+
spec.metadata["changelog_uri"] = "https://github.com/labocho/charwidth/blob/master/CHANGELOG.md"
|
41
17
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
47
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
48
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
49
|
-
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
50
|
-
else
|
51
|
-
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
52
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
53
|
-
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
54
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
55
|
-
end
|
56
|
-
else
|
57
|
-
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
58
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
59
|
-
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
60
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
|
61
22
|
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r(^exe/)) {|f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
62
26
|
end
|
63
|
-
|
data/exe/charwidth
ADDED
data/lib/charwidth.rb
CHANGED
@@ -1,9 +1,46 @@
|
|
1
|
+
require "charwidth/version"
|
2
|
+
|
1
3
|
module Charwidth
|
2
4
|
autoload :String, "charwidth/string"
|
3
5
|
autoload :Characters, "charwidth/characters"
|
4
|
-
autoload :
|
6
|
+
autoload :CLI, "charwidth/cli"
|
5
7
|
|
6
8
|
module ClassMethods
|
9
|
+
HALFWIDTH_TO_FULLWIDTH = {
|
10
|
+
ascii: [
|
11
|
+
Characters::ASCII_PUNCTUATION_AND_SYMBOLS,
|
12
|
+
Characters::FULLWIDTH_ASCII_VARIANTS,
|
13
|
+
],
|
14
|
+
white_parenthesis: [
|
15
|
+
Characters::WHITE_PARENTHESIS,
|
16
|
+
Characters::FULLWIDTH_BRACKETS,
|
17
|
+
],
|
18
|
+
cjk_punctuation: [
|
19
|
+
Characters::HALFWIDTH_CJK_PUCTUATION,
|
20
|
+
Characters::CJK_SYMBOLS_AND_PUNCTUATION,
|
21
|
+
],
|
22
|
+
katakana: [
|
23
|
+
Characters::HALFWIDTH_KATAKANA_VARIANTS,
|
24
|
+
Characters::KATAKANA,
|
25
|
+
],
|
26
|
+
hangul: [
|
27
|
+
Characters::HALFWIDTH_HANGUL_VARIANTS,
|
28
|
+
Characters::HANGUL,
|
29
|
+
],
|
30
|
+
latin_1_punctuation_and_symbols: [
|
31
|
+
Characters::LATIN_1_PUNCTUATION_AND_SYMBOLS,
|
32
|
+
Characters::FULLWIDTH_SYMBOL_VARIANTS,
|
33
|
+
],
|
34
|
+
mathematical_symbols: [
|
35
|
+
Characters::HALFWIDTH_SYMBOL_VARIANTS,
|
36
|
+
Characters::MATHEMATICAL_SYMBOLS,
|
37
|
+
],
|
38
|
+
space: [
|
39
|
+
Characters::SPACE,
|
40
|
+
Characters::IDEOGRAPHIC_SPACE,
|
41
|
+
],
|
42
|
+
}.transform_values(&:freeze).freeze
|
43
|
+
|
7
44
|
# Normalize Unicode fullwidth / halfwidth (zenkaku / hankaku) characters
|
8
45
|
# options: {
|
9
46
|
# only: [:ascii, :white_parenthesis, :cjk_punctuation, :katakana, :space],
|
@@ -19,10 +56,29 @@ module Charwidth
|
|
19
56
|
normalize_charwidth!(string, options)
|
20
57
|
end
|
21
58
|
|
59
|
+
def to_full_width(string)
|
60
|
+
to_full_width!(string.dup)
|
61
|
+
end
|
62
|
+
|
63
|
+
def to_full_width!(src)
|
64
|
+
unify_voiced_katakana!(src)
|
65
|
+
|
66
|
+
before = ""
|
67
|
+
after = ""
|
68
|
+
HALFWIDTH_TO_FULLWIDTH.each_value do |half, full|
|
69
|
+
before << half
|
70
|
+
after << full
|
71
|
+
end
|
72
|
+
|
73
|
+
escape_for_tr!(before)
|
74
|
+
escape_for_tr!(after)
|
75
|
+
src.tr!(before, after) || src
|
76
|
+
end
|
77
|
+
|
22
78
|
private
|
23
79
|
TYPES = [
|
24
80
|
:ascii, :white_parenthesis, :cjk_punctuation, :katakana, :hangul,
|
25
|
-
:latin_1_punctuation_and_symbols, :mathematical_symbols, :space
|
81
|
+
:latin_1_punctuation_and_symbols, :mathematical_symbols, :space,
|
26
82
|
].freeze
|
27
83
|
def normalize_charwidth!(src, options = {})
|
28
84
|
types = TYPES.dup
|
@@ -36,47 +92,39 @@ module Charwidth
|
|
36
92
|
unless (unexpected_types = options[:only] - TYPES).empty?
|
37
93
|
raise "Unexpected normalize type(s): #{unexpected_types.inspect}"
|
38
94
|
end
|
39
|
-
|
95
|
+
|
96
|
+
types &= options[:only]
|
40
97
|
end
|
41
98
|
|
42
99
|
if options[:expect]
|
43
100
|
unless (unexpected_types = options[:expected] - TYPES).empty?
|
44
|
-
raise "Unexpected normalize type(s): #{
|
101
|
+
raise "Unexpected normalize type(s): #{unexpected_types.inspect}"
|
45
102
|
end
|
46
|
-
|
103
|
+
|
104
|
+
types -= options[:expect]
|
47
105
|
end
|
48
106
|
|
49
|
-
before
|
107
|
+
before = ""
|
108
|
+
after = ""
|
50
109
|
types.each do |type|
|
51
110
|
case type
|
52
|
-
when :ascii
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
when :cjk_punctuation
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
when :hangul
|
65
|
-
before << Characters::HALFWIDTH_HANGUL_VARIANTS
|
66
|
-
after << Characters::HANGUL
|
67
|
-
when :latin_1_punctuation_and_symbols
|
68
|
-
before << Characters::FULLWIDTH_SYMBOL_VARIANTS
|
69
|
-
after << Characters::LATIN_1_PUNCTUATION_AND_SYMBOLS
|
70
|
-
when :mathematical_symbols
|
71
|
-
before << Characters::HALFWIDTH_SYMBOL_VARIANTS
|
72
|
-
after << Characters::MATHEMATICAL_SYMBOLS
|
73
|
-
when :space
|
74
|
-
before << Characters::IDEOGRAPHIC_SPACE
|
75
|
-
after << Characters::SPACE
|
111
|
+
when :ascii, :white_parenthesis, :latin_1_punctuation_and_symbols, :space
|
112
|
+
# convert fullwidth to halfwidth
|
113
|
+
HALFWIDTH_TO_FULLWIDTH[type].tap {|half, full|
|
114
|
+
before << full
|
115
|
+
after << half
|
116
|
+
}
|
117
|
+
when :cjk_punctuation, :katakana, :hangul, :mathematical_symbols
|
118
|
+
# convert halfwidth to fullwidth
|
119
|
+
HALFWIDTH_TO_FULLWIDTH[type].tap {|half, full|
|
120
|
+
before << half
|
121
|
+
after << full
|
122
|
+
}
|
76
123
|
end
|
77
124
|
end
|
78
125
|
|
79
|
-
|
126
|
+
escape_for_tr!(before)
|
127
|
+
escape_for_tr!(after)
|
80
128
|
src.tr!(before, after) || src
|
81
129
|
end
|
82
130
|
|
@@ -92,6 +140,15 @@ module Charwidth
|
|
92
140
|
str.gsub!(h, f) || str
|
93
141
|
end
|
94
142
|
end
|
143
|
+
|
144
|
+
def escape_for_tr!(s)
|
145
|
+
s.gsub!('\\', '\\\\')
|
146
|
+
s.gsub!("-", '\\-')
|
147
|
+
s.gsub!("^", '\\^')
|
148
|
+
s.gsub!("[", '\\[')
|
149
|
+
s.gsub!("]", '\\]')
|
150
|
+
s
|
151
|
+
end
|
95
152
|
end
|
96
153
|
|
97
154
|
extend ClassMethods
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "charwidth"
|
2
|
+
|
3
|
+
module Charwidth
|
4
|
+
module ActiveModel
|
5
|
+
module ClassMethods
|
6
|
+
def normalize_charwidth(*attribute_names)
|
7
|
+
m = Module.new do
|
8
|
+
attribute_names.each do |attribute|
|
9
|
+
define_method "#{attribute}=" do |v|
|
10
|
+
super(v.nil? ? nil : Charwidth.normalize(v.to_s))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
prepend m
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.included(base)
|
19
|
+
base.class_eval do
|
20
|
+
extend ClassMethods
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/charwidth/characters.rb
CHANGED
@@ -10,7 +10,7 @@ module Charwidth
|
|
10
10
|
(0xffc2..0xffc7).to_a,
|
11
11
|
(0xffca..0xffcf).to_a,
|
12
12
|
(0xffd2..0xffd7).to_a,
|
13
|
-
(0xffda..0xffdc).to_a
|
13
|
+
(0xffda..0xffdc).to_a,
|
14
14
|
].flatten.pack("U*").freeze
|
15
15
|
FULLWIDTH_SYMBOL_VARIANTS = (0xffe0..0xffe6).to_a.pack("U*").freeze
|
16
16
|
HALFWIDTH_SYMBOL_VARIANTS = (0xffe8..0xffee).to_a.pack("U*").freeze
|
@@ -39,7 +39,7 @@ module Charwidth
|
|
39
39
|
].flatten.pack("U*").freeze
|
40
40
|
HANGUL = [
|
41
41
|
0x3164, # HANGUL FILLER
|
42
|
-
(0x3131..0x3163).to_a # HANGUL LETTER KIYEOK to I
|
42
|
+
(0x3131..0x3163).to_a, # HANGUL LETTER KIYEOK to I
|
43
43
|
].flatten.pack("U*").freeze
|
44
44
|
LATIN_1_PUNCTUATION_AND_SYMBOLS = [
|
45
45
|
0x00a2, # CENT SIGN
|
@@ -48,33 +48,33 @@ module Charwidth
|
|
48
48
|
0x00af, # MACRON
|
49
49
|
0x00a6, # BROKEN BAR
|
50
50
|
0x00a5, # YEN SIGN
|
51
|
-
0x20a9
|
51
|
+
0x20a9, # WON SIGN
|
52
52
|
].pack("U*").freeze
|
53
53
|
MATHEMATICAL_SYMBOLS = [
|
54
54
|
0x2502, # BOX DRAWINGS LIGHT VERTICAL
|
55
55
|
(0x2190..0x2193).to_a, # LEFTWARDS, UPWARDS, RIGHTWARDS, DOWNWARDS ARROW
|
56
56
|
0x25a0, # BLACK SQUARE
|
57
|
-
0x25cb
|
57
|
+
0x25cb, # WHITE CIRCLE
|
58
58
|
].flatten.pack("U*").freeze
|
59
59
|
SPACE = "\u0020".freeze
|
60
60
|
|
61
|
-
HALFWIDTH_KATAKANA_VOICED_SOUND_MARK = "\uff9e"
|
61
|
+
HALFWIDTH_KATAKANA_VOICED_SOUND_MARK = "\uff9e".freeze
|
62
62
|
HALFWIDTH_VOICED_KATAKANA = [
|
63
63
|
(0xff76..0xff84).to_a, # HALFWIDTH KATAKANA LETTER KA to TO
|
64
64
|
(0xff8a..0xff8e).to_a, # HALFWIDTH KATAKANA LETTER HA to HO
|
65
|
-
0xff73 # HALFWIDTH KATAKANA LETTER U
|
66
|
-
].flatten.map{|k| ([k].pack("U") + HALFWIDTH_KATAKANA_VOICED_SOUND_MARK).freeze }.freeze
|
65
|
+
0xff73, # HALFWIDTH KATAKANA LETTER U
|
66
|
+
].flatten.map {|k| ([k].pack("U") + HALFWIDTH_KATAKANA_VOICED_SOUND_MARK).freeze }.freeze
|
67
67
|
VOICED_KATAKANA = [
|
68
68
|
0x30ac.step(0x30be, 2).to_a, # KATAKANA LETTER GA to ZO
|
69
69
|
[0x30c0, 0x30c2, 0x30c5, 0x30c7, 0x30c9], # KATAKANA LETTER DA to DO
|
70
70
|
0x30d0.step(0x30dc, 3).to_a, # KATAKANA LETTER BA to BO
|
71
|
-
0x30f4 # KATAKANA LETTER VU
|
72
|
-
].flatten.map{|c| [c].pack("U").freeze }.freeze
|
71
|
+
0x30f4, # KATAKANA LETTER VU
|
72
|
+
].flatten.map {|c| [c].pack("U").freeze }.freeze
|
73
73
|
|
74
|
-
HALFWIDTH_KATAKANA_SEMI_VOICED_SOUND_MARK = "\uff9f"
|
74
|
+
HALFWIDTH_KATAKANA_SEMI_VOICED_SOUND_MARK = "\uff9f".freeze
|
75
75
|
HALFWIDTH_SEMI_VOICED_KATAKANA = [
|
76
|
-
(0xff8a..0xff8e).to_a # HALFWIDTH KATAKANA LETTER HA to HO
|
77
|
-
].flatten.map{|k| ([k].pack("U") + HALFWIDTH_KATAKANA_SEMI_VOICED_SOUND_MARK).freeze }.freeze
|
78
|
-
SEMI_VOICED_KATAKANA = 0x30d1.step(0x30dd, 3).map{|c| [c].pack("U").freeze }.flatten.freeze # KATAKANA LETTER PA to PO
|
76
|
+
(0xff8a..0xff8e).to_a, # HALFWIDTH KATAKANA LETTER HA to HO
|
77
|
+
].flatten.map {|k| ([k].pack("U") + HALFWIDTH_KATAKANA_SEMI_VOICED_SOUND_MARK).freeze }.freeze
|
78
|
+
SEMI_VOICED_KATAKANA = 0x30d1.step(0x30dd, 3).map {|c| [c].pack("U").freeze }.flatten.freeze # KATAKANA LETTER PA to PO
|
79
79
|
end
|
80
80
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "optparse"
|
2
|
+
module Charwidth
|
3
|
+
class CLI
|
4
|
+
def self.run(argv)
|
5
|
+
new.run(argv)
|
6
|
+
end
|
7
|
+
|
8
|
+
def run(argv)
|
9
|
+
options = {}
|
10
|
+
optparse = OptionParser.new do |o|
|
11
|
+
o.banner += " TEXT\nNormalize character width in arguments or STDIN.\nAvailable character types are #{Charwidth::ClassMethods::TYPES.join(",")}."
|
12
|
+
o.on("--only=TYPES", "Comma separated character types that should be converted") {|types| options[:only] = types.split(",").map(&:to_sym) }
|
13
|
+
o.on("--except=TYPES", "Comma separated character types that should not be converted") {|types| options[:except] = types.split(",").map(&:to_sym) }
|
14
|
+
o.parse!(argv)
|
15
|
+
end
|
16
|
+
src = nil
|
17
|
+
if ARGV.empty?
|
18
|
+
if $stdin.tty?
|
19
|
+
warn optparse.banner
|
20
|
+
warn optparse.help
|
21
|
+
exit 1
|
22
|
+
else
|
23
|
+
src = $stdin.read
|
24
|
+
end
|
25
|
+
else
|
26
|
+
src = ARGV.join(" ")
|
27
|
+
end
|
28
|
+
print Charwidth.normalize(src, options)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/charwidth/string.rb
CHANGED
data/lib/charwidth/version.rb
CHANGED
metadata
CHANGED
@@ -1,130 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: charwidth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- labocho
|
9
|
-
autorequire:
|
10
|
-
bindir:
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: rspec
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 2.3.0
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 2.3.0
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: bundler
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ~>
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: 1.0.0
|
38
|
-
type: :development
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 1.0.0
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: jeweler
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ~>
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: 1.6.4
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 1.6.4
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: simplecov
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ! '>='
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
70
|
-
type: :development
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ! '>='
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
11
|
+
date: 2021-06-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
78
13
|
description: Normalize Japanese / Korean fullwidth (zenkaku) and halfwidth (hankaku)
|
79
14
|
characters
|
80
|
-
email:
|
81
|
-
|
15
|
+
email:
|
16
|
+
- labocho@penguinlab.jp
|
17
|
+
executables:
|
18
|
+
- charwidth
|
82
19
|
extensions: []
|
83
|
-
extra_rdoc_files:
|
84
|
-
- LICENSE.txt
|
85
|
-
- README.md
|
20
|
+
extra_rdoc_files: []
|
86
21
|
files:
|
87
|
-
- .cleancode
|
88
|
-
- .document
|
89
|
-
- .
|
22
|
+
- ".cleancode"
|
23
|
+
- ".document"
|
24
|
+
- ".gitignore"
|
25
|
+
- ".rspec"
|
26
|
+
- ".rubocop.yml"
|
27
|
+
- CHANGELOG.md
|
90
28
|
- Gemfile
|
91
29
|
- Gemfile.lock
|
92
30
|
- LICENSE.txt
|
93
31
|
- README.md
|
94
32
|
- Rakefile
|
33
|
+
- bin/rspec
|
34
|
+
- bin/rubocop
|
95
35
|
- charwidth.gemspec
|
36
|
+
- exe/charwidth
|
96
37
|
- lib/charwidth.rb
|
38
|
+
- lib/charwidth/active_model.rb
|
97
39
|
- lib/charwidth/characters.rb
|
40
|
+
- lib/charwidth/cli.rb
|
98
41
|
- lib/charwidth/string.rb
|
99
42
|
- lib/charwidth/version.rb
|
100
|
-
|
101
|
-
- spec/spec_helper.rb
|
102
|
-
homepage: http://github.com/labocho/charwidth
|
43
|
+
homepage: https://github.com/labocho/charwidth
|
103
44
|
licenses:
|
104
45
|
- MIT
|
105
|
-
|
46
|
+
metadata:
|
47
|
+
homepage_uri: https://github.com/labocho/charwidth
|
48
|
+
source_code_uri: https://github.com/labocho/charwidth
|
49
|
+
changelog_uri: https://github.com/labocho/charwidth/blob/master/CHANGELOG.md
|
50
|
+
post_install_message:
|
106
51
|
rdoc_options: []
|
107
52
|
require_paths:
|
108
53
|
- lib
|
109
54
|
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
-
none: false
|
111
55
|
requirements:
|
112
|
-
- -
|
56
|
+
- - ">="
|
113
57
|
- !ruby/object:Gem::Version
|
114
|
-
version:
|
115
|
-
segments:
|
116
|
-
- 0
|
117
|
-
hash: -548817087615038840
|
58
|
+
version: 2.4.0
|
118
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
-
none: false
|
120
60
|
requirements:
|
121
|
-
- -
|
61
|
+
- - ">="
|
122
62
|
- !ruby/object:Gem::Version
|
123
63
|
version: '0'
|
124
64
|
requirements: []
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
specification_version: 3
|
65
|
+
rubygems_version: 3.1.2
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
129
68
|
summary: Normalize Japanese / Korean fullwidth (zenkaku) and halfwidth (hankaku) characters
|
130
69
|
test_files: []
|
data/spec/charwidth_spec.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
-
|
4
|
-
describe "Charwidth" do
|
5
|
-
it "should convert full-width alphabet to half-width" do
|
6
|
-
Charwidth.normalize("ABCabc").should == "ABCabc"
|
7
|
-
end
|
8
|
-
it "should convert full-width number to half-width" do
|
9
|
-
Charwidth.normalize("123").should == "123"
|
10
|
-
end
|
11
|
-
it "should convert full-width ASCII symbol before numbers to half-width" do
|
12
|
-
Charwidth.normalize("!"#").should == "!\"#"
|
13
|
-
end
|
14
|
-
it "should convert full-width ASCII symbol between numbers and upper-case to half-width" do
|
15
|
-
Charwidth.normalize(":;").should == ":;"
|
16
|
-
end
|
17
|
-
it "should convert full-width ASCII symbol between upper-case and lower-case to half-width" do
|
18
|
-
Charwidth.normalize("[\]").should == "[\\]"
|
19
|
-
end
|
20
|
-
it "should convert full-width ASCII symbol after lower-case to half-width" do
|
21
|
-
Charwidth.normalize("{|}").should == "{|}"
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should convert half-width CJK punctuation to full-width" do
|
25
|
-
Charwidth.normalize("、。「」").should == "、。「」"
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should convert half-width katakana to full-width" do
|
29
|
-
Charwidth.normalize("アカサタナハマヤラワヲンァャッー・").should == "アカサタナハマヤラワヲンァャッー・"
|
30
|
-
Charwidth.normalize("タチツテトナニヌネノ").should == "タチツテトナニヌネノ"
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should unify half-width (semi) voiced katakana with dakuon to full-width" do
|
34
|
-
Charwidth.normalize("ガザダバパ").should == "ガザダバパ"
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should convert half-width hangul to full-width" do
|
38
|
-
Charwidth.normalize("アカサタナハマヤラワヲンァャッー・").should == "アカサタナハマヤラワヲンァャッー・"
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should convert IDIOGRAPHIC-SPACE to SPACE" do
|
42
|
-
Charwidth.normalize("\u3000").should == " "
|
43
|
-
end
|
44
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
-
require 'rspec'
|
4
|
-
require 'charwidth'
|
5
|
-
|
6
|
-
# Requires supporting files with custom matchers and macros, etc,
|
7
|
-
# in ./support/ and its subdirectories.
|
8
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
-
|
10
|
-
RSpec.configure do |config|
|
11
|
-
|
12
|
-
end
|