Giter Site home page Giter Site logo

pyjft's People

Watchers

 avatar

pyjft's Issues

修改了j2f函数,可以把混合了英文字母,数字,特殊字符等和简体中文混排的字符串转成繁体字符串。

您好,我修改了一下 j2f 
简体转繁体的函数,基本上可以实现带有字符,逗号,英
文,数字等特殊符合和中文简体混排的内容也可以正常的转��
�成繁体字符串。 下面的
代码供您参考。

def _j2f(nc, destinationEncoding):
    pos = jt.find(nc)
    while pos>0:
        if pos%2 == 0:
            return unicode(ft[pos:pos+2],'gbk').encode(destinationEncoding)
            break
        pos = jt.find(nc,pos+1)
    return None



def j2f(sourceEncoding,destinationEncoding,sourceString):
    '''
    Simplified Chinese character to traditional Chinese character converter

    Parameters:
        sourceEncoding : The encoding codec name of string to be converted
        destinationEncoding : The encoding codec name of output string
        sourceString : The string to be converted

    Return value:
        The output traditional Chinese character string
    '''
    des = []
    nString = unicode(sourceString,sourceEncoding).encode('gbk')
    #print nString
    sLen = len(nString)
    i = 0
    while i < sLen:
        nc = nString[i:i+2]
        fnc = _j2f(nc,destinationEncoding)
        if fnc:
            des.append(fnc)
            i += 2
        else:
            des.append(nString[i:i+1])
            i += 1

    return ''.join(des)


其他部分都不用改变。
联系人:lidongok # gmail.com

Original issue reported on code.google.com by [email protected] on 1 Dec 2009 at 7:50

Attachments:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.