PageRenderTime 31ms CodeModel.GetById 16ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/python/scim/Utility.py

http://scim-python.googlecode.com/
Python | 102 lines | 74 code | 3 blank | 25 comment | 8 complexity | d14945e96c5f6c09aea4320325b0db09 MD5 | raw file
  1# -*- coding: utf-8 -*-
  2# vim:set noet ts=4:
  3#
  4# scim-python
  5#
  6# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
  7#
  8#
  9# This library is free software; you can redistribute it and/or
 10# modify it under the terms of the GNU Lesser General Public
 11# License as published by the Free Software Foundation; either
 12# version 2 of the License, or (at your option) any later version.
 13#
 14# This library is distributed in the hope that it will be useful,
 15# but WITHOUT ANY WARRANTY; without even the implied warranty of
 16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 17# GNU Lesser General Public License for more details.
 18#
 19# You should have received a copy of the GNU Lesser General Public
 20# License along with this program; if not, write to the
 21# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 22# Boston, MA  02111-1307  USA
 23#
 24# $Id: $
 25#
 26__half_full_table = [
 27    (0x0020, 0x3000, 1),
 28    (0x0021, 0xFF01, 0x5E),
 29    (0x00A2, 0xFFE0, 2),
 30    (0x00A5, 0xFFE5, 1),
 31    (0x00A6, 0xFFE4, 1),
 32    (0x00AC, 0xFFE2, 1),
 33    (0x00AF, 0xFFE3, 1),
 34    (0x20A9, 0xFFE6, 1),
 35    (0xFF61, 0x3002, 1),
 36    (0xFF62, 0x300C, 2),
 37    (0xFF64, 0x3001, 1),
 38    (0xFF65, 0x30FB, 1),
 39    (0xFF66, 0x30F2, 1),
 40    (0xFF67, 0x30A1, 1),
 41    (0xFF68, 0x30A3, 1),
 42    (0xFF69, 0x30A5, 1),
 43    (0xFF6A, 0x30A7, 1),
 44    (0xFF6B, 0x30A9, 1),
 45    (0xFF6C, 0x30E3, 1),
 46    (0xFF6D, 0x30E5, 1),
 47    (0xFF6E, 0x30E7, 1),
 48    (0xFF6F, 0x30C3, 1),
 49    (0xFF70, 0x30FC, 1),
 50    (0xFF71, 0x30A2, 1),
 51    (0xFF72, 0x30A4, 1),
 52    (0xFF73, 0x30A6, 1),
 53    (0xFF74, 0x30A8, 1),
 54    (0xFF75, 0x30AA, 2),
 55    (0xFF77, 0x30AD, 1),
 56    (0xFF78, 0x30AF, 1),
 57    (0xFF79, 0x30B1, 1),
 58    (0xFF7A, 0x30B3, 1),
 59    (0xFF7B, 0x30B5, 1),
 60    (0xFF7C, 0x30B7, 1),
 61    (0xFF7D, 0x30B9, 1),
 62    (0xFF7E, 0x30BB, 1),
 63    (0xFF7F, 0x30BD, 1),
 64    (0xFF80, 0x30BF, 1),
 65    (0xFF81, 0x30C1, 1),
 66    (0xFF82, 0x30C4, 1),
 67    (0xFF83, 0x30C6, 1),
 68    (0xFF84, 0x30C8, 1),
 69    (0xFF85, 0x30CA, 6),
 70    (0xFF8B, 0x30D2, 1),
 71    (0xFF8C, 0x30D5, 1),
 72    (0xFF8D, 0x30D8, 1),
 73    (0xFF8E, 0x30DB, 1),
 74    (0xFF8F, 0x30DE, 5),
 75    (0xFF94, 0x30E4, 1),
 76    (0xFF95, 0x30E6, 1),
 77    (0xFF96, 0x30E8, 6),
 78    (0xFF9C, 0x30EF, 1),
 79    (0xFF9D, 0x30F3, 1),
 80    (0xFFA0, 0x3164, 1),
 81    (0xFFA1, 0x3131, 30),
 82    (0xFFC2, 0x314F, 6),
 83    (0xFFCA, 0x3155, 6),
 84    (0xFFD2, 0x315B, 9),
 85    (0xFFE9, 0x2190, 4),
 86    (0xFFED, 0x25A0, 1),
 87    (0xFFEE, 0x25CB, 1)]
 88
 89def unichar_half_to_full (c):
 90	code = ord (c)
 91	for half, full, size in __half_full_table:
 92		if code >= half and code < half + size:
 93			return unichr (full + code - half)
 94	return c
 95
 96def unichar_full_to_falf (c):
 97	code = ord (c)
 98	for half, full, size in __half_full_table:
 99		if code >= full and code < full + size:
100			return unichr (half + code - full)
101	return c
102