Github user rikles commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/75#discussion_r30461235
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -3277,6 +3277,164 @@ public static String substringBetween(final String 
str, final String open, final
             return list.toArray(new String[list.size()]);
         }
     
    +    /**
    +     * <p>Split a String into an array, using an array of fixed string 
lengths.</p>
    +     *
    +     * <p>If not null String input, the returned array size is same as the 
input lengths array.</p>
    +     *
    +     * <p>A null input String returns {@code null}.
    +     * A {@code null} or empty input lengths array returns an empty array.
    +     * A {@code 0} in the input lengths array results in en empty 
string.</p>
    +     *
    +     * <p>Extra characters are ignored (ie String length greater than sum 
of split lengths).
    +     * All empty substrings other than zero length requested, are returned 
{@code null}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.splitByLength(null, *)      = null
    +     * StringUtils.splitByLength("abc")        = []
    +     * StringUtils.splitByLength("abc", null)  = []
    +     * StringUtils.splitByLength("abc", [])    = []
    +     * StringUtils.splitByLength("", 2, 4, 1)  = [null, null, null]
    +     *
    +     * StringUtils.splitByLength("abcdefg", 2, 4, 1)     = ["ab", "cdef", 
"g"]
    +     * StringUtils.splitByLength("abcdefghij", 2, 4, 1)  = ["ab", "cdef", 
"g"]
    +     * StringUtils.splitByLength("abcdefg", 2, 4, 5)     = ["ab", "cdef", 
"g"]
    +     * StringUtils.splitByLength("abcdef", 2, 4, 1)      = ["ab", "cdef", 
null]
    +     *
    +     * StringUtils.splitByLength(" abcdef", 2, 4, 1)     = [" a", "bcde", 
"f"]
    +     * StringUtils.splitByLength("abcdef ", 2, 4, 1)     = ["ab", "cdef", 
" "]
    +     * StringUtils.splitByLength("abcdefg", 2, 4, 0, 1)  = ["ab", "cdef", 
"", "g"]
    +     * StringUtils.splitByLength("abcdefg", -1)          = {@link 
IllegalArgumentException}
    --- End diff --
    
    It's true that negative numbers could be easily promotes to 0.
    But here, it's not like in `StringUtils.split(String, String, int)` where 
the int value indicate the maximum number of results we want. It's very common 
that passing a zero or negative value mean _no limit_.
    Here, we request several "column" lengths. I thought it was natural and 
easier to consider negative lengths as a coding mistake.
    
    I even wondered if we could interpret negative values like :
      * _unlimited length_. But what about 
`StringUtils.splitByLength("abcdefg", -1, 2, -1, -1)` ... ?
      * _backward move_ like `StringUtils.splitByLength("abcde", 3, -2, 4) = 
["abc", "bcde"]`. But what about `StringUtils.splitByLength("abcdef", 1, -4, 
3)` ... ?
    
    I don't know what to think about it...


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to