List of utility methods to do String Whitespace Normalize
String | normalizeWhitespace(String source) INTERNAL: Replaces sequences of one or more ' ', \t, \n, \r by a single space, returning the new string. char[] string = source.toCharArray(); int pos = 0; boolean previousWasWS = false; for (int ix = 0; ix < string.length; ix++) { switch (string[ix]) { case ' ': case '\t': case '\n': ... |
String | normalizeWhiteSpace(String src) Replace all blocks of white space by a single space character, just used for creating test cases. StringBuilder result = new StringBuilder(src.length()); boolean inWhitespaceBlock = false; for (int i = 0; i < src.length(); i++) { char c = src.charAt(i); if (Character.isWhitespace(c)) { if (!inWhitespaceBlock) { result.append(" "); inWhitespaceBlock = true; ... |
String | normalizeWhitespace(String text) Translates multiple whitespace into single space character. text = text.replaceAll("(\r\n|\r)", "\n"); text = text.replaceAll("(?:(?![\n])\\s+)", " "); text = text.replaceAll("<br>", ""); return text; |
String | normalizeWhitespaces(String s) Replaces all duplicated whitespace characters with single space. int length = s.length(); StringBuffer normalized = new StringBuffer(length); boolean needSpace = false; for (int index = 0; index < length; index++) { char c = s.charAt(index); if (Character.isWhitespace(c)) { needSpace = true; } else { ... |
String | normalizeWhitespaces(String text) normalize Whitespaces return compressWhitespaces(text).trim();
|