blackwinter / unicode

Unicode normalization library. (Mirror of Yoshida-san's code base to maintain the RubyGem.)
http://www.yoshidam.net/Ruby.html#unicode
79 stars 13 forks source link

Some strings return -1 width #6

Closed gauteh closed 10 years ago

gauteh commented 10 years ago

Hi, we had some issues in sup (https://github.com/sup-heliotrope/sup/issues/157) and it turns out that Unicode.width returns -1 for some strings (https://github.com/sup-heliotrope/sup/pull/256), example (ruby 1.9.3):

> require 'unicode'
> a = 'This is =91 a test: the first line seems to disappear from the mail body but is
still visible in the thread view.'
> Unicode.width a
=> -1
> a.length
=> 113
blackwinter commented 10 years ago

it's caused by the newline. what display width would you expect a multi-line string to have? you could argue that it should be the maximum width of all lines, but then again the specification for wcswidth states that it should return -1 as soon as it encounters a control character.

so i think, whatever it is you actually need, is application specific and should be handled in sup itself.

gauteh commented 10 years ago

Sounds fair, thanks for the explanation.