Created
August 25, 2016 21:45
-
-
Save thieux/d22374521e30d2f41366bd145fcf7efc to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# Validates utf-8 input | |
function uu() { | |
iconv --from-code=utf-8 --to-code=utf-8 | |
} | |
# Converts UTF-8 -> ISO-8859-1 | |
function ui() { | |
iconv --from-code=utf-8 --to-code=iso-8859-1 | |
} | |
# Converts ISO-8859-1 -> UTF-8 | |
function iu() { | |
iconv --from-code=iso-8859-1 --to-code=utf-8 | |
} | |
# All that follows assume a unicode environment | |
if [[ 'fr_FR.UTF-8' != $LANG ]]; then | |
exit 1 | |
fi | |
echo UTF-8 encoding | |
echo -n é | uu | hexdump | |
echo ISO-8859-1 encoding | |
echo -n é | uu | ui | hexdump | |
echo Identity | |
echo -n é | ui | iu | hexdump | |
echo Misinterpret UTF-8 bytes as ISO-8859-1 | |
echo -n é | iu | hexdump # 'é' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment