Method: UnicodeUtils.debug
- Defined in:
- lib/unicode_utils/debug.rb
.debug(str, opts = {}) ⇒ Object
Print a table with detailed information about each code point in str. opts can have the following keys:
:io-
An IO compatible object. Receives the output. Defaults to
$stdout.
str may also be an Integer, in which case it is interpreted as a single code point that must be in UnicodeUtils::Codepoint::RANGE.
Examples:
$ ruby -r unicode_utils/u -e 'U.debug "良い一日"'
Char | Ordinal | Sid | General Category | UTF-8
------+---------+----------------------------+------------------+----------
"良" | 826F | CJK UNIFIED IDEOGRAPH-826F | Other_Letter | E8 89 AF
"い" | 3044 | HIRAGANA LETTER I | Other_Letter | E3 81 84
"一" | 4E00 | CJK UNIFIED IDEOGRAPH-4E00 | Other_Letter | E4 B8 80
"日" | 65E5 | CJK UNIFIED IDEOGRAPH-65E5 | Other_Letter | E6 97 A5
$ ruby -r unicode_utils/u -e 'U.debug 0xd800'
Char | Ordinal | Sid | General Category | UTF-8
------+---------+------------------+------------------+-------
N/A | D800 | <surrogate-D800> | Surrogate | N/A
The output is purely informal and may change even in minor releases.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/unicode_utils/debug.rb', line 37 def debug(str, opts = {}) io = opts[:io] || $stdout table = [Impl::DEBUG_COLUMNS.keys] if str.kind_of?(Integer) table << Impl::DEBUG_COLUMNS.values.map { |f| f.call(str) } else str.each_codepoint { |cp| table << Impl::DEBUG_COLUMNS.values.map { |f| f.call(cp) } } end Impl.print_table(table, io) nil end |