[
https://issues.apache.org/jira/browse/LANG-1679?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
clover updated LANG-1679:
-------------------------
Description:
public static String unwrap(final String str, final String wrapToken) {
if (isEmpty(str) || isEmpty(wrapToken) || str.length() < 2 *
wrapToken.length())
{ return str; }
if (startsWith(str, wrapToken) && endsWith(str, wrapToken)) {
{color:#de350b} // When we come here, startIndex must be 0. Thus,
startIndex is redundant.{color}
final int startIndex = str.indexOf(wrapToken);
{color:#ff0000} final int endIndex =
str.lastIndexOf(wrapToken);{color}
final int wrapLength = wrapToken.length();
{color:#172b4d} {color:#de350b}// (startIndex != -1 && endIndex !=
-1) is always true{color}{color}
{color:#ff0000} if (startIndex != -1 && endIndex != -1) {{color}
{color:#ff0000} return str.substring(startIndex + wrapLength,
endIndex);{color}
{color:#ff0000} }{color}
}
return str;
}
*As commented above, unwrap() could be improved:*
public static String unwrap(final String str, final String wrapToken) {
if (isEmpty(str) || isEmpty(wrapToken) || str.length() < 2 *
wrapToken.length()) \{ return str; }
if (startsWith(str, wrapToken) && endsWith(str, wrapToken)) {
{color:#ff0000} return str.substring(wrapToken.length(),
str.lastIndexOf(wrapToken));{color}
{color:#ff0000} }{color}
}
return str;
}
was:
public static String unwrap(final String str, final String wrapToken) {
if (isEmpty(str) || isEmpty(wrapToken) || str.length() < 2 *
wrapToken.length()) {
return str;
}
if (startsWith(str, wrapToken) && endsWith(str, wrapToken)) {
{color:#de350b} // When we come here,
{color}{color:#FF0000}{color:#de350b}s{color}tartIndex must be 0. Thus,
startIndex is redundant.{color}
{color:#FF0000}final int startIndex = str.indexOf(wrapToken);{color}
{color:#FF0000} {color:#172b4d} final int endIndex =
str.lastIndexOf(wrapToken);{color}{color}
{color:#172b4d} final int wrapLength = wrapToken.length();{color}
{color:#172b4d}{color:#de350b} // {color:#FF0000}(startIndex != -1 &&
endIndex != -1) is always true{color}{color}{color}
{color:#FF0000} if (startIndex != -1 && endIndex != -1) {{color}
{color:#FF0000} return str.substring(startIndex + wrapLength,
endIndex);{color}
{color:#FF0000} }{color}
}
return str;
}
*As commented above, unwrap() could be improved:*
public static String unwrap(final String str, final String wrapToken) {
if (isEmpty(str) || isEmpty(wrapToken) || str.length() < 2 *
wrapToken.length()) {
return str;
}
if (startsWith(str, wrapToken) && endsWith(str, wrapToken)) {
{color:#FF0000} return str.substring(wrapToken.length(),
str.lastIndexOf(wrapToken));{color}
{color:#FF0000} }{color}
}
return str;
}
> StringUtils.unwrap() may be implemented faster
> ----------------------------------------------
>
> Key: LANG-1679
> URL: https://issues.apache.org/jira/browse/LANG-1679
> Project: Commons Lang
> Issue Type: Improvement
> Reporter: clover
> Priority: Minor
>
> public static String unwrap(final String str, final String wrapToken) {
> if (isEmpty(str) || isEmpty(wrapToken) || str.length() < 2 *
> wrapToken.length())
> { return str; }
> if (startsWith(str, wrapToken) && endsWith(str, wrapToken)) {
> {color:#de350b} // When we come here, startIndex must be 0. Thus,
> startIndex is redundant.{color}
> final int startIndex = str.indexOf(wrapToken);
> {color:#ff0000} final int endIndex =
> str.lastIndexOf(wrapToken);{color}
> final int wrapLength = wrapToken.length();
> {color:#172b4d} {color:#de350b}// (startIndex != -1 && endIndex !=
> -1) is always true{color}{color}
> {color:#ff0000} if (startIndex != -1 && endIndex != -1) {{color}
> {color:#ff0000} return str.substring(startIndex + wrapLength,
> endIndex);{color}
> {color:#ff0000} }{color}
> }
> return str;
> }
>
> *As commented above, unwrap() could be improved:*
> public static String unwrap(final String str, final String wrapToken) {
> if (isEmpty(str) || isEmpty(wrapToken) || str.length() < 2 *
> wrapToken.length()) \{ return str; }
> if (startsWith(str, wrapToken) && endsWith(str, wrapToken)) {
> {color:#ff0000} return str.substring(wrapToken.length(),
> str.lastIndexOf(wrapToken));{color}
> {color:#ff0000} }{color}
> }
> return str;
> }
--
This message was sent by Atlassian Jira
(v8.20.1#820001)