You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/12/05 17:20:07 UTC
[commons-lang] branch master updated: LANG-1619 - refine
StringUtils.abbreviate (#663)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push:
new dd7f02f LANG-1619 - refine StringUtils.abbreviate (#663)
dd7f02f is described below
commit dd7f02feac27aef5ba05cb1a3ab52206ee11fe10
Author: Arturo Bernal <ar...@gmail.com>
AuthorDate: Sat Dec 5 18:20:00 2020 +0100
LANG-1619 - refine StringUtils.abbreviate (#663)
---
src/main/java/org/apache/commons/lang3/StringUtils.java | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java
index 93e8407..d96c5fe 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -349,14 +349,15 @@ public class StringUtils {
if (maxWidth < minAbbrevWidth) {
throw new IllegalArgumentException(String.format("Minimum abbreviation width is %d", minAbbrevWidth));
}
- if (str.length() <= maxWidth) {
+ final int strLen = str.length();
+ if (strLen <= maxWidth) {
return str;
}
- if (offset > str.length()) {
- offset = str.length();
+ if (offset > strLen) {
+ offset = strLen;
}
- if (str.length() - offset < maxWidth - abbrevMarkerLength) {
- offset = str.length() - (maxWidth - abbrevMarkerLength);
+ if (strLen - offset < maxWidth - abbrevMarkerLength) {
+ offset = strLen - (maxWidth - abbrevMarkerLength);
}
if (offset <= abbrevMarkerLength+1) {
return str.substring(0, maxWidth - abbrevMarkerLength) + abbrevMarker;
@@ -364,10 +365,10 @@ public class StringUtils {
if (maxWidth < minAbbrevWidthOffset) {
throw new IllegalArgumentException(String.format("Minimum abbreviation width with offset is %d", minAbbrevWidthOffset));
}
- if (offset + maxWidth - abbrevMarkerLength < str.length()) {
+ if (offset + maxWidth - abbrevMarkerLength < strLen) {
return abbrevMarker + abbreviate(str.substring(offset), abbrevMarker, maxWidth - abbrevMarkerLength);
}
- return abbrevMarker + str.substring(str.length() - (maxWidth - abbrevMarkerLength));
+ return abbrevMarker + str.substring(strLen - (maxWidth - abbrevMarkerLength));
}
/**