@Test public void testReplaceUnicodeEntities() { assertEquals("Markus&Pia", NormalizeUtils.replaceUnicodeEntities("Markus&Pia")); assertEquals("Markus&Pia;", NormalizeUtils.replaceUnicodeEntities("Markus&Pia;")); assertEquals("Markus & Pia ; ", NormalizeUtils.replaceUnicodeEntities("Markus & Pia ; ")); assertEquals("&#pia;", NormalizeUtils.replaceUnicodeEntities("&#pia;")); assertEquals("&#12pia;", NormalizeUtils.replaceUnicodeEntities("&#12pia;")); assertTrue(NormalizeUtils.replaceUnicodeEntities(null) == null); assertEquals("лобан", NormalizeUtils.replaceUnicodeEntities("&#1083;&#1086;&#1073;&#1072;&#1085;")); assertEquals("лобан", NormalizeUtils.replaceUnicodeEntities("&#x43b;&#x43e;&#x431;&#x430;&#x43d;")); assertEquals("лобан", NormalizeUtils.replaceUnicodeEntities("&#x43B;&#x043e;&#x0431;&#x430;&#x43D;")); assertEquals("\\u43b\\u43e\\u431\\u430\\u43d", NormalizeUtils.replaceUnicodeEntities("\\u43b\\u43e\\u431\\u430\\u43d")); }
public static String replaceUnicodeEntities(String x) { if (x == null) { return x; } Matcher m = XML_ENTITIES_DEC.matcher(x); if (m.find()) { m.reset(); StringBuffer sb = new StringBuffer(); while (m.find()) { try { Character uc = (char) Integer.parseInt(m.group(1)); m.appendReplacement(sb, uc.toString()); } catch (NumberFormatException e) { m.appendReplacement(sb, m.group()); } } m.appendTail(sb); x = sb.toString(); } m = XML_ENTITIES_HEX.matcher(x); if (m.find()) { m.reset(); StringBuffer sb = new StringBuffer(); while (m.find()) { try { Character uc = (char) Integer.parseInt(m.group(1), 16); m.appendReplacement(sb, uc.toString()); } catch (NumberFormatException e) { m.appendReplacement(sb, m.group()); } } m.appendTail(sb); x = sb.toString(); } m = UNICODE_HEX.matcher(x); if (m.find()) { m.reset(); StringBuffer sb = new StringBuffer(); while (m.find()) { try { Character uc = (char) Integer.parseInt(m.group(1), 16); m.appendReplacement(sb, uc.toString()); } catch (NumberFormatException e) { m.appendReplacement(sb, m.group()); } } m.appendTail(sb); x = sb.toString(); } return x; }
NormalizeUtils { public static String replaceUnicodeEntities(String x) { if (x == null) { return x; } Matcher m = XML_ENTITIES_DEC.matcher(x); if (m.find()) { m.reset(); StringBuffer sb = new StringBuffer(); while (m.find()) { try { Character uc = (char) Integer.parseInt(m.group(1)); m.appendReplacement(sb, uc.toString()); } catch (NumberFormatException e) { m.appendReplacement(sb, m.group()); } } m.appendTail(sb); x = sb.toString(); } m = XML_ENTITIES_HEX.matcher(x); if (m.find()) { m.reset(); StringBuffer sb = new StringBuffer(); while (m.find()) { try { Character uc = (char) Integer.parseInt(m.group(1), 16); m.appendReplacement(sb, uc.toString()); } catch (NumberFormatException e) { m.appendReplacement(sb, m.group()); } } m.appendTail(sb); x = sb.toString(); } m = UNICODE_HEX.matcher(x); if (m.find()) { m.reset(); StringBuffer sb = new StringBuffer(); while (m.find()) { try { Character uc = (char) Integer.parseInt(m.group(1), 16); m.appendReplacement(sb, uc.toString()); } catch (NumberFormatException e) { m.appendReplacement(sb, m.group()); } } m.appendTail(sb); x = sb.toString(); } return x; } }
NormalizeUtils { public static String replaceUnicodeEntities(String x) { if (x == null) { return x; } Matcher m = XML_ENTITIES_DEC.matcher(x); if (m.find()) { m.reset(); StringBuffer sb = new StringBuffer(); while (m.find()) { try { Character uc = (char) Integer.parseInt(m.group(1)); m.appendReplacement(sb, uc.toString()); } catch (NumberFormatException e) { m.appendReplacement(sb, m.group()); } } m.appendTail(sb); x = sb.toString(); } m = XML_ENTITIES_HEX.matcher(x); if (m.find()) { m.reset(); StringBuffer sb = new StringBuffer(); while (m.find()) { try { Character uc = (char) Integer.parseInt(m.group(1), 16); m.appendReplacement(sb, uc.toString()); } catch (NumberFormatException e) { m.appendReplacement(sb, m.group()); } } m.appendTail(sb); x = sb.toString(); } m = UNICODE_HEX.matcher(x); if (m.find()) { m.reset(); StringBuffer sb = new StringBuffer(); while (m.find()) { try { Character uc = (char) Integer.parseInt(m.group(1), 16); m.appendReplacement(sb, uc.toString()); } catch (NumberFormatException e) { m.appendReplacement(sb, m.group()); } } m.appendTail(sb); x = sb.toString(); } return x; }  }
NormalizeUtils { public static String replaceUnicodeEntities(String x) { if (x == null) { return x; } Matcher m = XML_ENTITIES_DEC.matcher(x); if (m.find()) { m.reset(); StringBuffer sb = new StringBuffer(); while (m.find()) { try { Character uc = (char) Integer.parseInt(m.group(1)); m.appendReplacement(sb, uc.toString()); } catch (NumberFormatException e) { m.appendReplacement(sb, m.group()); } } m.appendTail(sb); x = sb.toString(); } m = XML_ENTITIES_HEX.matcher(x); if (m.find()) { m.reset(); StringBuffer sb = new StringBuffer(); while (m.find()) { try { Character uc = (char) Integer.parseInt(m.group(1), 16); m.appendReplacement(sb, uc.toString()); } catch (NumberFormatException e) { m.appendReplacement(sb, m.group()); } } m.appendTail(sb); x = sb.toString(); } m = UNICODE_HEX.matcher(x); if (m.find()) { m.reset(); StringBuffer sb = new StringBuffer(); while (m.find()) { try { Character uc = (char) Integer.parseInt(m.group(1), 16); m.appendReplacement(sb, uc.toString()); } catch (NumberFormatException e) { m.appendReplacement(sb, m.group()); } } m.appendTail(sb); x = sb.toString(); } return x; }  static String normalizeCitation(String citation); static String normalizeTerm(String term); static String replaceUnicodeEntities(String x); static String trimToNull(String x); }
NormalizeUtils { public static String replaceUnicodeEntities(String x) { if (x == null) { return x; } Matcher m = XML_ENTITIES_DEC.matcher(x); if (m.find()) { m.reset(); StringBuffer sb = new StringBuffer(); while (m.find()) { try { Character uc = (char) Integer.parseInt(m.group(1)); m.appendReplacement(sb, uc.toString()); } catch (NumberFormatException e) { m.appendReplacement(sb, m.group()); } } m.appendTail(sb); x = sb.toString(); } m = XML_ENTITIES_HEX.matcher(x); if (m.find()) { m.reset(); StringBuffer sb = new StringBuffer(); while (m.find()) { try { Character uc = (char) Integer.parseInt(m.group(1), 16); m.appendReplacement(sb, uc.toString()); } catch (NumberFormatException e) { m.appendReplacement(sb, m.group()); } } m.appendTail(sb); x = sb.toString(); } m = UNICODE_HEX.matcher(x); if (m.find()) { m.reset(); StringBuffer sb = new StringBuffer(); while (m.find()) { try { Character uc = (char) Integer.parseInt(m.group(1), 16); m.appendReplacement(sb, uc.toString()); } catch (NumberFormatException e) { m.appendReplacement(sb, m.group()); } } m.appendTail(sb); x = sb.toString(); } return x; }  static String normalizeCitation(String citation); static String normalizeTerm(String term); static String replaceUnicodeEntities(String x); static String trimToNull(String x);  }