commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joanne Polsky (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (LANG-875) StringUtils: Include methods for appending suffix or prepending a prefix if not already present
Date Fri, 12 Apr 2013 21:38:15 GMT

    [ https://issues.apache.org/jira/browse/LANG-875?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13630659#comment-13630659
] 

Joanne Polsky edited comment on LANG-875 at 4/12/13 9:36 PM:
-------------------------------------------------------------

Hi Seth,

I've added another patch, LANG-875-moretests1.patch, with those additional tests that you
mentioned.

The code is working as designed but maybe it's not consistent with the other methods.

I was treating null as empty string.  Since all non empty strings start/end with empty string
technically the return result will simply be the same string supplied.  These methods are
essentially useless if someone puts empty or null strings in the list of suffixes/prefixes.
For instance,

    appendIfMissing("file", ".txt", new CharSequence[]{null}) = "file"

I was looking at endsWith method and it seems like they don't treat null and empty string
the same:

    assertFalse("endsWith(FOOBAR, null)", StringUtils.endsWith(FOOBAR, (String)null));
    assertTrue("endsWith(FOOBAR, \"\")",  StringUtils.endsWith(FOOBAR, ""));

That change could involve simply falling back to whatever endsWith returns -

Replacing:
7125                 if (isEmpty(s) || endsWith(str, s, ignoreCase)) {

With:
7125                 if (endsWith(str, s, ignoreCase)) {

Let me know what you think?

                
      was (Author: jpolsky):
    Hi Seth,

I've added another patch, LANG-875-moretests1.patch, with those additional tests that you
mentioned.

The code is working as designed but maybe it's not consistent with the other methods.

I was treating null as empty string.  Since all non empty strings start/end with empty string
technically the return result will simply be the same string supplied.  These methods are
essentially useless if someone puts empty or null strings in the list of suffixes/prefixes.
For instance,
appendIfMissing("file", ".txt", new CharSequence[]{null}) = "file"

I was looking at endsWith method and it seems like they don't treat null and empty string
the same:

assertFalse("endsWith(FOOBAR, null)", StringUtils.endsWith(FOOBAR, (String)null));
assertTrue("endsWith(FOOBAR, \"\")",  StringUtils.endsWith(FOOBAR, ""));

That change could involve simply falling back to whatever endsWith returns -

Replacing:
7125                 if (isEmpty(s) || endsWith(str, s, ignoreCase)) {

With:
7125                 if (endsWith(str, s, ignoreCase)) {

Let me know what you think?

                  
> StringUtils: Include methods for appending suffix or prepending a prefix if not already
present
> -----------------------------------------------------------------------------------------------
>
>                 Key: LANG-875
>                 URL: https://issues.apache.org/jira/browse/LANG-875
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 3.1
>            Reporter: Joanne Polsky
>            Priority: Minor
>             Fix For: 3.2
>
>         Attachments: LANG-875-moretests1.patch, LANG-875-noany.patch, LANG-875.patch
>
>
> StringUtils has various methods to checking and removing a substring from the start/end
of a string but nothing for appending.  These methods will append a suffix to the end or prepend
a prefix to the start of the string if not already present.
> The methods would include:
> - appendIfMissing
> - appendIfMissingAny
> - appendIfMissingIgnoreCase
> - appendIfMissingAnyIgnoreCase
> - prependIfMissing
> - prependIfMissingAny
> - prependIfMissingIgnoreCase
> - prependIfMissingAnyIgnoreCase

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message