@@ -231,38 +231,14 @@ public String toUnicode(String name)
231231 {
232232 unicode = toUnicode (name .substring (0 , name .indexOf ('.' )));
233233 }
234- else if (name .startsWith ("uni" ) && name .length () == 7 )
234+ else if ((name .length () == 7 && name .startsWith ("uni" ))
235+ || (name .length () == 5 && name .startsWith ("u" )))
235236 {
236- // test for Unicode name in the format uniXXXX where X is hex
237- int nameLength = name .length ();
238- StringBuilder uniStr = new StringBuilder ();
237+ // test for Unicode name in the format uniXXXX/uXXXX where X is hex
238+ int start = name .startsWith ("uni" ) ? 3 : 1 ;
239239 try
240240 {
241- for (int chPos = 3 ; chPos + 4 <= nameLength ; chPos += 4 )
242- {
243- int codePoint = Integer .parseInt (name .substring (chPos , chPos + 4 ), 16 );
244- if (codePoint > 0xD7FF && codePoint < 0xE000 )
245- {
246- LOG .warn ("Unicode character name with disallowed code area: {}" , name );
247- }
248- else
249- {
250- uniStr .append ((char ) codePoint );
251- }
252- }
253- unicode = uniStr .toString ();
254- }
255- catch (NumberFormatException nfe )
256- {
257- LOG .warn ("Not a number in Unicode character name: {}" , name );
258- }
259- }
260- else if (name .startsWith ("u" ) && name .length () == 5 )
261- {
262- // test for an alternate Unicode name representation uXXXX
263- try
264- {
265- int codePoint = Integer .parseInt (name .substring (1 ), 16 );
241+ int codePoint = Integer .parseInt (name , start , start + 4 , 16 );
266242 if (codePoint > 0xD7FF && codePoint < 0xE000 )
267243 {
268244 LOG .warn ("Unicode character name with disallowed code area: {}" , name );
0 commit comments