Merge branch 'pr-441'

This closes #441
This commit is contained in:
Bruno P. Kinoshita 2019-08-25 12:14:19 +12:00
commit 102a6d7565
3 changed files with 15 additions and 6 deletions

View File

@ -61,6 +61,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="update" dev="ggregory">checkstyle.version 8.18 -> 8.23.</action> <action type="update" dev="ggregory">checkstyle.version 8.18 -> 8.23.</action>
<action type="update" dev="ggregory">junit-jupiter 5.5.0 -> 5.5.1.</action> <action type="update" dev="ggregory">junit-jupiter 5.5.0 -> 5.5.1.</action>
<action issue="LANG-1477" type="add" dev="jochen">Added Functions.as*, and tests thereof, as suggested by Peter Verhas</action> <action issue="LANG-1477" type="add" dev="jochen">Added Functions.as*, and tests thereof, as suggested by Peter Verhas</action>
<action issue="LANG-1475" type="fix" dev="kinow" due-to="stzx">StringUtils.unwrap incorrect throw StringIndexOutOfBoundsException.</action>
</release> </release>
<release version="3.9" date="2019-04-09" description="New features and bug fixes. Requires Java 8, supports Java 9, 10, 11"> <release version="3.9" date="2019-04-09" description="New features and bug fixes. Requires Java 8, supports Java 9, 10, 11">

View File

@ -9159,6 +9159,8 @@ public class StringUtils {
* StringUtils.unwrap(null, null) = null * StringUtils.unwrap(null, null) = null
* StringUtils.unwrap(null, '\0') = null * StringUtils.unwrap(null, '\0') = null
* StringUtils.unwrap(null, '1') = null * StringUtils.unwrap(null, '1') = null
* StringUtils.unwrap("a", 'a') = "a"
* StringUtils.unwrap("aa", 'a') = ""
* StringUtils.unwrap("\'abc\'", '\'') = "abc" * StringUtils.unwrap("\'abc\'", '\'') = "abc"
* StringUtils.unwrap("AABabcBAA", 'A') = "ABabcBA" * StringUtils.unwrap("AABabcBAA", 'A') = "ABabcBA"
* StringUtils.unwrap("A", '#') = "A" * StringUtils.unwrap("A", '#') = "A"
@ -9175,17 +9177,16 @@ public class StringUtils {
* @since 3.6 * @since 3.6
*/ */
public static String unwrap(final String str, final char wrapChar) { public static String unwrap(final String str, final char wrapChar) {
if (isEmpty(str) || wrapChar == CharUtils.NUL) { if (isEmpty(str) || wrapChar == CharUtils.NUL || str.length() == 1) {
return str; return str;
} }
if (str.charAt(0) == wrapChar && str.charAt(str.length() - 1) == wrapChar) { if (str.charAt(0) == wrapChar && str.charAt(str.length() - 1) == wrapChar) {
final int startIndex = 0; final int startIndex = 0;
final int endIndex = str.length() - 1; final int endIndex = str.length() - 1;
if (endIndex != -1) {
return str.substring(startIndex + 1, endIndex); return str.substring(startIndex + 1, endIndex);
} }
}
return str; return str;
} }
@ -9199,6 +9200,8 @@ public class StringUtils {
* StringUtils.unwrap(null, null) = null * StringUtils.unwrap(null, null) = null
* StringUtils.unwrap(null, "") = null * StringUtils.unwrap(null, "") = null
* StringUtils.unwrap(null, "1") = null * StringUtils.unwrap(null, "1") = null
* StringUtils.unwrap("a", "a") = "a"
* StringUtils.unwrap("aa", "a") = ""
* StringUtils.unwrap("\'abc\'", "\'") = "abc" * StringUtils.unwrap("\'abc\'", "\'") = "abc"
* StringUtils.unwrap("\"abc\"", "\"") = "abc" * StringUtils.unwrap("\"abc\"", "\"") = "abc"
* StringUtils.unwrap("AABabcBAA", "AA") = "BabcB" * StringUtils.unwrap("AABabcBAA", "AA") = "BabcB"
@ -9216,7 +9219,7 @@ public class StringUtils {
* @since 3.6 * @since 3.6
*/ */
public static String unwrap(final String str, final String wrapToken) { public static String unwrap(final String str, final String wrapToken) {
if (isEmpty(str) || isEmpty(wrapToken)) { if (isEmpty(str) || isEmpty(wrapToken) || str.length() == 1) {
return str; return str;
} }
@ -9224,6 +9227,7 @@ public class StringUtils {
final int startIndex = str.indexOf(wrapToken); final int startIndex = str.indexOf(wrapToken);
final int endIndex = str.lastIndexOf(wrapToken); final int endIndex = str.lastIndexOf(wrapToken);
final int wrapLength = wrapToken.length(); final int wrapLength = wrapToken.length();
if (startIndex != -1 && endIndex != -1) { if (startIndex != -1 && endIndex != -1) {
return str.substring(startIndex + wrapLength, endIndex); return str.substring(startIndex + wrapLength, endIndex);
} }

View File

@ -3073,6 +3073,8 @@ public class StringUtilsTest {
assertNull(StringUtils.unwrap(null, '1')); assertNull(StringUtils.unwrap(null, '1'));
assertEquals("abc", StringUtils.unwrap("abc", null)); assertEquals("abc", StringUtils.unwrap("abc", null));
assertEquals("a", StringUtils.unwrap("a", "a"));
assertEquals("", StringUtils.unwrap("aa", "a"));
assertEquals("abc", StringUtils.unwrap("\'abc\'", '\'')); assertEquals("abc", StringUtils.unwrap("\'abc\'", '\''));
assertEquals("abc", StringUtils.unwrap("AabcA", 'A')); assertEquals("abc", StringUtils.unwrap("AabcA", 'A'));
assertEquals("AabcA", StringUtils.unwrap("AAabcAA", 'A')); assertEquals("AabcA", StringUtils.unwrap("AAabcAA", 'A'));
@ -3090,6 +3092,8 @@ public class StringUtilsTest {
assertEquals("abc", StringUtils.unwrap("abc", null)); assertEquals("abc", StringUtils.unwrap("abc", null));
assertEquals("abc", StringUtils.unwrap("abc", "")); assertEquals("abc", StringUtils.unwrap("abc", ""));
assertEquals("a", StringUtils.unwrap("a", "a"));
assertEquals("", StringUtils.unwrap("aa", "a"));
assertEquals("abc", StringUtils.unwrap("\'abc\'", "\'")); assertEquals("abc", StringUtils.unwrap("\'abc\'", "\'"));
assertEquals("abc", StringUtils.unwrap("\"abc\"", "\"")); assertEquals("abc", StringUtils.unwrap("\"abc\"", "\""));
assertEquals("abc\"xyz", StringUtils.unwrap("\"abc\"xyz\"", "\"")); assertEquals("abc\"xyz", StringUtils.unwrap("\"abc\"xyz\"", "\""));