Unicode handle in truncated_name function

1 view
Skip to first unread message

NoSyu

unread,
Jul 4, 2009, 11:19:48 PM7/4/09
to sage-devel
Hello.

I use Sagemath to show the Linear Algebra problems solution.

And I am Korean.

Therefore I write the title in Korean.

http://nosyu.pe.kr/attach/1/5682987737.png


But in worksheet, the title is broken because of truncated_name
function in worksheet.py.


def truncated_name(self, max=30):
name = self.name()
if len(name) > max:
name = name[:max] + ' ...'
return name


But Unicode is not 1 byte by character.

So Korean is broken if max is midpoint of Korean one character.

Therefore I modify the function code like this.


def truncated_name(self, max=30):
name = unicode(self.name(), "utf-8") # name = self.name()
if len(name) > max:
name = name[:max] + ' ...'
return name.encode('utf-8') # return name


Now name is encoded by unicode, then Korean one character's length is
1, not 2 or 3.

So I can see the right title.



I think there are more good choice to solve the problem.

Because I don't know about Python well and unicode also.

So I suggest this.

------------------------------------------------------------------------

누구나가 다, 자기 옆에서 눈물을 흘리며 신음하는 불행한 사람들에 비해 자기가 훨씬 더 불행하다고 생각하지요. 이게 바로 우리
가련한 인간들의 오만 중 하나입니다.

- 몬테크리스토 백작

it is the infirmity of our nature always to believe ourselves much
more unhappy than those who groan by our sides!

- The Count of Monte Cristo

c'est un des orgueils de notre pauvre humanit?, que chaque homme se
croie plus malheureux qu'un autre malheureux qui pleure et qui g?mit ?
c?t? de lui

- Le Comte de Monte-Cristo



박진영 - Bak JinYeong

학부재학생 - Undergraduate

컴퓨터공학전공 - Department of Computer Engineering

정보통신공학부 - School of Information & Communication Engineering

성균관대학교 - SungKyunKwan University

블로그 - http://nosyu.pe.kr

이메일 - don...@skku.edu

William Stein

unread,
Jul 7, 2009, 9:44:30 PM7/7/09
to sage-...@googlegroups.com
2009/7/4 NoSyu <don...@gmail.com>:

Thanks. This is now http://trac.sagemath.org/sage_trac/ticket/6477

William

Reply all
Reply to author
Forward
0 new messages