~stub/ubuntu/precise/calibre/devel

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/unihandecode/pykakasi/k2a.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-04-12 11:29:25 UTC
  • mfrom: (42.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110412112925-c7171kt2bb5rmft4
Tags: 0.7.50+dfsg-2
* debian/control: Build with libpodofo-dev to enable PDF metadata.
  (Closes: #619632)
* debian/control: Add libboost1.42-dev build dependency. Apparently it is
  needed in some setups. (Closes: #619807)
* debian/rules: Call dh_sip to generate a proper sip API dependency, to
  prevent crashes like #616372 for partial upgrades.
* debian/control: Bump python-qt4 dependency to >= 4.8.3-2, which reportedly
  fixes crashes on startup. (Closes: #619701, #620125)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#  k2a.py
 
3
#
 
4
# Copyright 2011 Hiroshi Miura <miurahr@linux.com>
 
5
#
 
6
# Original copyright:
 
7
# * KAKASI (Kanji Kana Simple inversion program)
 
8
# * $Id: jj2.c,v 1.7 2001-04-12 05:57:34 rug Exp $
 
9
# * Copyright (C) 1992
 
10
# * Hironobu Takahashi (takahasi@tiny.or.jp)
 
11
# *
 
12
# * This program is free software; you can redistribute it and/or modify
 
13
# * it under the terms of the GNU General Public License as published by
 
14
# * the Free Software Foundation; either versions 2, or (at your option)
 
15
# * any later version.
 
16
# *
 
17
# * This program is distributed in the hope that it will be useful
 
18
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
# * GNU General Public License for more details.
 
21
# *
 
22
# * You should have received a copy of the GNU General Public License
 
23
# * along with KAKASI, see the file COPYING.  If not, write to the Free
 
24
# * Software Foundation Inc., 59 Temple Place - Suite 330, Boston, MA
 
25
# * 02111-1307, USA.
 
26
# */
 
27
 
 
28
from calibre.ebooks.unihandecode.pykakasi.jisyo import jisyo
 
29
 
 
30
class K2a (object):
 
31
 
 
32
    kanwa = None
 
33
 
 
34
    def __init__(self):
 
35
        self.kanwa = jisyo()
 
36
 
 
37
    def isKatakana(self, char):
 
38
        return ( 0x30a0 < ord(char) and ord(char) < 0x30f7)
 
39
 
 
40
    def convert(self, text):
 
41
        Hstr = ""
 
42
        max_len = -1
 
43
        r = min(10, len(text)+1)
 
44
        for x in xrange(r):
 
45
            if text[:x] in self.kanwa.kanadict:
 
46
                if max_len < x:
 
47
                    max_len = x
 
48
                    Hstr = self.kanwa.kanadict[text[:x]]
 
49
        return (Hstr, max_len) 
 
50