Skip to content

Commit

Permalink
More robust conversion to unicode
Browse files Browse the repository at this point in the history
Fixes #72.
  • Loading branch information
jessevdk committed Dec 1, 2014
1 parent d0fa020 commit f4da1a2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cldoc/utf8.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
def makeutf8(s):
if not isinstance(s, unicode):
if hasattr(s, '__unicode__'):
return unicode(s)
if isinstance(s, str) or isinstance(s, buffer):
return unicode(s, 'utf-8')
else:
return unicode(s)

return str(s).decode('utf-8')

Expand All @@ -25,8 +28,8 @@ def makeutf8(s):
string = basecls

class utf8(string):
def __init__(self, s):
super(utf8, self).__init__(makeutf8(s))
def __new__(cls, s):
return super(utf8, cls).__new__(cls, makeutf8(s))

def __str__(self):
if not isinstance(self, str):
Expand Down
4 changes: 4 additions & 0 deletions tests/input/utf8.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Copyright © */
class A
{
};
4 changes: 4 additions & 0 deletions tests/output/utf8-A.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version='1.0' encoding='utf-8'?>
<class id="A" name="A" xmlns="http://jessevdk.github.com/cldoc/1.0">
<brief>Copyright ©</brief>
</class>
6 changes: 6 additions & 0 deletions tests/output/utf8-index.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='utf-8'?>
<index xmlns="http://jessevdk.github.com/cldoc/1.0">
<class name="A" ref="A#A">
<brief>Copyright ©</brief>
</class>
</index>

0 comments on commit f4da1a2

Please sign in to comment.