You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Mitth'raw'nuruodo (JIRA)" <ji...@apache.org> on 2017/09/06 02:08:00 UTC

[jira] [Updated] (LANG-1345) Add methods to enhance non-empty strings

     [ https://issues.apache.org/jira/browse/LANG-1345?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mitth'raw'nuruodo updated LANG-1345:
------------------------------------
    Description: 
As a corollary to {{defaultString}}, {{appendIfMissing}}, and similar methods, which allow the client to replace a missing string with something, it would sometimes be helpful to have methods that enhance a string, if it is present, with a prefix and suffix (or perhaps with an arbitrary function).

Eg
{code}
if (StringUtils.isNotEmpty(queryString)) {
    return url + "?" + queryString;
} else {
    return url;
}
{code}
would become:
{code}
return url + StringUtils.addIfNotEmpty(queryString, "?", null);
{code}

with the second parameter being the prefix, and the third, the suffix. If the string is null or empty, return empty string.

If this could accept arbitrary transformation functions, it could effectively become the Elvis operator.


  was:
As a corollary to {{defaultString}} and similar methods, which allow the client to replace a missing string with something, it would sometimes be helpful to have methods that enhance a string, if it is present, with a prefix and suffix (or perhaps with an arbitrary function).

Eg
{code}
if (StringUtils.isNotEmpty(queryString)) {
    return url + "?" + queryString;
} else {
    return url;
}
{code}
would become:
{code}
return url + StringUtils.addIfNotEmpty(queryString, "?", null);
{code}

with the second parameter being the prefix, and the third, the suffix. If the string is null or empty, return empty string.

If this could accept arbitrary transformation functions, it could effectively become the Elvis operator.


> Add methods to enhance non-empty strings
> ----------------------------------------
>
>                 Key: LANG-1345
>                 URL: https://issues.apache.org/jira/browse/LANG-1345
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>            Reporter: Mitth'raw'nuruodo
>            Priority: Minor
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> As a corollary to {{defaultString}}, {{appendIfMissing}}, and similar methods, which allow the client to replace a missing string with something, it would sometimes be helpful to have methods that enhance a string, if it is present, with a prefix and suffix (or perhaps with an arbitrary function).
> Eg
> {code}
> if (StringUtils.isNotEmpty(queryString)) {
>     return url + "?" + queryString;
> } else {
>     return url;
> }
> {code}
> would become:
> {code}
> return url + StringUtils.addIfNotEmpty(queryString, "?", null);
> {code}
> with the second parameter being the prefix, and the third, the suffix. If the string is null or empty, return empty string.
> If this could accept arbitrary transformation functions, it could effectively become the Elvis operator.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)