@Test public void testNormalizeSpaces() throws Exception { assertThat(normalizeSpaces(""), is("")); assertThat(normalizeSpaces(" "), is("")); assertThat(normalizeSpaces(" "), is("")); assertThat(normalizeSpaces(" abc"), is("abc")); assertThat(normalizeSpaces(" abc"), is("abc")); assertThat(normalizeSpaces("abc "), is("abc")); assertThat(normalizeSpaces("abc "), is("abc")); assertThat(normalizeSpaces("abc def"), is("abc def")); assertThat(normalizeSpaces("abc def"), is("abc def")); assertThat(normalizeSpaces("abc\u00A0def"), is("abc def")); assertThat(normalizeSpaces("abc \u00A0def"), is("abc def")); assertThat(normalizeSpaces("\n\n\n"), is("\n\n\n")); assertThat(normalizeSpaces(" \n "), is("\n")); assertThat(normalizeSpaces(" abc \n def "), is("abc \n def")); assertThat(normalizeSpaces("abc\ndef\n"), is("abc\ndef\n")); assertThat(normalizeSpaces("abc def\nghi jkl"), is("abc def\nghi jkl")); }
public static String normalizeSpaces(String str) { int si = str.indexOf(' '); int ni = str.indexOf('\u00A0'); if (si < 0 && ni < 0) return str; int len = str.length(); StringBuilder buf = new StringBuilder(len); boolean skipSpc = true; for (int i = 0; i < len; i++) { char c = str.charAt(i); if (c != ' ' && c != '\u00A0') { buf.append(c); skipSpc = false; } else if (!skipSpc) { buf.append(' '); skipSpc = true; } } int blen = buf.length(); if (blen > 0 && buf.charAt(blen - 1) == ' ') buf.deleteCharAt(blen - 1); return buf.toString(); }
SeleniumUtils { public static String normalizeSpaces(String str) { int si = str.indexOf(' '); int ni = str.indexOf('\u00A0'); if (si < 0 && ni < 0) return str; int len = str.length(); StringBuilder buf = new StringBuilder(len); boolean skipSpc = true; for (int i = 0; i < len; i++) { char c = str.charAt(i); if (c != ' ' && c != '\u00A0') { buf.append(c); skipSpc = false; } else if (!skipSpc) { buf.append(' '); skipSpc = true; } } int blen = buf.length(); if (blen > 0 && buf.charAt(blen - 1) == ' ') buf.deleteCharAt(blen - 1); return buf.toString(); } }
SeleniumUtils { public static String normalizeSpaces(String str) { int si = str.indexOf(' '); int ni = str.indexOf('\u00A0'); if (si < 0 && ni < 0) return str; int len = str.length(); StringBuilder buf = new StringBuilder(len); boolean skipSpc = true; for (int i = 0; i < len; i++) { char c = str.charAt(i); if (c != ' ' && c != '\u00A0') { buf.append(c); skipSpc = false; } else if (!skipSpc) { buf.append(' '); skipSpc = true; } } int blen = buf.length(); if (blen > 0 && buf.charAt(blen - 1) == ' ') buf.deleteCharAt(blen - 1); return buf.toString(); } private  SeleniumUtils(); }
SeleniumUtils { public static String normalizeSpaces(String str) { int si = str.indexOf(' '); int ni = str.indexOf('\u00A0'); if (si < 0 && ni < 0) return str; int len = str.length(); StringBuilder buf = new StringBuilder(len); boolean skipSpc = true; for (int i = 0; i < len; i++) { char c = str.charAt(i); if (c != ' ' && c != '\u00A0') { buf.append(c); skipSpc = false; } else if (!skipSpc) { buf.append(' '); skipSpc = true; } } int blen = buf.length(); if (blen > 0 && buf.charAt(blen - 1) == ' ') buf.deleteCharAt(blen - 1); return buf.toString(); } private  SeleniumUtils(); static boolean patternMatches(String pattern, CharSequence input); static String normalizeSpaces(String str); static String doubleToString(double d); static String convertToString(T result); static boolean isElementNotFound(RuntimeException e); static void windowMaximize(WebDriver driver); }
SeleniumUtils { public static String normalizeSpaces(String str) { int si = str.indexOf(' '); int ni = str.indexOf('\u00A0'); if (si < 0 && ni < 0) return str; int len = str.length(); StringBuilder buf = new StringBuilder(len); boolean skipSpc = true; for (int i = 0; i < len; i++) { char c = str.charAt(i); if (c != ' ' && c != '\u00A0') { buf.append(c); skipSpc = false; } else if (!skipSpc) { buf.append(' '); skipSpc = true; } } int blen = buf.length(); if (blen > 0 && buf.charAt(blen - 1) == ' ') buf.deleteCharAt(blen - 1); return buf.toString(); } private  SeleniumUtils(); static boolean patternMatches(String pattern, CharSequence input); static String normalizeSpaces(String str); static String doubleToString(double d); static String convertToString(T result); static boolean isElementNotFound(RuntimeException e); static void windowMaximize(WebDriver driver);  }