This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
j2a.py
66 lines (55 loc) · 1.84 KB
/
j2a.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
# j2a.py
#
# Copyright 2011,2014 Hiroshi Miura <miurahr@linux.com>
#
# Original Copyright:
# * KAKASI (Kanji Kana Simple inversion program)
# * $Id: jj2.c,v 1.7 2001-04-12 05:57:34 rug Exp $
# * Copyright (C) 1992
# * Hironobu Takahashi (takahasi@tiny.or.jp)
# *
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
# * the Free Software Foundation; either versions 2, or (at your option)
# * any later version.
# *
# * This program is distributed in the hope that it will be useful
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
# * You should have received a copy of the GNU General Public License
# * along with KAKASI, see the file COPYING. If not, write to the Free
# * Software Foundation Inc., 59 Temple Place - Suite 330, Boston, MA
# * 02111-1307, USA.
# */
import re
class J2a (object):
_jconv = None
_hconv = None
def __init__(self, method="Hepburn"):
from .j2h import J2H
from .h2a import H2a
self._jconv = J2H()
self._hconv = H2a(method)
def isRegion(self, char):
return self._jconv.isRegion(char)
def convert(self, text):
if not self._jconv.isRegion(text[0]):
return ("", 0)
(t, l) = self._jconv.convert(text)
if l <= 0: # pragma: no cover
return ("", 0)
m = 0
otext = ""
while True:
if m >= len(t):
break
(s, n) = self._hconv.convert(t[m:])
if n <= 0: # pragma: no cover
m = m + 1
else:
m = m + n
otext = otext+s
return (otext, l)