@Test public void testDefaultValidName() { assertEquals("_", createValidId("")); assertEquals("_", createValidId(null)); assertEquals("_", createValidId("&")); assertEquals("_", createValidId("#")); assertEquals("_", createValidId(" ")); assertEquals("_", createValidId("£")); }
public static String createValidId(String value) { if (isEmpty(value)) { return "_"; } StringBuilder resultId = new StringBuilder(); for (int i = 0; i < value.length(); i++) { if (isNcNameCharacter(value.charAt(i))) { resultId.append(value.charAt(i)); } } String result = resultId.toString(); if (isEmpty(result)) { return "_"; } if (isNcNameStartCharacter(result.charAt(0))) { return result; } return "_" + result; }
XmlUtils { public static String createValidId(String value) { if (isEmpty(value)) { return "_"; } StringBuilder resultId = new StringBuilder(); for (int i = 0; i < value.length(); i++) { if (isNcNameCharacter(value.charAt(i))) { resultId.append(value.charAt(i)); } } String result = resultId.toString(); if (isEmpty(result)) { return "_"; } if (isNcNameStartCharacter(result.charAt(0))) { return result; } return "_" + result; } }
XmlUtils { public static String createValidId(String value) { if (isEmpty(value)) { return "_"; } StringBuilder resultId = new StringBuilder(); for (int i = 0; i < value.length(); i++) { if (isNcNameCharacter(value.charAt(i))) { resultId.append(value.charAt(i)); } } String result = resultId.toString(); if (isEmpty(result)) { return "_"; } if (isNcNameStartCharacter(result.charAt(0))) { return result; } return "_" + result; } private  XmlUtils(); }
XmlUtils { public static String createValidId(String value) { if (isEmpty(value)) { return "_"; } StringBuilder resultId = new StringBuilder(); for (int i = 0; i < value.length(); i++) { if (isNcNameCharacter(value.charAt(i))) { resultId.append(value.charAt(i)); } } String result = resultId.toString(); if (isEmpty(result)) { return "_"; } if (isNcNameStartCharacter(result.charAt(0))) { return result; } return "_" + result; } private  XmlUtils(); static boolean isNcNameStartCharacter(char ch); static boolean isNcNameCharacter(char ch); static String createValidId(String value); }
XmlUtils { public static String createValidId(String value) { if (isEmpty(value)) { return "_"; } StringBuilder resultId = new StringBuilder(); for (int i = 0; i < value.length(); i++) { if (isNcNameCharacter(value.charAt(i))) { resultId.append(value.charAt(i)); } } String result = resultId.toString(); if (isEmpty(result)) { return "_"; } if (isNcNameStartCharacter(result.charAt(0))) { return result; } return "_" + result; } private  XmlUtils(); static boolean isNcNameStartCharacter(char ch); static boolean isNcNameCharacter(char ch); static String createValidId(String value);  }