All pastes #737517 Raw Edit

Someone

public text v1 · immutable
·published 2007-10-15 14:21 UTC
rendered paste body
  public static String normalizeString(String str) {
    if (str == null)
      return EMPTY_STRING;

    char[] n = new char[str.length()];
    boolean white = true;
    int pos = 0;
    for (int i = 0, c = str.length(); i < c; ++i) {
      char element = str.charAt(i);
      if (" \t\n\r".indexOf(element) != -1) { //$NON-NLS-1$
        if (!white) {
          n[pos++] = ' ';
          white = true;
        }
      } else {
        n[pos++] = element;
        white = false;
      }
    }
    if (white && pos > 0)
      pos--;

    return new String(n, 0, pos);
  }