Properties.java UTF-16 support refactoring.

This commit is contained in:
JET 2011-03-23 17:06:33 -06:00
parent b29e692c31
commit 5b830343ba

View File

@ -85,7 +85,18 @@ public class Properties extends Hashtable {
} }
abstract int readCharacter() throws IOException; abstract int readCharacter() throws IOException;
char readUtf16() throws IOException {
char c = 0;
for (int i = 0; i < 4; ++i) {
int digit = Character.digit((char)readCharacter(), 16);
if (digit == -1) throw new IOException("Invalid Unicode escape encountered.");
c <<= 4;
c |= digit;
}
return c;
}
void parse(Map map) void parse(Map map)
throws IOException throws IOException
{ {
@ -149,17 +160,11 @@ public class Properties extends Hashtable {
break; break;
case 'u': case 'u':
if (escaped) { // ASCII Unicode escape if (escaped) {
int most = Character.digit((char)in.read(), 16); append(readUtf16());
int more = Character.digit((char)in.read(), 16);
int less = Character.digit((char)in.read(), 16);
int least = Character.digit((char)in.read(), 16);
char utf16 = (char)(most << 12 | more << 8 | less << 4 | least);
append(utf16);
} else { } else {
append(c); append(c);
} } break;
break;
default: default:
append(c); append(c);