P V schrieb:
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?
Yeah, I can. The main concept behind this is to avoid unnecessary string
building if the string does not contain special character. If you take a
closer look you'll see that on creating the string builder the whole
strind read so far is appended:
sb = new StringBuilder( string.length()+4 );
sb.append( string.substring(0,i) );
This would be relevant for your example with leading latin characters.
On meeting the first non-latin character all latin chars read so far are
appended to the builder.
This approach improves performance for strings that do not contain
non-latin characters (which normally should be quite some amount).
Hope this helps!
regards
Michael