bidi布局算法的纯python实现
python-bidi的Python项目详细描述
Bi-directional(bidi)纯python中的布局实现
API
算法从一个入口点开始。
必需参数:
- unicode_or_str:原始Unicode或字符串(即:存储)。如果是绳子 使用可选参数encoding指定其编码。
可选参数:
- encoding:如果unicode_或_str是字符串,则指定编码。这个 算法使用需要unicode的unicodedata。此编码将是 用于在返回之前解码并编码回字符串 (默认值:“UTF-8”)。
- upper_is_rtl:如果为true,则将大写字符视为 调试(默认值:false)。
- base_dir:'l'或'r',覆盖计算的基本级别。
- debug:true显示(使用sys.stderr)使用 算法(默认值:false)。
以Unicode或^{TT2}$编码字符串的形式返回显示布局 (取决于unicode_or_str'的类型)。
示例:
>>> from bidi.algorithm import get_display >>> get_display(u'car is THE CAR in arabic', upper_is_rtl=True) u'car is RAC EHT in arabic'
cli
pybidi是用于运行 bidi算法。脚本可以获取字符串作为参数或从 stdin。用法:
$ pybidi -h Usage: pybidi [options] Options: -h, --help show this help message and exit -e ENCODING, --encoding=ENCODING Text encoding (default: utf-8) -u, --upper-is-rtl treat upper case chars as strong 'R' for debugging (default: False). -d, --debug Output to stderr steps taken with the algorithm -b BASE_DIR, --base-dir=BASE_DIR Override base direction [L|R]
示例:
$ pybidi -u 'car is THE CAR in arabic' car is RAC EHT in arabic $ cat ~/Documents/example.txt | pybidi ...
安装
见docs/INSTALL.rst
运行测试
运行测试:
python setup.py test
一些显式测试正在失败(请参阅TOdo)
0.4.2
- 类型修复,谢谢jwilk
历史
0.4.1
- 混合rtl和数字的合并修复,谢谢van rossum
0.4.0
- 移动到CookiCutter模板
- python 3支持(py2.6、2.7、3.3、3.4和pypy)
- 更好的文档
- 特拉维斯积分
- 毒性试验
- PEP8清除
0.3.4
- 删除控制台脚本输出中的额外换行符
0.3.3
- 实现覆盖基段落方向
- 允许在pybidi控制台脚本中重写基方向
- 修复以相同编码返回显示的问题
0.3.2
- 测试代理项对
- 固定文档中的缩进
- 在setup.py中指定许可证
0.3.1
- 添加了缺少的说明
- docs/install.rst
0.3
- 应用bidi镜像
- 向后移动基于函数的实现
0.2
- 将算法移到基于类的实现中
0.1
- 初始版本