So I am aware that Unicode is not simple... I have been working on a boxes like project http://boxes.thomasjensen.com/

it basically puts a pretty border around stdin characters. like so:
 ________________________
/\                       \
\_|Different all twisty a|
  |of in maze are you,   |
  |passages little.      |
  |   ___________________|_
   \_/_____________________/

but I find that I need to know a bit more than the length of the string because of encoding differences

I had a thought at one point to do this:

MyString.splitlines.map!(a => a.toUTF32.length).reduce!max();

Should get me the longest line.

but this has a problem too because control characters might not take up space (backspace?).

https://en.wikipedia.org/wiki/Unicode_control_characters

leaving an unwanted nasty space :( or take weird amount of space \t. And perhaps the first isn't really something to worry about.

Or should i do something like:

MyString.splitLines
                .map!(a => a
                          .map!(a => a
                                        .isGraphical)
                          .map!(a => cast(int) a?1:0)
                          .array
                          .reduce!((a,b) => a+b))
                .reduce!max

Mostly I am just curious of best practice in this situation.

Both of the above fail with the input:
"hello \n People \nP\u0008ofEARTH"
on my command prompt at least.


Reply via email to