LANG-1193 ordinalIndexOf("abc", "ab", 1) gives incorrect answer of -1
(correct answer should be 0) Revert LANG-1077
This commit is contained in:
parent
15e1ea2f4e
commit
d75fe46b8f
|
@ -22,6 +22,7 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<release version="3.5" date="tba" description="tba">
|
<release version="3.5" date="tba" description="tba">
|
||||||
|
<action issue="LANG-1193" type="fix" dev="sebb" due-to="Qin Li">ordinalIndexOf("abc", "ab", 1) gives incorrect answer of -1 (correct answer should be 0); revert fix for LANG-1077</action>
|
||||||
<action issue="LANG-1182" type="update" dev="britter" due-to="Larry West, Pascal Schumacher">Clarify JavaDoc of StringUtils.containsAny()</action>
|
<action issue="LANG-1182" type="update" dev="britter" due-to="Larry West, Pascal Schumacher">Clarify JavaDoc of StringUtils.containsAny()</action>
|
||||||
<action issue="LANG-1169" type="add" dev="lguibert" due-to="Rafal Glowinski, Robert Parr, Arman Sharif">Add StringUtils methods to compare a string to multiple strings</action>
|
<action issue="LANG-1169" type="add" dev="lguibert" due-to="Rafal Glowinski, Robert Parr, Arman Sharif">Add StringUtils methods to compare a string to multiple strings</action>
|
||||||
<action issue="LANG-1185" type="add" dev="lguibert">Add remove by regular expression methods in StringUtils</action>
|
<action issue="LANG-1185" type="add" dev="lguibert">Add remove by regular expression methods in StringUtils</action>
|
||||||
|
@ -104,7 +105,6 @@
|
||||||
<action issue="LANG-1071" type="update" dev="britter" due-to="Arno Noordover">Fix wrong examples in JavaDoc of StringUtils.replaceEachRepeatedly(...), StringUtils.replaceEach(...)</action>
|
<action issue="LANG-1071" type="update" dev="britter" due-to="Arno Noordover">Fix wrong examples in JavaDoc of StringUtils.replaceEachRepeatedly(...), StringUtils.replaceEach(...)</action>
|
||||||
<action issue="LANG-883" type="add" dev="britter" due-to="Daniel Stewart">Add StringUtils.containsAny(CharSequence, CharSequence...) method</action>
|
<action issue="LANG-883" type="add" dev="britter" due-to="Daniel Stewart">Add StringUtils.containsAny(CharSequence, CharSequence...) method</action>
|
||||||
<action issue="LANG-1073" type="fix" dev="kinow" due-to="haiyang li">Read wrong component type of array in add in ArrayUtils</action>
|
<action issue="LANG-1073" type="fix" dev="kinow" due-to="haiyang li">Read wrong component type of array in add in ArrayUtils</action>
|
||||||
<action issue="LANG-1077" type="fix" dev="kinow" due-to="haiyang li">StringUtils.ordinalIndexOf("aaaaaa", "aa", 2) != 3 in StringUtils</action>
|
|
||||||
<action issue="LANG-1072" type="fix" dev="sebb" due-to="haiyang li">Duplicated "0x" check in createBigInteger in NumberUtils</action>
|
<action issue="LANG-1072" type="fix" dev="sebb" due-to="haiyang li">Duplicated "0x" check in createBigInteger in NumberUtils</action>
|
||||||
<action issue="LANG-1064" type="fix" dev="djones" due-to="B.J. Herbison">StringUtils.abbreviate description doesn't agree with the examples</action>
|
<action issue="LANG-1064" type="fix" dev="djones" due-to="B.J. Herbison">StringUtils.abbreviate description doesn't agree with the examples</action>
|
||||||
<action issue="LANG-1052" type="add" dev="britter" due-to="Jan Matèrne">Multiline recursive to string style</action>
|
<action issue="LANG-1052" type="add" dev="britter" due-to="Jan Matèrne">Multiline recursive to string style</action>
|
||||||
|
|
|
@ -1222,6 +1222,13 @@ public static int indexOf(final CharSequence seq, final CharSequence searchSeq,
|
||||||
* StringUtils.ordinalIndexOf("aabaabaa", "", 2) = 0
|
* StringUtils.ordinalIndexOf("aabaabaa", "", 2) = 0
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
* <p>Matches may overlap:</p>
|
||||||
|
* <pre>
|
||||||
|
* StringUtils.ordinalIndexOf("ababab","aba", 1) = 0
|
||||||
|
* StringUtils.ordinalIndexOf("ababab","aba", 2) = 2
|
||||||
|
* StringUtils.ordinalIndexOf("ababab","aba", 3) = -1
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
* <p>Note that 'head(CharSequence str, int n)' may be implemented as: </p>
|
* <p>Note that 'head(CharSequence str, int n)' may be implemented as: </p>
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
|
@ -1248,7 +1255,7 @@ public static int ordinalIndexOf(final CharSequence str, final CharSequence sear
|
||||||
*
|
*
|
||||||
* @param str the CharSequence to check, may be null
|
* @param str the CharSequence to check, may be null
|
||||||
* @param searchStr the CharSequence to find, may be null
|
* @param searchStr the CharSequence to find, may be null
|
||||||
* @param ordinal the n-th {@code searchStr} to find
|
* @param ordinal the n-th {@code searchStr} to find, overlapping matches are allowed.
|
||||||
* @param lastIndex true if lastOrdinalIndexOf() otherwise false if ordinalIndexOf()
|
* @param lastIndex true if lastOrdinalIndexOf() otherwise false if ordinalIndexOf()
|
||||||
* @return the n-th index of the search CharSequence,
|
* @return the n-th index of the search CharSequence,
|
||||||
* {@code -1} ({@code INDEX_NOT_FOUND}) if no match or {@code null} string input
|
* {@code -1} ({@code INDEX_NOT_FOUND}) if no match or {@code null} string input
|
||||||
|
@ -1262,12 +1269,14 @@ private static int ordinalIndexOf(final CharSequence str, final CharSequence sea
|
||||||
return lastIndex ? str.length() : 0;
|
return lastIndex ? str.length() : 0;
|
||||||
}
|
}
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
// set the initial index beyond the end of the string
|
||||||
|
// this is to allow for the initial index decrement/increment
|
||||||
int index = lastIndex ? str.length() : INDEX_NOT_FOUND;
|
int index = lastIndex ? str.length() : INDEX_NOT_FOUND;
|
||||||
do {
|
do {
|
||||||
if (lastIndex) {
|
if (lastIndex) {
|
||||||
index = CharSequenceUtils.lastIndexOf(str, searchStr, index - searchStr.length());
|
index = CharSequenceUtils.lastIndexOf(str, searchStr, index - 1); // step backwards thru string
|
||||||
} else {
|
} else {
|
||||||
index = CharSequenceUtils.indexOf(str, searchStr, index + searchStr.length());
|
index = CharSequenceUtils.indexOf(str, searchStr, index + 1); // step forwards through string
|
||||||
}
|
}
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
return index;
|
return index;
|
||||||
|
|
|
@ -1148,8 +1148,21 @@ public void testOrdinalIndexOf() {
|
||||||
assertEquals(8, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 9));
|
assertEquals(8, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 9));
|
||||||
assertEquals(-1, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 10));
|
assertEquals(-1, StringUtils.ordinalIndexOf("aaaaaaaaa", "a", 10));
|
||||||
|
|
||||||
assertEquals(3, StringUtils.ordinalIndexOf("aaaaaa", "aa", 2));
|
assertEquals(0, StringUtils.ordinalIndexOf("aaaaaa", "aa", 1));
|
||||||
assertEquals(-1, StringUtils.ordinalIndexOf("aaaaaa", "aa", 3));
|
assertEquals(1, StringUtils.ordinalIndexOf("aaaaaa", "aa", 2));
|
||||||
|
assertEquals(2, StringUtils.ordinalIndexOf("aaaaaa", "aa", 3));
|
||||||
|
assertEquals(3, StringUtils.ordinalIndexOf("aaaaaa", "aa", 4));
|
||||||
|
assertEquals(4, StringUtils.ordinalIndexOf("aaaaaa", "aa", 5));
|
||||||
|
assertEquals(-1, StringUtils.ordinalIndexOf("aaaaaa", "aa", 6));
|
||||||
|
|
||||||
|
assertEquals(0, StringUtils.ordinalIndexOf("ababab", "aba", 1));
|
||||||
|
assertEquals(2, StringUtils.ordinalIndexOf("ababab", "aba", 2));
|
||||||
|
assertEquals(-1, StringUtils.ordinalIndexOf("ababab", "aba", 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLANG1193() {
|
||||||
|
assertEquals(0, StringUtils.ordinalIndexOf("abc", "ab", 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue