Skip to content
This repository


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…


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


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 the gem with

gem install unicode-display_width


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 © 2011 Jan Lelis,, released under the MIT license.

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

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


Something went wrong with that request. Please try again.