List of utility methods to do String Sanitize
String | sanitizeString(final String s) sanitize String if (s == null) { return ""; } else { return s.trim(); |
String | sanitizeString(String dirtyString) sanitize String StringBuilder sb = new StringBuilder(dirtyString.length()); for (int i = 0; i < dirtyString.length(); i++) { if (!Character.isIdentifierIgnorable(dirtyString.charAt(i))) { sb.append(dirtyString.charAt(i)); return sb.toString(); |
String | sanitizeString(String input) sanitize String if (input != null) { char[] docCharArray = input.toCharArray(); replaceInvalidXmlChars(docCharArray); return String.valueOf(docCharArray); return input; |
String | sanitizeString(String s) Removes newlines and tabs from a string String n = null; if (s != null) { n = s.replaceAll("\t", ""); n = n.replaceAll("\n", ""); return n; |
String | sanitizeString(String s) Clean any XML from the string return s.replace("<", "").replace(">", "").replace("/>", ""); |
String | sanitizeString(String s) sanitize String StringBuilder sb = new StringBuilder(); for (char c : s.toCharArray()) { if (c < 0x20) { sb.append(" "); } else { sb.append(c); return sb.toString().trim(); |
String | sanitizeString(String str) Escapes all escapable characters in a string. String newStr = ""; boolean escape = false; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (escape) { switch (c) { case '\\': newStr += "\\"; ... |
String | sanitizeStringAsLiteral(String literal) Sanitize a String for use in a SQL statement if (literal == null) { return "NULL"; String sanitizedLiteral = literal.replace("'", "''"); int nullIndex = sanitizedLiteral.indexOf('\0'); if (nullIndex >= 0) { StringBuilder builder = new StringBuilder(); int start = 0; ... |
String | sanitizeStringForXPath(String text) Convert the string to a safer version for XPath For example: Will o' The Wisp => concat('Will o' , "'" , ' The Wisp' , '') This will result in the same string when read by XPath. StringBuilder result = new StringBuilder(); int startOfChain = 0; int textLength = text.length(); boolean isSingleQuotationChain = false; for (int currentPos = 0; currentPos <= textLength; currentPos++) { boolean isChainBroken = currentPos >= textLength || isSingleQuotationChain && text.charAt(currentPos) != '\'' || !isSingleQuotationChain && text.charAt(currentPos) == '\''; ... |
String | sanitizeStringLiteral(String inputString) Removes first and last character, assuming they're simple (') or double quotes (") if (inputString != null && inputString != "") { if (inputString.charAt(0) == '"' && inputString.charAt(inputString.length() - 1) == '"' || inputString.charAt(0) == '\'' && inputString.charAt(inputString.length() - 1) == '\'') { if (inputString.length() > 2) inputString = inputString.substring(1, inputString.length() - 1); else inputString = ""; return inputString; |