Trims a string of unicode whitespace and invisible characters

@param input Input string
@return Trimmed string or null if input was null
763810
public static String trim(CharSequence input) {
      if (input == null) {
         return null;
      }
      return StringFunctions.TRIM.apply(input.toString());
   }
221639
public static List<Token> tokenize(final String input) {
        List<Token> result = new ArrayList<Token>();
        if (input == null) {
            return result;
        }

        final int WHITESPACE = 0;
        final int WORD = 1;
        final int STRINGDQ = 2;
        final int STRINGSQ = 3;
        final int COMMENT = 4;

        int state = WHITESPACE;
        char ch; // character in hand
        int tokenIndex = -1;
        StringBuilder token = new StringBuilder("");

        for (int i = 0; i < input.length(); i++) {
            ch = input.charAt(i);
            switch (state) {
                case WHITESPACE:
                    if (Character.isWhitespace(ch)) {
                        // keep state
                    } else if (Character.isLetterOrDigit(ch) || ch == '_') {
                        state = WORD;
                        tokenIndex = i;
                        token.append(ch);
                    } else if (ch == '"') {
                        state = STRINGDQ;
                        tokenIndex = i;
                    } else if (ch == '\'') {
                        state = STRINGSQ;
                        tokenIndex = i;
                    } else if (ch == '#') {
                        state = COMMENT;
                    } else {
                        state = WORD;
                        tokenIndex = i;
                        token.append(ch);
                    }
                    break;

                case WORD:
                    if (Character.isWhitespace(ch)) {
                        // submit token
                        result.add(new Token(tokenIndex, token.toString()));
                        token.setLength(0);
                        state = WHITESPACE;
                    } else if (Character.isLetterOrDigit(ch) || ch == '_') {
                        token.append(ch); // and keep state
                    } else if (ch == '"') {
                        if (i < input.length()-1 && input.charAt(i+1) == '"' ) {
                            // Yes, it's somewhat wrong in terms of statemachine, but it's the
                            // simplest and crearest way.
                            token.append('"');
                            i++;
                            // and keep state.
                        } else {
                            state = STRINGDQ; // but don't append; a"b"c is the same as abc.
                        }
                    } else if (ch == '\'') {
                        if (i < input.length()-1 && input.charAt(i+1) == '\'' ) {
                            // Yes, it's somewhat wrong in terms of statemachine, but it's the
                            // simplest and crearest way.
                            token.append('\'');
                            i++;
                            // and keep state.
                        } else {
                            state = STRINGSQ; // but don't append; a"b"c is the same as abc.
                        }
                    } else if (ch == '#') {
                        // submit token
                        result.add(new Token(tokenIndex, token.toString()));
                        token.setLength(0);
                        state = COMMENT;
                    } else {
                        // for now we do allow special chars in words
                        token.append(ch);
                    }
                    break;

                case STRINGDQ:
                    if (ch == '"') {
                        if (i < input.length() - 1 && input.charAt(i+1) == '"') {
                            token.append('"');
                            i++;
                            // and keep state
                        } else {
                            state = WORD;
                        }
                    } else {
                        token.append(ch);
                    }
                    break;

                case STRINGSQ:
                    if (ch == '\'') {
                        if (i < input.length() - 1 && input.charAt(i+1) == '\'') {
                            token.append('\'');
                            i++;
                            // and keep state
                        } else {
                            state = WORD;
                        }
                    } else {
                        token.append(ch);
                    }
                    break;

                case COMMENT:
                    // eat ch
                    break;

                default:
                    assert false : "Unknown state in Shell.tokenize() state machine";
                    break;
            }
        }

        if (state == WORD || state == STRINGDQ || state == STRINGSQ) {
            result.add(new Token(tokenIndex, token.toString()));
        }

        return result;
    }
296115
public static Slice trim(Slice utf8)
    {
        int start = firstNonWhitespacePosition(utf8);
        int end = lastNonWhitespacePosition(utf8, start);
        return utf8.slice(start, end - start);
    }
