Skip to content

Commit

Permalink
minor code tunes
Browse files Browse the repository at this point in the history
  • Loading branch information
lxyu committed Jan 4, 2016
1 parent ad4a6a4 commit f4ea236
Showing 5 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@ python:
- 2.7
- 3.2
- 3.3
- 3.4
- 3.5
- pypy
install:
- pip install .
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014, Lx Yu
Copyright (c) 2016, Lx Yu

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -37,3 +37,7 @@ Usage
>>> print pinyin.get_initial('你好')
n h
.. note::

`format` must be one of: numerical/diacritical/strip
8 changes: 5 additions & 3 deletions pinyin/pinyin.py
Original file line number Diff line number Diff line change
@@ -29,18 +29,20 @@ def _pinyin_generator(chars, format):
key = "%X" % ord(char)
pinyin = pinyin_dict.get(key, char)
tone = pinyin_tone.get(key, 0)
if tone == 0:

if tone == 0 or format == "strip":
pass
elif format == "numerical":
pinyin = pinyin + str(tone)
pinyin += str(tone)
elif format == "diacritical":
# Find first vowel -- we should put the diacritical mark
# just after
vowel = pinyin.index(next(x for x in pinyin if x in "aeiou")) + 1
pinyin = pinyin[:vowel] + tonemarks[tone] + pinyin[vowel:]
elif format != "strip":
else:
error = "Format must be one of: numerical/diacritical/strip"
raise ValueError(error)

yield unicodedata.normalize('NFC', pinyin)


19 changes: 18 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from distutils.core import setup
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from setuptools import setup

setup(
name='pinyin',
@@ -12,4 +15,18 @@
url='http://lxyu.github.io/pinyin/',
license="BSD",
long_description=open('README.rst').read(),
classifiers=[
"Topic :: Software Development",
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
)

0 comments on commit f4ea236

Please sign in to comment.