@Test public void normalize() { assertSame("foo", Nodes.normalize("foo")); assertSame("foo bar", Nodes.normalize("foo bar")); assertEquals("foo bar", Nodes.normalize("foo\nbar")); assertEquals("foo bar", Nodes.normalize("foo \r\n\t bar")); }
static String normalize(String s) { StringBuilder sb = new StringBuilder(); boolean changed = false; boolean lastCharWasWS = false; final int len = s.length(); for (int i = 0; i < len; i++) { char c = s.charAt(i); if (Character.isWhitespace(c)) { if (!lastCharWasWS) { sb.append(SPACE); changed |= c != SPACE; } else { changed = true; } lastCharWasWS = true; } else { sb.append(c); lastCharWasWS = false; } } return changed ? sb.toString() : s; }
Nodes { static String normalize(String s) { StringBuilder sb = new StringBuilder(); boolean changed = false; boolean lastCharWasWS = false; final int len = s.length(); for (int i = 0; i < len; i++) { char c = s.charAt(i); if (Character.isWhitespace(c)) { if (!lastCharWasWS) { sb.append(SPACE); changed |= c != SPACE; } else { changed = true; } lastCharWasWS = true; } else { sb.append(c); lastCharWasWS = false; } } return changed ? sb.toString() : s; } }
Nodes { static String normalize(String s) { StringBuilder sb = new StringBuilder(); boolean changed = false; boolean lastCharWasWS = false; final int len = s.length(); for (int i = 0; i < len; i++) { char c = s.charAt(i); if (Character.isWhitespace(c)) { if (!lastCharWasWS) { sb.append(SPACE); changed |= c != SPACE; } else { changed = true; } lastCharWasWS = true; } else { sb.append(c); lastCharWasWS = false; } } return changed ? sb.toString() : s; } private  Nodes(); }
Nodes { static String normalize(String s) { StringBuilder sb = new StringBuilder(); boolean changed = false; boolean lastCharWasWS = false; final int len = s.length(); for (int i = 0; i < len; i++) { char c = s.charAt(i); if (Character.isWhitespace(c)) { if (!lastCharWasWS) { sb.append(SPACE); changed |= c != SPACE; } else { changed = true; } lastCharWasWS = true; } else { sb.append(c); lastCharWasWS = false; } } return changed ? sb.toString() : s; } private  Nodes(); static QName getQName(Node n); static String getMergedNestedText(Node n); static Map<QName, String> getAttributes(Node n); static Node stripWhitespace(Node original); static Node normalizeWhitespace(Node original); static Node stripElementContentWhitespace(Node original); }
Nodes { static String normalize(String s) { StringBuilder sb = new StringBuilder(); boolean changed = false; boolean lastCharWasWS = false; final int len = s.length(); for (int i = 0; i < len; i++) { char c = s.charAt(i); if (Character.isWhitespace(c)) { if (!lastCharWasWS) { sb.append(SPACE); changed |= c != SPACE; } else { changed = true; } lastCharWasWS = true; } else { sb.append(c); lastCharWasWS = false; } } return changed ? sb.toString() : s; } private  Nodes(); static QName getQName(Node n); static String getMergedNestedText(Node n); static Map<QName, String> getAttributes(Node n); static Node stripWhitespace(Node original); static Node normalizeWhitespace(Node original); static Node stripElementContentWhitespace(Node original);  }