707849
public static UnicodeFriendlyString stripAccents(final UnicodeFriendlyString input) {
    // this nifty normalization courtesy of http://stackoverflow.com/questions/3322152/is-there-a-way-to-get-rid-of-accents-and-convert-a-whole-string-to-regular-lette
    return StringUtils.unicodeFriendly(ACCENT_STRIPPER.matcher(
        Normalizer.normalize(input.utf16CodeUnits(), Normalizer.Form.NFD))
        // note this replaceAll is really deleteAll
        .replaceAll(""));
  }
542041
public static boolean isBlank(String input) {
        int strLen;
        if (input == null || (strLen = input.length()) == 0) {
            return true;
        }
        for (int i = 0; i < strLen; i++) {
            if (!Character.isWhitespace(input.charAt(i))) {
                return false;
            }
        }
        return true;
    }
1278426
public static Slice trim(Slice utf8, int[] whiteSpaceCodePoints)
    {
        int start = firstNonMatchPosition(utf8, whiteSpaceCodePoints);
        int end = lastNonMatchPosition(utf8, start, whiteSpaceCodePoints);
        return utf8.slice(start, end - start);
    }
1164777
static String unescape(String input)
    {
        if (input.isEmpty())
            return input;

        String res = input.replaceAll("\\\\:", ":");
        char last = res.charAt(res.length() - 1);
        return last == '!' ? res.substring(0, res.length() - 1) : res;
    }
537014
public Token[] tokenize(String input) 
    {
    	char[] stringChars =  input.toCharArray();
        List<Token> tokens = new ArrayList<Token>();
        for (char c : stringChars) {
			if(Character.isLetterOrDigit(c)){
				tokens.add(internSomething(Character.toString(c)));
			}
			else if (!ignorePunctuation && !Character.isWhitespace(c)) {
				tokens.add(internSomething(Character.toString(c)));
			}
		}
        return (Token[]) tokens.toArray(new BasicToken[tokens.size()]);
    }
931808
public static boolean isStringNullOrEmpty(final String input) {
        if (input == null || input.trim().isEmpty()) {
            return true;
        }
        return false;

    }
48745
@Nullable
  @CheckReturnValue
  public static String trimTrailingWhitespaces (@Nullable final String s)
  {
    final int n = getTrailingWhitespaceCount (s);
    return n == 0 ? s : s.substring (0, s.length () - n);
  }
815947
public static @Nullable String trim(@Nullable String s) {
		return (s != null ? s.trim() : s);
	}
515949
static String unescapeText(String input)
    {
        ByteBuffer buffer = unescapeBytes(input);
        return new String(buffer.array(), buffer.position(), buffer.limit(), ISO_8859_1);
    }
1268566
@Nonnull
    public static List<String> removeEmptyEntries(@Nullable List<String> input) {
        if(input==null) {
            return Collections.emptyList();
        }
        Iterable<String> trimmedInputs = Iterables.transform(input, TRIM);
        Iterable<String> nonEmptyInputs = Iterables.filter(trimmedInputs, NOT_EMPTY);
        return Lists.newArrayList(nonEmptyInputs);
    }
1019185
private static String trimTrailingWhitespace(String string) {
        int end = 0;
        char c;

        for (int i = string.length() - 1; i >= 0; i--) {
            c = string.charAt(i);
            if (!Character.isWhitespace(c)) {
                end = i;
                break;
            }
        }

        if (end == 0) {
            return string;
        }

        return string.substring(0, end + 1);
    }
963442
public static int skipLeadingAsciiWhitespace(String input, int pos, int limit) {
    for (int i = pos; i < limit; i++) {
      switch (input.charAt(i)) {
        case '\t':
        case '\n':
        case '\f':
        case '\r':
        case ' ':
          continue;
        default:
          return i;
      }
    }
    return limit;
  }
1331591
public final static String trim(String value)
    {
        String result = null;
        if (null != value)
        {
            result = value.trim();
        }

        return result;
    }
1008817
public static String trimAllWhitespace(String str) {
        if (!hasLength(str)) {
            return str;
        }
        StringBuilder sb = new StringBuilder(str);
        int index = 0;
        while (sb.length() > index) {
            if (Character.isWhitespace(sb.charAt(index))) {
                sb.deleteCharAt(index);
            }
            else {
                index++;
            }
        }
        return sb.toString();
    }