StringUtil { public static CharSequence trimOws(CharSequence value) { final int length = value.length(); if (length == 0) { return value; } int start = indexOfFirstNonOwsChar(value, length); int end = indexOfLastNonOwsChar(value, start, length); return start == 0 && end == length - 1 ? value : value.subSequence(start, end + 1); } private  StringUtil(); static String substringAfter(String value, char delim); static boolean commonSuffixOfLength(String s, String p, int len); static String byteToHexStringPadded(int value); static T byteToHexStringPadded(T buf, int value); static String toHexStringPadded(byte[] src); static String toHexStringPadded(byte[] src, int offset, int length); static T toHexStringPadded(T dst, byte[] src); static T toHexStringPadded(T dst, byte[] src, int offset, int length); static String byteToHexString(int value); static T byteToHexString(T buf, int value); static String toHexString(byte[] src); static String toHexString(byte[] src, int offset, int length); static T toHexString(T dst, byte[] src); static T toHexString(T dst, byte[] src, int offset, int length); static int decodeHexNibble(final char c); static byte decodeHexByte(CharSequence s, int pos); static byte[] decodeHexDump(CharSequence hexDump, int fromIndex, int length); static byte[] decodeHexDump(CharSequence hexDump); static String simpleClassName(Object o); static String simpleClassName(Class<?> clazz); static CharSequence escapeCsv(CharSequence value); static CharSequence escapeCsv(CharSequence value, boolean trimWhiteSpace); static CharSequence unescapeCsv(CharSequence value); static List<CharSequence> unescapeCsvFields(CharSequence value); static int length(String s); static boolean isNullOrEmpty(String s); static int indexOfNonWhiteSpace(CharSequence seq, int offset); static boolean isSurrogate(char c); static boolean endsWith(CharSequence s, char c); static CharSequence trimOws(CharSequence value); static final String EMPTY_STRING; static final String NEWLINE; static final char DOUBLE_QUOTE; static final char COMMA; static final char LINE_FEED; static final char CARRIAGE_RETURN; static final char TAB; static final char SPACE; }
@Test public void trimOws() { assertSame("", StringUtil.trimOws("")); assertEquals("", StringUtil.trimOws(" \t ")); assertSame("a", StringUtil.trimOws("a")); assertEquals("a", StringUtil.trimOws(" a")); assertEquals("a", StringUtil.trimOws("a ")); assertEquals("a", StringUtil.trimOws(" a ")); assertSame("abc", StringUtil.trimOws("abc")); assertEquals("abc", StringUtil.trimOws("\tabc")); assertEquals("abc", StringUtil.trimOws("abc\t")); assertEquals("abc", StringUtil.trimOws("\tabc\t")); assertSame("a\t b", StringUtil.trimOws("a\t b")); assertEquals("", StringUtil.trimOws("\t ").toString()); assertEquals("a b", StringUtil.trimOws("\ta b \t").toString()); }