Python library to make and get the encoding of unicode code points in UTF8.
Design UTF-8 can be seen in the following table that originally proposed by Dave Prosser and subsequently modified by Ken Thompson. You can read more on the table above in https://en.wikipedia.org/wiki/UTF-
Bit Code Point | The first code point | The last code point | Byte In sequence |
---|---|---|---|
7 | U+0000 | U+007F | 1 |
11 | U+0080 | U+07FF | 2 |
16 | U+0800 | U+FFFF | 3 |
21 | U+10000 | U+1FFFFF | 4 |
26 | U+200000 | U+3FFFFFF | 5 |
31 | U+4000000 | U+7FFFFFFF | 6 |
$ pip install utf8_codepoint
simple examples using this package.
from utf8_codepoint import CodePoint
# unicode symbol for European currency
euro_money = "U+20AC"
# create instance object
cp = CodePoint(euro_money)
# get representation integer of the Unicode Code Point
print(cp.to_int())
the result is:
226 130 172
from utf8_codepoint import CodePoint
...
print(cp.to_hex())
the result is:
E2 82 AC
from utf8_codepoint import CodePoint
...
print(cp.to_string())
the result is:
11100010 10000010 10101100
from utf8_codepoint import CodePoint
...
print(cp.to_list())
the result is:
['11100010', '10000010', '10101100']
from utf8_codepoint import CodePoint
...
cp.bprint()
the result is:
{'0x20AC': {'bit_list': ['11100010', '10000010', '10101100'],
'code_point': 16,
'hexa_list': ['0xe2', '0x82', '0xac'],
'initial_bit': '1110',
'integer_list': [226, 130, 172]}}
Get all data
from utf8_codepoint import CodePoint
...
print(cp.get_all())
the result is:
{'0x20AC':
{
'bit_list': ['11100010', '10000010', '10101100'],
'integer_list': [226, 130, 172],
'initial_bit': '1110',
'hexa_list': ['0xe2', '0x82', '0xac'],
'code_point': 16
}
}
If you want to turn it into a json format, you can pass a true value as a parameter in the method get_all:
cp.get_all(True)
build with love, provide with sincerity.
Copyright (c) 2015 Yanwar Solahudin
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall
be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
sIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.