Blame ibus/utility.py

Packit 3ff832
# vim:set et sts=4 sw=4:
Packit 3ff832
#
Packit 3ff832
# ibus - The Input Bus
Packit 3ff832
#
Packit 3ff832
# Copyright (c) 2007-2010 Peng Huang <shawn.p.huang@gmail.com>
Packit 3ff832
# Copyright (c) 2007-2010 Red Hat, Inc.
Packit 3ff832
#
Packit 3ff832
# This library is free software; you can redistribute it and/or
Packit 3ff832
# modify it under the terms of the GNU Lesser General Public
Packit 3ff832
# License as published by the Free Software Foundation; either
Packit 3ff832
# version 2.1 of the License, or (at your option) any later version.
Packit 3ff832
#
Packit 3ff832
# This library is distributed in the hope that it will be useful,
Packit 3ff832
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 3ff832
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 3ff832
# Lesser General Public License for more details.
Packit 3ff832
#
Packit 3ff832
# You should have received a copy of the GNU Lesser General Public
Packit 3ff832
# License along with this library; if not, write to the Free Software
Packit 3ff832
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
Packit 3ff832
# USA
Packit 3ff832
Packit 3ff832
__all__ = (
Packit 3ff832
        "unichar_half_to_full",
Packit 3ff832
        "unichar_full_to_half"
Packit 3ff832
    )
Packit 3ff832
Packit 3ff832
__half_full_table = [
Packit 3ff832
    (0x0020, 0x3000, 1),
Packit 3ff832
    (0x0021, 0xFF01, 0x5E),
Packit 3ff832
    (0x00A2, 0xFFE0, 2),
Packit 3ff832
    (0x00A5, 0xFFE5, 1),
Packit 3ff832
    (0x00A6, 0xFFE4, 1),
Packit 3ff832
    (0x00AC, 0xFFE2, 1),
Packit 3ff832
    (0x00AF, 0xFFE3, 1),
Packit 3ff832
    (0x20A9, 0xFFE6, 1),
Packit 3ff832
    (0xFF61, 0x3002, 1),
Packit 3ff832
    (0xFF62, 0x300C, 2),
Packit 3ff832
    (0xFF64, 0x3001, 1),
Packit 3ff832
    (0xFF65, 0x30FB, 1),
Packit 3ff832
    (0xFF66, 0x30F2, 1),
Packit 3ff832
    (0xFF67, 0x30A1, 1),
Packit 3ff832
    (0xFF68, 0x30A3, 1),
Packit 3ff832
    (0xFF69, 0x30A5, 1),
Packit 3ff832
    (0xFF6A, 0x30A7, 1),
Packit 3ff832
    (0xFF6B, 0x30A9, 1),
Packit 3ff832
    (0xFF6C, 0x30E3, 1),
Packit 3ff832
    (0xFF6D, 0x30E5, 1),
Packit 3ff832
    (0xFF6E, 0x30E7, 1),
Packit 3ff832
    (0xFF6F, 0x30C3, 1),
Packit 3ff832
    (0xFF70, 0x30FC, 1),
Packit 3ff832
    (0xFF71, 0x30A2, 1),
Packit 3ff832
    (0xFF72, 0x30A4, 1),
Packit 3ff832
    (0xFF73, 0x30A6, 1),
Packit 3ff832
    (0xFF74, 0x30A8, 1),
Packit 3ff832
    (0xFF75, 0x30AA, 2),
Packit 3ff832
    (0xFF77, 0x30AD, 1),
Packit 3ff832
    (0xFF78, 0x30AF, 1),
Packit 3ff832
    (0xFF79, 0x30B1, 1),
Packit 3ff832
    (0xFF7A, 0x30B3, 1),
Packit 3ff832
    (0xFF7B, 0x30B5, 1),
Packit 3ff832
    (0xFF7C, 0x30B7, 1),
Packit 3ff832
    (0xFF7D, 0x30B9, 1),
Packit 3ff832
    (0xFF7E, 0x30BB, 1),
Packit 3ff832
    (0xFF7F, 0x30BD, 1),
Packit 3ff832
    (0xFF80, 0x30BF, 1),
Packit 3ff832
    (0xFF81, 0x30C1, 1),
Packit 3ff832
    (0xFF82, 0x30C4, 1),
Packit 3ff832
    (0xFF83, 0x30C6, 1),
Packit 3ff832
    (0xFF84, 0x30C8, 1),
Packit 3ff832
    (0xFF85, 0x30CA, 6),
Packit 3ff832
    (0xFF8B, 0x30D2, 1),
Packit 3ff832
    (0xFF8C, 0x30D5, 1),
Packit 3ff832
    (0xFF8D, 0x30D8, 1),
Packit 3ff832
    (0xFF8E, 0x30DB, 1),
Packit 3ff832
    (0xFF8F, 0x30DE, 5),
Packit 3ff832
    (0xFF94, 0x30E4, 1),
Packit 3ff832
    (0xFF95, 0x30E6, 1),
Packit 3ff832
    (0xFF96, 0x30E8, 6),
Packit 3ff832
    (0xFF9C, 0x30EF, 1),
Packit 3ff832
    (0xFF9D, 0x30F3, 1),
Packit 3ff832
    (0xFFA0, 0x3164, 1),
Packit 3ff832
    (0xFFA1, 0x3131, 30),
Packit 3ff832
    (0xFFC2, 0x314F, 6),
Packit 3ff832
    (0xFFCA, 0x3155, 6),
Packit 3ff832
    (0xFFD2, 0x315B, 9),
Packit 3ff832
    (0xFFE9, 0x2190, 4),
Packit 3ff832
    (0xFFED, 0x25A0, 1),
Packit 3ff832
    (0xFFEE, 0x25CB, 1)]
Packit 3ff832
Packit 3ff832
def unichar_half_to_full (c):
Packit 3ff832
    code = ord (c)
Packit 3ff832
    for half, full, size in __half_full_table:
Packit 3ff832
        if code >= half and code < half + size:
Packit 3ff832
            return unichr (full + code - half)
Packit 3ff832
    return c
Packit 3ff832
Packit 3ff832
def unichar_full_to_half (c):
Packit 3ff832
    code = ord (c)
Packit 3ff832
    for half, full, size in __half_full_table:
Packit 3ff832
        if code >= full and code < full + size:
Packit 3ff832
            return unichr (half + code - full)
Packit 3ff832
    return c
Packit 3ff832