You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Bruno P. Kinoshita" <ki...@apache.org> on 2020/10/01 00:20:23 UTC

Re: [text] String substitution doesn't work with empty prefix and suffix

 >Note: The Javadoc says the var markers must not be null. So we could document null and empty as the same.

+1

I think it doesn't make much sense, and I think it also doesn't work. Maybe we should allow only for non-empty prefix/sufix?


Bruno

    On Thursday, 1 October 2020, 11:57:46 am NZDT, Gary Gregory <ga...@gmail.com> wrote:  
 
 Note: The Javadoc says the var markers must not be null. So we could document null and empty as the same.
The first question I have is how does this even make sense, both the start and end markers are empty strings... so... that matches each character in input since "a" starts with "" and ends with ""?
Gary
On Wed, Sep 30, 2020 at 6:46 PM Bruno P. Kinoshita <ki...@apache.org> wrote:

 Hi,
I reproduced the same behaviour on master branch of [text]. And indeed, found nothing in the javadoc that says what is the expected behaviour.
I think the class javadoc, as well as the setter javadoc would be good places to have such a documentation.
Let's see what others think about it, but if there are no objections, then we would need a JIRA issue to track this change (and pull requests would be welcome as well :)

Thanks!Bruno


    On Thursday, 1 October 2020, 10:49:52 am NZDT, Thomas Auinger <th...@auinger.de> wrote:  

 Hi,



I can run the following test without exception but it doesn't yield the
expected result. Also I can find no information that prefix and or suffix
must not be empty.



@Test
public void testNoPrefixAndSuffix() {
    final Map<String, String> map = new HashMap<>();
    map.put("name", "commons");
    assertEqualsCharSeq("Hi commons!", StringSubstitutor.replace("Hi name!",
map, "", ""));
}



Is that a bug?



Cheers

Thomas



  
  

Re: [text] String substitution doesn't work with empty prefix and suffix

Posted by Gary Gregory <ga...@gmail.com>.
On Wed, Sep 30, 2020 at 8:20 PM Bruno P. Kinoshita <ki...@apache.org> wrote:

> >Note: The Javadoc says the var markers must not be null. So we could
> document null and empty as the same.
>
> +1
>
> I think it doesn't make much sense, and I think it also doesn't work.
> Maybe we should allow only for non-empty prefix/sufix?
>

Let's think about the principle of least surprise:
- Don't look at the implementation now.
- What do you expect to happen for null variable prefix
- What do you expect to happen for null variable postfix
- As above for the empty string

For me, this is about _variable substitution_ and my expectation is that I
should be able to tell a variable from its surrounding text, so empty
strings fall into the noop category.
At that point, you might as well use String#replace().

Gary


>
>
> Bruno
>
> On Thursday, 1 October 2020, 11:57:46 am NZDT, Gary Gregory <
> garydgregory@gmail.com> wrote:
>
>
> Note: The Javadoc says the var markers must not be null. So we could
> document null and empty as the same.
>
> The first question I have is how does this even make sense, both the start
> and end markers are empty strings... so... that matches each character in
> input since "a" starts with "" and ends with ""?
>
> Gary
>
> On Wed, Sep 30, 2020 at 6:46 PM Bruno P. Kinoshita <ki...@apache.org>
> wrote:
>
>  Hi,
> I reproduced the same behaviour on master branch of [text]. And indeed,
> found nothing in the javadoc that says what is the expected behaviour.
> I think the class javadoc, as well as the setter javadoc would be good
> places to have such a documentation.
> Let's see what others think about it, but if there are no objections, then
> we would need a JIRA issue to track this change (and pull requests would be
> welcome as well :)
>
> Thanks!Bruno
>
>
>     On Thursday, 1 October 2020, 10:49:52 am NZDT, Thomas Auinger <
> thomas@auinger.de> wrote:
>
>  Hi,
>
>
>
> I can run the following test without exception but it doesn't yield the
> expected result. Also I can find no information that prefix and or suffix
> must not be empty.
>
>
>
> @Test
> public void testNoPrefixAndSuffix() {
>     final Map<String, String> map = new HashMap<>();
>     map.put("name", "commons");
>     assertEqualsCharSeq("Hi commons!", StringSubstitutor.replace("Hi
> name!",
> map, "", ""));
> }
>
>
>
> Is that a bug?
>
>
>
> Cheers
>
> Thomas
>
>
>
>
>
>