Determines the monospace display width of a string in Ruby. Implementation inspired by unicode-display_width and based on http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c from the University of Cambridge.
Add the line below to your build_config.rb
:
MRuby::Build.new do |conf|
# ... (snip) ...
conf.gem 'mruby-unicode-display_width'
end
Or add this line to your aplication's mrbgem.rake
:
MRuby::Gem::Specification.new('your-mrbgem') do |spec|
# ... (snip) ...
spec.add_dependency 'mruby-unicode-display_width'
end
The interace follows unicode-display_width. However custom overwrites nor the 2nd parameter for ambiguous values aren't supported.
Unicode::DisplayWidth.of("⚀") # => 1
Unicode::DisplayWidth.of("一") # => 2
With String Extension:
'⚀'.display_width #=> 1
'一'.display_width #=> 2
Clone the repo:
$ git clone https://github.com/katzer/mruby-unicode-display_width.git && cd mruby-unicode-display_width/
Compile the source:
$ rake compile
Run the tests:
$ rake test
Bug reports and pull requests are welcome on GitHub at https://github.com/katzer/mruby-unicode-display_width.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
The gem is available as open source under the terms of the MIT License.
Made with 😋 in Leipzig
© 2017 Sebastián Katzer