-
Notifications
You must be signed in to change notification settings - Fork 2
/
utf8.functions
28 lines (24 loc) · 1.41 KB
/
utf8.functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# This file is part of shellfire unicode. It is subject to the licence terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/shellfire-dev/unicode/master/COPYRIGHT. No part of shellfire unicode, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
# Copyright © 2014-2015 The developers of shellfire unicode. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/shellfire-dev/unicode/master/COPYRIGHT.
core_usesIn unicode
unicode_utf8_encodeCodePoint()
{
local codePoint=$(($1+0))
if [ $codePoint -le 127 ]; then
_unicode_writeByte $codePoint
elif [ $codePoint -le 2047 ]; then
_unicode_writeByte $(((codePoint >> 6) + 192))
_unicode_writeByte $(((codePoint & 63) + 128))
elif [ $codePoint -le 65535 ]; then
_unicode_writeByte $(((codePoint >> 12) + 224))
_unicode_writeByte $((((codePoint >> 6) & 63) + 128))
_unicode_writeByte $(((codePoint & 63) + 128))
elif [ $codePoint -le 1114111 ]; then
_unicode_writeByte $(((codePoint >> 18) + 240))
_unicode_writeByte $((((codePoint >> 12) & 63) + 128))
_unicode_writeByte $((((codePoint >> 6) & 63) + 128))
_unicode_writeByte $(((codePoint & 63) + 128))
else
core_exitError $core_commandLine_exitCode_SOFTWARE "Invalid code point"
fi
}