commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bindul <...@git.apache.org>
Subject [GitHub] commons-lang pull request #223: [LANG-1304] StringUtils method to check for ...
Date Fri, 30 Dec 2016 04:07:20 GMT
Github user bindul commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/223#discussion_r94201247
  
    --- Diff: src/main/java/org/apache/commons/lang3/StringUtils.java ---
    @@ -7193,6 +7193,45 @@ public static boolean isAllUpperCase(final CharSequence cs) {
             return true;
         }
     
    +    /**
    +     * <p>Checks if the CharSequence contains mixed casing of both uppercase and
lowercase characters.</p>
    +     *
    +     * <p>{@code null} will return {@code false}.
    +     * An empty String (length()=0) will return {@code false}.</p>
    +     *
    +     * <pre>
    +     * StringUtils.isMixedCase(null)    = false
    +     * StringUtils.isMixedCase("")      = false
    +     * StringUtils.isMixedCase("aBc")   = true
    +     * StringUtils.isMixedCase("ABC")   = false
    +     * StringUtils.isMixedCase("abc")   = false
    +     * StringUtils.isMixedCase("A c")   = false
    +     * StringUtils.isMixedCase("A1c")   = false
    +     * StringUtils.isMixedCase("a/C")   = false
    +     * </pre>
    +     *
    +     * @param cs the CharSequence to check, may be null
    +     * @return {@code true} if contains both uppercase and lowercase characters, and
is non-null
    +     */
    +    public static boolean isMixedCase(final CharSequence cs) {
    +        if (cs == null || isEmpty(cs)) {
    +            return false;
    +        }
    +        boolean containsUppercase = false;
    +        boolean containsLowercase = false;
    +        final int sz = cs.length();
    +        for (int i = 0; i < sz; i++) {
    --- End diff --
    
    In which case the name of the method should probably be changed? With a method name like
`isMixedCase`, I would expect a return value of `true`.
    With your test string, yes there is the `\n` which is neither upper case or lower case,
but the string has `a` and `B`, so it is mixed case.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message