Created
April 12, 2021 17:24
-
-
Save alecjacobson/b9ace772006a923b680d0d0095c8090a to your computer and use it in GitHub Desktop.
Convert ascii text from standard input into fixed-width unicode characters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# Convert ascii text from standard input into fixed-width unicode characters. | |
# | |
# http://xahlee.info/comp/unicode_full-width_chars.html | |
fixedWidth = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,.:;!?"'`^~ ̄_&@#%+-*=<>()[]{}⦅⦆|¦/\¬$£¢₩¥ ' | |
ascii = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,.:;!?"\'`^~‾_&@#%+-*=<>()[]{}«»|¦/\\¬$£¢₩¥ ' | |
input = STDIN.read | |
output = input.split('').map do |c| | |
i = ascii.index(c) | |
i.nil? ? c : fixedWidth[i] | |
end | |
puts output.join('') | |
yig
commented
Apr 12, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment