StringUtils { public static String normalizeId(String name) { char[] buffer = name.toCharArray(); int outix = 0; boolean whitespacerun = false; boolean firstchar = false; for (int inix = 0; inix < buffer.length; inix++) { char ch = buffer[inix]; if (ch > 0x00FF) continue; if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n') { if (!firstchar || whitespacerun) continue; ch = '-'; whitespacerun = true; } else whitespacerun = false; char mapsto = charmap[ch]; if (mapsto == 0 && firstchar) continue; if (mapsto == 0) buffer[outix++] = '_'; else { buffer[outix++] = mapsto; firstchar = true; } } if (whitespacerun) outix--; if (outix < 1) return null; else if (isNameStart(buffer[0])) return new String(buffer, 0, outix); else return "_" + new String(buffer, 0, outix); }  static String escapeHTMLEntities(String value); static void escapeHTMLEntities(String value, Writer out); static String makeRandomId(int length); static String normalizeId(String name); static final String VERY_UNLIKELY_STRING; }
@Test public void testNormalizeIdEmpty() { Assert.assertTrue("incorrect normalization of empty string", StringUtils.normalizeId("") == null); }
@Test public void testNormalizeIdOK() { Assert.assertEquals("incorrect normalization", StringUtils.normalizeId("abc"), "abc"); }
@Test public void testNormalizeIdOK1() { Assert.assertEquals("incorrect normalization", StringUtils.normalizeId("a"), "a"); }
@Test public void testNormalizeIdLowerCase() { Assert.assertEquals("incorrect normalization", StringUtils.normalizeId("ABCD"), "abcd"); }
@Test public void testNormalizeIdStripAccents() { String input = "ab\u00C6\u00D8\u00E5\u00E9\u00FF\u00FCab\u00CF"; Assert.assertEquals("incorrect normalization", StringUtils.normalizeId(input), "abeoaeyuabi"); }
@Test public void testNormalizeIdKeepSpecials() { Assert.assertEquals("incorrect normalization", StringUtils.normalizeId("ab._-"), "ab._-"); }
@Test public void testNormalizeIdGetRidOfSpaces() { String id = StringUtils.normalizeId(" ab ab "); Assert.assertTrue("incorrect normalization, should be 'ab-ab', but was '" + id + "'", "ab-ab".equals(id)); }
@Test public void testNormalizeIdEarlyDiscard() { String id = StringUtils.normalizeId("@@ab"); Assert.assertTrue("incorrect normalization, should be '__ab', but was '" + id + "'", "__ab".equals(id)); }