[
https://issues.apache.org/jira/browse/LANG-1343?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17894737#comment-17894737
]
Capt. Cutlass commented on LANG-1343:
-------------------------------------
The OP’s statement seems incorrect. This example doesn’t relate to the first
and last characters or surrogate pairs. Having _maxWidth_ equal to 4 (with the
last 3 characters taken by "...") leaves only one place for the character. A
similar case is indeed described in the
[documentation|https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html#abbreviate(java.lang.String,int)].
{noformat}
Specifically:
* If the number of characters in the string is less than or equal to
maxWidth, return the string.
* Otherwise, abbreviate it to (substring(str, 0, max-3) + "...").
...
StringUtils.abbreviate("abcdefg", 4) = "a..."
{noformat}
CC: [~ggregory]
> StringUtils#abbreviate breaks up surrogate pairs
> ------------------------------------------------
>
> Key: LANG-1343
> URL: https://issues.apache.org/jira/browse/LANG-1343
> Project: Commons Lang
> Issue Type: Bug
> Components: lang.*
> Affects Versions: 3.6
> Reporter: Dominik Strecker
> Priority: Minor
>
> If the last char in the remaining substring is the first char of a surrogate
> pair, the resulting string has an illegal surrogate pair with the second char
> of the surrogate pair being the first char of the ellipsis.
> {code:java}
> StringUtils.abbreviate("\uD83D\uDCA9\uD83D\uDCA9\uD83D\uDCA9", 4); // returns
> "\uD83D..."
> {code}
> In my case this breaks further along when the string is transformed to UTF-8
> for a SOAP request.
> Should this at least be mentioned in the Javadoc?
--
This message was sent by Atlassian Jira
(v8.20.10#820010)