commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LANG-1304) Add a method in StringUtils to check for mixed case in string
Date Fri, 30 Dec 2016 03:38:58 GMT

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

ASF GitHub Bot commented on LANG-1304:
--------------------------------------

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

    https://github.com/apache/commons-lang/pull/223#discussion_r94200421
  
    --- 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 --
    
    Almost, because consider the string "aB\n":
    It does contain a lowercase, then an uppercase, but it also contains the character '\n',
which is a neither lower or uppercase. Breaking early would miss this case.


> Add a method in StringUtils to check for mixed case in string
> -------------------------------------------------------------
>
>                 Key: LANG-1304
>                 URL: https://issues.apache.org/jira/browse/LANG-1304
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Arshad Basha
>            Priority: Minor
>             Fix For: 3.6
>
>
> It would be nice to have a method that check whether the string has mixed (lower and
upper) case.
> Examples:
> StringUtils.isMixedCase("passWORD"); //true
> StringUtils.isMixedCase("PASSWORD"); //false
> StringUtils.isMixedCase("password"); //false



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message