unibits
Ruby library and CLI command that visualizes various Unicode and ASCII encodings in the terminal.
Helps you debugging and learning about Unicode encodings.
Supported encodings: UTF-8, UTF-16LE, UTF-16BE, UTF-32LE, UTF-32BE, BINARY, ASCII
Setup
$ gem install unibits
Usage
From CLI
$ unibits "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪"
From Ruby
require 'unibits/kernel_method'
unibits "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪"
Options
unibits
takes three optional options:
- encoding (e): The encoding of the given string (uses your default encoding if none given)
- convert (c): An encoding the string should be converted to before visualizing it
- stats: Whether to show a short stats header (default:
true
), you can deactivate on the CLI with--no-stats
Please note: This uses Ruby's built-in encoding support. Currently, only strings with valid encodings are supported.
Output for Different Encodings
UTF-8
CLI: $ unibits -e utf-8 -c utf-8 "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪"
Ruby: unibits "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪", encoding: 'utf-8', convert: 'utf-8'
UTF-16LE
CLI: $ unibits -e utf-8 -c utf-8 "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪"
Ruby: unibits "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪", encoding: 'utf-8', convert: 'utf-8'
UTF-16BE
CLI: $ unibits -e utf-8 -c utf-8 "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪"
Ruby: unibits "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪", encoding: 'utf-8', convert: 'utf-8'
UTF-32LE
CLI: $ unibits -e utf-8 -c utf-8 "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪"
Ruby: unibits "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪", encoding: 'utf-8', convert: 'utf-8'
UTF-32BE
CLI: $ unibits -e utf-8 -c utf-8 "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪"
Ruby: unibits "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪", encoding: 'utf-8', convert: 'utf-8'
BINARY
CLI: $ unibits -e binary "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪"
Ruby: unibits "馃尗 Idio锘縮yncr盲tic 鈩溦结柉蕪", encoding: 'binary'
ASCII
CLI: $ unibits -e utf-8 -c ascii "ascii"
Ruby: unibits "ASCII String", encoding: 'utf-8', convert: 'ascii'
Notes
Also see
- UTF-8 (Wikipedia)
- UTF-16 (Wikipedia)
- UTF-32 (Wikipedia)
- Ruby's Encoding class
- Unicode Micro Libraries for Ruby
Lots of thanks to @damienklinnert for the motivation and inspiration required to build this! 馃巻
Copyright (C) 2017 Jan Lelis http://janlelis.com. Released under the MIT license.