Saturday, February 27, 2010

Bug Sony W580: error displaying text using UTF8 encoding

There is a strange bug with SonyEricsson W580. When drawing strings in UTF8 format some special characters are not displayed.
The strings are created using the following:

new String(bytearray, offset, size, "UTF-8")

and to fix the bug it must be created using:

                StringBuffer sb = new StringBuffer();
                for (int i = offset; i < offset + size; i++) {
                    sb.append(new String(bytearray, i, bytearray[i] < 0 ? 2 : 1, "UTF-8"));
                    if (bytearray[i] < 0){ i++; }
                }
                String txt = sb.toString();

A tiny bug, and a very ugly fix ;)

Lula