[LANG-192] API improvements
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@611528 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c739e01c68
commit
97f1c120c0
|
@ -2612,15 +2612,15 @@ public class StringUtils {
|
||||||
* <code>java.lang.Character.getType(char)</code>. Groups of contiguous
|
* <code>java.lang.Character.getType(char)</code>. Groups of contiguous
|
||||||
* characters of the same type are returned as complete tokens.
|
* characters of the same type are returned as complete tokens.
|
||||||
* <pre>
|
* <pre>
|
||||||
* StringUtils.splitByCamelCase(null) = null
|
* StringUtils.splitByCharacterType(null) = null
|
||||||
* StringUtils.splitByCamelCase("") = []
|
* StringUtils.splitByCharacterType("") = []
|
||||||
* StringUtils.splitByCamelCase("ab de fg") = ["ab", " ", "de", " ", "fg"]
|
* StringUtils.splitByCharacterType("ab de fg") = ["ab", " ", "de", " ", "fg"]
|
||||||
* StringUtils.splitByCamelCase("ab de fg") = ["ab", " ", "de", " ", "fg"]
|
* StringUtils.splitByCharacterType("ab de fg") = ["ab", " ", "de", " ", "fg"]
|
||||||
* StringUtils.splitByCamelCase("ab:cd:ef") = ["ab", ":", "cd", ":", "ef"]
|
* StringUtils.splitByCharacterType("ab:cd:ef") = ["ab", ":", "cd", ":", "ef"]
|
||||||
* StringUtils.splitByCamelCase("number5") = ["number", "5"]
|
* StringUtils.splitByCharacterType("number5") = ["number", "5"]
|
||||||
* StringUtils.splitByCamelCase("fooBar") = ["foo", "B", "ar"]
|
* StringUtils.splitByCharacterType("fooBar") = ["foo", "B", "ar"]
|
||||||
* StringUtils.splitByCamelCase("foo200Bar") = ["foo", "200", "B", "ar"]
|
* StringUtils.splitByCharacterType("foo200Bar") = ["foo", "200", "B", "ar"]
|
||||||
* StringUtils.splitByCamelCase("ASFRules") = ["ASFR", "ules"]
|
* StringUtils.splitByCharacterType("ASFRules") = ["ASFR", "ules"]
|
||||||
* </pre>
|
* </pre>
|
||||||
* @param str the String to split, may be <code>null</code>
|
* @param str the String to split, may be <code>null</code>
|
||||||
* @return an array of parsed Strings, <code>null</code> if null String input
|
* @return an array of parsed Strings, <code>null</code> if null String input
|
||||||
|
@ -2630,6 +2630,34 @@ public class StringUtils {
|
||||||
return splitByCharacterType(str, false);
|
return splitByCharacterType(str, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Splits a String by Character type as returned by
|
||||||
|
* <code>java.lang.Character.getType(char)</code>. Groups of contiguous
|
||||||
|
* characters of the same type are returned as complete tokens, with the
|
||||||
|
* following exception: the character of type
|
||||||
|
* <code>Character.UPPERCASE_LETTER</code>, if any, immediately
|
||||||
|
* preceding a token of type <code>Character.LOWERCASE_LETTER</code>
|
||||||
|
* will belong to the following token rather than to the preceding, if any,
|
||||||
|
* <code>Character.UPPERCASE_LETTER</code> token.
|
||||||
|
* <pre>
|
||||||
|
* StringUtils.splitByCharacterTypeCamelCase(null) = null
|
||||||
|
* StringUtils.splitByCharacterTypeCamelCase("") = []
|
||||||
|
* StringUtils.splitByCharacterTypeCamelCase("ab de fg") = ["ab", " ", "de", " ", "fg"]
|
||||||
|
* StringUtils.splitByCharacterTypeCamelCase("ab de fg") = ["ab", " ", "de", " ", "fg"]
|
||||||
|
* StringUtils.splitByCharacterTypeCamelCase("ab:cd:ef") = ["ab", ":", "cd", ":", "ef"]
|
||||||
|
* StringUtils.splitByCharacterTypeCamelCase("number5") = ["number", "5"]
|
||||||
|
* StringUtils.splitByCharacterTypeCamelCase("fooBar") = ["foo", "Bar"]
|
||||||
|
* StringUtils.splitByCharacterTypeCamelCase("foo200Bar") = ["foo", "200", "Bar"]
|
||||||
|
* StringUtils.splitByCharacterTypeCamelCase("ASFRules") = ["ASF", "Rules"]
|
||||||
|
* </pre>
|
||||||
|
* @param str the String to split, may be <code>null</code>
|
||||||
|
* @return an array of parsed Strings, <code>null</code> if null String input
|
||||||
|
* @since 2.4
|
||||||
|
*/
|
||||||
|
public static String[] splitByCharacterTypeCamelCase(String str) {
|
||||||
|
return splitByCharacterType(str, true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Splits a String by Character type as returned by
|
* <p>Splits a String by Character type as returned by
|
||||||
* <code>java.lang.Character.getType(char)</code>. Groups of contiguous
|
* <code>java.lang.Character.getType(char)</code>. Groups of contiguous
|
||||||
|
@ -2639,23 +2667,12 @@ public class StringUtils {
|
||||||
* immediately preceding a token of type <code>Character.LOWERCASE_LETTER</code>
|
* immediately preceding a token of type <code>Character.LOWERCASE_LETTER</code>
|
||||||
* will belong to the following token rather than to the preceding, if any,
|
* will belong to the following token rather than to the preceding, if any,
|
||||||
* <code>Character.UPPERCASE_LETTER</code> token.
|
* <code>Character.UPPERCASE_LETTER</code> token.
|
||||||
* <pre>
|
|
||||||
* StringUtils.splitByCamelCase(null) = null
|
|
||||||
* StringUtils.splitByCamelCase("") = []
|
|
||||||
* StringUtils.splitByCamelCase("ab de fg") = ["ab", " ", "de", " ", "fg"]
|
|
||||||
* StringUtils.splitByCamelCase("ab de fg") = ["ab", " ", "de", " ", "fg"]
|
|
||||||
* StringUtils.splitByCamelCase("ab:cd:ef") = ["ab", ":", "cd", ":", "ef"]
|
|
||||||
* StringUtils.splitByCamelCase("number5") = ["number", "5"]
|
|
||||||
* StringUtils.splitByCamelCase("fooBar") = ["foo", "Bar"]
|
|
||||||
* StringUtils.splitByCamelCase("foo200Bar") = ["foo", "200", "Bar"]
|
|
||||||
* StringUtils.splitByCamelCase("ASFRules") = ["ASF", "Rules"]
|
|
||||||
* </pre>
|
|
||||||
* @param str the String to split, may be <code>null</code>
|
* @param str the String to split, may be <code>null</code>
|
||||||
* @param camelCase whether to use so-called "camel-case" for letter types
|
* @param camelCase whether to use so-called "camel-case" for letter types
|
||||||
* @return an array of parsed Strings, <code>null</code> if null String input
|
* @return an array of parsed Strings, <code>null</code> if null String input
|
||||||
* @since 2.4
|
* @since 2.4
|
||||||
*/
|
*/
|
||||||
public static String[] splitByCharacterType(String str, boolean camelCase) {
|
private static String[] splitByCharacterType(String str, boolean camelCase) {
|
||||||
if (str == null) {
|
if (str == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -851,52 +851,53 @@ public class StringUtilsTest extends TestCase {
|
||||||
public void testSplitByCharacterType() {
|
public void testSplitByCharacterType() {
|
||||||
assertNull(StringUtils.splitByCharacterType(null));
|
assertNull(StringUtils.splitByCharacterType(null));
|
||||||
assertEquals(0, StringUtils.splitByCharacterType("").length);
|
assertEquals(0, StringUtils.splitByCharacterType("").length);
|
||||||
assertNull(StringUtils.splitByCharacterType(null, true));
|
|
||||||
assertEquals(0, StringUtils.splitByCharacterType("", true).length);
|
|
||||||
|
|
||||||
final boolean camelCase = true;
|
|
||||||
|
|
||||||
assertTrue(ArrayUtils.isEquals(new String[] { "ab", " ", "de", " ",
|
assertTrue(ArrayUtils.isEquals(new String[] { "ab", " ", "de", " ",
|
||||||
"fg" }, StringUtils.splitByCharacterType("ab de fg")));
|
"fg" }, StringUtils.splitByCharacterType("ab de fg")));
|
||||||
|
|
||||||
assertTrue(ArrayUtils.isEquals(new String[] { "ab", " ", "de", " ",
|
|
||||||
"fg" }, StringUtils.splitByCharacterType("ab de fg", camelCase)));
|
|
||||||
|
|
||||||
assertTrue(ArrayUtils.isEquals(new String[] { "ab", " ", "de", " ",
|
assertTrue(ArrayUtils.isEquals(new String[] { "ab", " ", "de", " ",
|
||||||
"fg" }, StringUtils.splitByCharacterType("ab de fg")));
|
"fg" }, StringUtils.splitByCharacterType("ab de fg")));
|
||||||
|
|
||||||
assertTrue(ArrayUtils.isEquals(new String[] { "ab", " ", "de", " ",
|
|
||||||
"fg" }, StringUtils.splitByCharacterType("ab de fg", camelCase)));
|
|
||||||
|
|
||||||
assertTrue(ArrayUtils.isEquals(new String[] { "ab", ":", "cd", ":",
|
assertTrue(ArrayUtils.isEquals(new String[] { "ab", ":", "cd", ":",
|
||||||
"ef" }, StringUtils.splitByCharacterType("ab:cd:ef")));
|
"ef" }, StringUtils.splitByCharacterType("ab:cd:ef")));
|
||||||
|
|
||||||
assertTrue(ArrayUtils.isEquals(new String[] { "ab", ":", "cd", ":",
|
|
||||||
"ef" }, StringUtils.splitByCharacterType("ab:cd:ef", camelCase)));
|
|
||||||
|
|
||||||
assertTrue(ArrayUtils.isEquals(new String[] { "number", "5" },
|
assertTrue(ArrayUtils.isEquals(new String[] { "number", "5" },
|
||||||
StringUtils.splitByCharacterType("number5")));
|
StringUtils.splitByCharacterType("number5")));
|
||||||
|
|
||||||
assertTrue(ArrayUtils.isEquals(new String[] { "number", "5" },
|
|
||||||
StringUtils.splitByCharacterType("number5", camelCase)));
|
|
||||||
|
|
||||||
assertTrue(ArrayUtils.isEquals(new String[] { "foo", "B", "ar" },
|
assertTrue(ArrayUtils.isEquals(new String[] { "foo", "B", "ar" },
|
||||||
StringUtils.splitByCharacterType("fooBar")));
|
StringUtils.splitByCharacterType("fooBar")));
|
||||||
|
|
||||||
assertTrue(ArrayUtils.isEquals(new String[] { "foo", "Bar" },
|
|
||||||
StringUtils.splitByCharacterType("fooBar", camelCase)));
|
|
||||||
|
|
||||||
assertTrue(ArrayUtils.isEquals(new String[] { "foo", "200", "B", "ar" },
|
assertTrue(ArrayUtils.isEquals(new String[] { "foo", "200", "B", "ar" },
|
||||||
StringUtils.splitByCharacterType("foo200Bar")));
|
StringUtils.splitByCharacterType("foo200Bar")));
|
||||||
|
|
||||||
assertTrue(ArrayUtils.isEquals(new String[] { "foo", "200", "Bar" },
|
|
||||||
StringUtils.splitByCharacterType("foo200Bar", camelCase)));
|
|
||||||
|
|
||||||
assertTrue(ArrayUtils.isEquals(new String[] { "ASFR", "ules" },
|
assertTrue(ArrayUtils.isEquals(new String[] { "ASFR", "ules" },
|
||||||
StringUtils.splitByCharacterType("ASFRules")));
|
StringUtils.splitByCharacterType("ASFRules")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSplitByCharacterTypeCamelCase() {
|
||||||
|
assertNull(StringUtils.splitByCharacterTypeCamelCase(null));
|
||||||
|
assertEquals(0, StringUtils.splitByCharacterTypeCamelCase("").length);
|
||||||
|
|
||||||
|
assertTrue(ArrayUtils.isEquals(new String[] { "ab", " ", "de", " ",
|
||||||
|
"fg" }, StringUtils.splitByCharacterTypeCamelCase("ab de fg")));
|
||||||
|
|
||||||
|
assertTrue(ArrayUtils.isEquals(new String[] { "ab", " ", "de", " ",
|
||||||
|
"fg" }, StringUtils.splitByCharacterTypeCamelCase("ab de fg")));
|
||||||
|
|
||||||
|
assertTrue(ArrayUtils.isEquals(new String[] { "ab", ":", "cd", ":",
|
||||||
|
"ef" }, StringUtils.splitByCharacterTypeCamelCase("ab:cd:ef")));
|
||||||
|
|
||||||
|
assertTrue(ArrayUtils.isEquals(new String[] { "number", "5" },
|
||||||
|
StringUtils.splitByCharacterTypeCamelCase("number5")));
|
||||||
|
|
||||||
|
assertTrue(ArrayUtils.isEquals(new String[] { "foo", "Bar" },
|
||||||
|
StringUtils.splitByCharacterTypeCamelCase("fooBar")));
|
||||||
|
|
||||||
|
assertTrue(ArrayUtils.isEquals(new String[] { "foo", "200", "Bar" },
|
||||||
|
StringUtils.splitByCharacterTypeCamelCase("foo200Bar")));
|
||||||
|
|
||||||
assertTrue(ArrayUtils.isEquals(new String[] { "ASF", "Rules" },
|
assertTrue(ArrayUtils.isEquals(new String[] { "ASF", "Rules" },
|
||||||
StringUtils.splitByCharacterType("ASFRules", camelCase)));
|
StringUtils.splitByCharacterTypeCamelCase("ASFRules")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDeprecatedDeleteSpace_String() {
|
public void testDeprecatedDeleteSpace_String() {
|
||||||
|
|
Loading…
Reference in New Issue