StringUtil { public static String filter(String str) { if (str == null) { return null; } char[] cbuf = str.toCharArray(); StringBuilder sbui = new StringBuilder(); for (int i = 0; i < cbuf.length; i++) { if (cbuf[i] == '&') { sbui.append("&amp;"); } else if (cbuf[i] == '<') { sbui.append("&lt;"); } else if (cbuf[i] == '>') { sbui.append("&gt;"); } else if (cbuf[i] == '"') { sbui.append("&quot;"); } else if (cbuf[i] == '\'') { sbui.append("&#39;"); } else { sbui.append(cbuf[i]); } } return sbui.toString(); }  static boolean isWhitespace(char c); static boolean isZenHankakuSpace(char c); static String rtrim(String str); static String ltrim(String str); static String trim(String str); static String rtrimZ(String str); static String ltrimZ(String str); static String trimZ(String str); static String toShortClassName(String longClassName); static String getExtension(String name); static String toHexString(byte[] byteArray, String delim); static String capitalizeInitial(String str); static String[] parseCSV(String csvString); static String[] parseCSV(String csvString, String escapeString); static String dump(Map<?, ?> map); static String getArraysStr(Object[] arrayObj); static String hankakuToZenkaku(String value); static String zenkakuToHankaku(String value); static String filter(String str); static String toLikeCondition(String condition); static int getByteLength(String value, String encoding); static final String LINE_SEP; static final String LIKE_ESC_CHAR; }
@Test public void testFilter01() throws Exception { String input = "a & b"; String result = StringUtil.filter(input); assertEquals("a &amp; b", result); }
@Test public void testFilter02() throws Exception { String input = "abc"; String result = StringUtil.filter(input); assertEquals("abc", result); }
@Test public void testFilter03() throws Exception { String input = "< & > \" '"; String result = StringUtil.filter(input); assertEquals("&lt; &amp; &gt; &quot; &#39;", result); }
@Test public void testFilter04() throws Exception { String input = "<"; String result = StringUtil.filter(input); assertEquals("&lt;", result); }
@Test public void testFilter05() throws Exception { String input = "ア"; String result = StringUtil.filter(input); assertEquals("ア", result); }
@Test public void testFilter06() throws Exception { String input = null; String result = StringUtil.filter(input); assertNull(result); }
@Test public void testFilter07() throws Exception { String input = ""; String result = StringUtil.filter(input); assertEquals("", result); }