Skip to content

Commit

Permalink
Add Python 3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
fgallaire committed Sep 5, 2016
1 parent 15ae01b commit 80e27d2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cjkwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@

import textwrap
import unicodedata
import sys

PY3 = sys.version[0] == '3'

if PY3:
text_type = str
else:
text_type = unicode


def cjklen(text):
Expand All @@ -35,7 +43,7 @@ def cjklen(text):
Return the real width of a text.
Fullwidth and Wide CJK chars are double-width.
"""
if not isinstance(text, unicode):
if not isinstance(text, text_type):
return len(text)
l = 0
for char in text:
Expand All @@ -51,7 +59,7 @@ def cjkslices(text, index):
Return the two slices of a text cut to the index.
"""
if not isinstance(text, unicode):
if not isinstance(text, text_type):
return text[:index], text[index:]
if cjklen(text) <= index:
return text, u''
Expand Down

0 comments on commit 80e27d2

Please sign in to comment.