S
stefoid
Hi. Ive got a problem. I have some code that takes a text file and
breaks it into an array of substrings for displaying the text truncated
to fit the screen width on word boundaries.
It just looks for the spaces.
trouble is, it crashes out with japenese text. There is a part of the
code that looks at the next character to see if it is a space:
ch = str.substring(offset, offset + 1);
isSpace = false;
// return when a new line is reached
if (ch.equals("\n"))
return offset+1;
currentWidth += font.stringWidth(ch);
if (ch.equals(" "))
isSpace = true;
and if it isnt a space, it adds the width of the character (in pixels)
, and keeps going until it does find a space.
the problem with this is it assumes that each byte is a characater. In
utf8, up to 3 bytes could be one character, so this code is trying to
find the widths of characters representing each byte in a utf8
sequence, rather than the width of the utf8 character as a whole.
my additional problem is this is iAppli code, so I am limited to a 30K
codebase, and I have hit the limit, so I cant write any more lines of
code - I just have to change the existing code such that it doesnt
generate any more bytecode.
what can I do to the above code so that I can count widths of utf8
characters instead of asc characters, without writing too much extra
code - I need existing java library functions to do it for me, but I
dont know what that fucntionality is.
breaks it into an array of substrings for displaying the text truncated
to fit the screen width on word boundaries.
It just looks for the spaces.
trouble is, it crashes out with japenese text. There is a part of the
code that looks at the next character to see if it is a space:
ch = str.substring(offset, offset + 1);
isSpace = false;
// return when a new line is reached
if (ch.equals("\n"))
return offset+1;
currentWidth += font.stringWidth(ch);
if (ch.equals(" "))
isSpace = true;
and if it isnt a space, it adds the width of the character (in pixels)
, and keeps going until it does find a space.
the problem with this is it assumes that each byte is a characater. In
utf8, up to 3 bytes could be one character, so this code is trying to
find the widths of characters representing each byte in a utf8
sequence, rather than the width of the utf8 character as a whole.
my additional problem is this is iAppli code, so I am limited to a 30K
codebase, and I have hit the limit, so I cant write any more lines of
code - I just have to change the existing code such that it doesnt
generate any more bytecode.
what can I do to the above code so that I can count widths of utf8
characters instead of asc characters, without writing too much extra
code - I need existing java library functions to do it for me, but I
dont know what that fucntionality is.