Hi, all,
I have a question on the "UnicodeEncoder" class implementation.
The class contains one method: "public static String encode (String
string)".
My question is about usage of StringBuilder/StringBuffer in it (the logic is
common for both 1.1.5 and 1.2.2).
Initially we have
StringBuilder sb = null;
and as I understand we have lazy creation of it.
For characters with "((int)c) >= 0x80" we check is our "sb" null or not, and
in case of null we create new instance of it.
But for rest of chars (((int)c) < 0x80) we have the following logic which is
not correct for me:
"else if( sb != null )
{
sb.append(c);
}"
So we append char to buffer/builder only if we have the instance of
buffer/builder.
For now imagine that we have some string with leading latin symbols. In
result we'll have incorrect encoded string.
I think I can miss something. Could somebody please describe the method's
logic?
Thank you in advance,
Peter