Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

This gem adds String#display_size to get the display size of a string using EastAsianWidth.txt.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 data
Octocat-spinner-32 lib
Octocat-spinner-32 .gemspec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE.txt
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
README.rdoc

Description

An early draft of a way to determine the size of the characters using EastAsianWidth.txt, based on the very early draft of a Ruby interface to UnicodeData.txt by runpaint.

Install

Install the gem with

gem install unicode-display_width

Usage

require 'unicode/display_width'

The easy way is to use the String#display_size method:

"⚀".display_width #=> 1
'一'.display_width #=> 2

To obtain more detailed data, you can use the following syntax:

Unicode::DiplayWidth.codepoint( c )

Bugs / TODO

Since it is not tested extensively, it does probably not work correctly for all characters… For example, there is a class of unicode characters, which is not exactly defined to be narrow or full-width (“ambiguous”). This gem currently gives them a size of 1, which is not always correct.

Furthermore, the index data structure can be improved.

Copyright

Copyright © 2011 Jan Lelis, rbjl.net, released under the MIT license.

Contains code by runpaint: Copyright © 2009 Run Paint Run Run

Contains EastAsianWidth.txt: Copyright © 1991-2010 Unicode, Inc.

J-_-L

Something went wrong with that request. Please try again.