[ 
https://issues.apache.org/jira/browse/LANG-1619?focusedWorklogId=520521&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-520521
 ]

ASF GitHub Bot logged work on LANG-1619:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 05/Dec/20 17:20
            Start Date: 05/Dec/20 17:20
    Worklog Time Spent: 10m 
      Work Description: garydgregory merged pull request #663:
URL: https://github.com/apache/commons-lang/pull/663


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 520521)
    Time Spent: 50m  (was: 40m)

> refine StringUtils.abbreviate
> -----------------------------
>
>                 Key: LANG-1619
>                 URL: https://issues.apache.org/jira/browse/LANG-1619
>             Project: Commons Lang
>          Issue Type: Improvement
>            Reporter: Arturo Bernal
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> Avoid Multiple calls to calculate the length of the chain
>  
> [https://github.com/apache/commons-lang/pull/663]
> {code:java}
>  public static String abbreviate(final String str, final String abbrevMarker, 
> int offset, final int maxWidth) {
>         if (isNotEmpty(str) && EMPTY.equals(abbrevMarker) && maxWidth > 0) {
>             return substring(str, 0, maxWidth);
>         } else if (isAnyEmpty(str, abbrevMarker)) {
>             return str;
>         }
>         final int abbrevMarkerLength = abbrevMarker.length();
>         final int minAbbrevWidth = abbrevMarkerLength + 1;
>         final int minAbbrevWidthOffset = abbrevMarkerLength + 
> abbrevMarkerLength + 1;
>         if (maxWidth < minAbbrevWidth) {
>             throw new IllegalArgumentException(String.format("Minimum 
> abbreviation width is %d", minAbbrevWidth));
>         }
>         final int strLen = str.length();
>         if (strLen <= maxWidth) {
>             return str;
>         }
>         if (offset > strLen) {
>             offset = strLen;
>         }
>         if (strLen - offset < maxWidth - abbrevMarkerLength) {
>             offset = strLen - (maxWidth - abbrevMarkerLength);
>         }
>         if (offset <= abbrevMarkerLength+1) {
>             return str.substring(0, maxWidth - abbrevMarkerLength) + 
> abbrevMarker;
>         }
>         if (maxWidth < minAbbrevWidthOffset) {
>             throw new IllegalArgumentException(String.format("Minimum 
> abbreviation width with offset is %d", minAbbrevWidthOffset));
>         }
>         if (offset + maxWidth - abbrevMarkerLength < strLen) {
>             return abbrevMarker + abbreviate(str.substring(offset), 
> abbrevMarker, maxWidth - abbrevMarkerLength);
>         }
>         return abbrevMarker + str.substring(strLen - (maxWidth - 
> abbrevMarkerLength));
>     }
> {code}
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to