[jira] Created: (LANG-622) StringUtils.lastIndexOfAnyBut() function desired

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] Created: (LANG-622) StringUtils.lastIndexOfAnyBut() function desired

ASF GitHub Bot (Jira)
StringUtils.lastIndexOfAnyBut() function desired
------------------------------------------------

                 Key: LANG-622
                 URL: https://issues.apache.org/jira/browse/LANG-622
             Project: Commons Lang
          Issue Type: Improvement
            Reporter: david cogen
            Priority: Minor


class StringUtils needs the function lastIndexOfAnyBut()
This would be like indexOfAnyBut() except searches from the end rather than the beginning.
It would be like lastIndexOfAny() except looks for a character other than those in the string rather than for those in the string.

This is the only one of the four combinations of "from beginning"/"from end" and "for any"/"for any but" that is not provided.

Interestingly, the class header doc. mentions "LastIndexOfAnyBut" but the function does not exist - even as a private, as determined by class introspection.

(This is not a frivolous request. I actually did need this function and ended up having to code a search loop.)


--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (LANG-622) StringUtils.lastIndexOfAnyBut() function desired

ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/LANG-622?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated LANG-622:
-------------------------------

    Component/s: lang.*

> StringUtils.lastIndexOfAnyBut() function desired
> ------------------------------------------------
>
>                 Key: LANG-622
>                 URL: https://issues.apache.org/jira/browse/LANG-622
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>            Reporter: david cogen
>            Priority: Minor
>
> class StringUtils needs the function lastIndexOfAnyBut()
> This would be like indexOfAnyBut() except searches from the end rather than the beginning.
> It would be like lastIndexOfAny() except looks for a character other than those in the string rather than for those in the string.
> This is the only one of the four combinations of "from beginning"/"from end" and "for any"/"for any but" that is not provided.
> Interestingly, the class header doc. mentions "LastIndexOfAnyBut" but the function does not exist - even as a private, as determined by class introspection.
> (This is not a frivolous request. I actually did need this function and ended up having to code a search loop.)

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (LANG-622) StringUtils.lastIndexOfAnyBut() function desired

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/LANG-622?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated LANG-622:
-------------------------------

    Fix Version/s: 3.1

Seems good - putting in 3.1 as no patches currently. Patches welcome for anyone who wants to work on it.

> StringUtils.lastIndexOfAnyBut() function desired
> ------------------------------------------------
>
>                 Key: LANG-622
>                 URL: https://issues.apache.org/jira/browse/LANG-622
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>            Reporter: david cogen
>            Priority: Minor
>             Fix For: 3.1
>
>
> class StringUtils needs the function lastIndexOfAnyBut()
> This would be like indexOfAnyBut() except searches from the end rather than the beginning.
> It would be like lastIndexOfAny() except looks for a character other than those in the string rather than for those in the string.
> This is the only one of the four combinations of "from beginning"/"from end" and "for any"/"for any but" that is not provided.
> Interestingly, the class header doc. mentions "LastIndexOfAnyBut" but the function does not exist - even as a private, as determined by class introspection.
> (This is not a frivolous request. I actually did need this function and ended up having to code a search loop.)

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (LANG-622) StringUtils.lastIndexOfAnyBut() function desired

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

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

Minhaj Mehmood commented on LANG-622:
-------------------------------------

I've gone through the StringUtils source code and found that just minor changes required to acquire such behavior, check code below.

Following methods could be add to StringUtils class.
public static int lastIndexOfAnyBut(CharSequence cs, char[] searchChars) {
        int ret = INDEX_NOT_FOUND;
       
    if (isEmpty(cs) || ArrayUtils.isEmpty(searchChars)) {
        return ret;
    }
    int csLen = cs.length();
    int csLast = csLen - 1;
    int searchLen = searchChars.length;
    int searchLast = searchLen - 1;
    outer:
    for (int i = 0; i < csLen; i++) {
        char ch = cs.charAt(i);
        for (int j = 0; j < searchLen; j++) {
            if (searchChars[j] == ch) {
                if (i < csLast && j < searchLast && Character.isHighSurrogate(ch)) {
                    if (searchChars[j + 1] == cs.charAt(i + 1)) {
                        continue outer;
                    }
                } else {
                    continue outer;
                }
            }
        }
        ret = i;
    }
    return ret;
}

public static int lastIndexOfAnyBut(String str, String searchChars) {
        int ret = INDEX_NOT_FOUND;
    if (isEmpty(str) || isEmpty(searchChars)) {
        return ret;
    }
    int strLen = str.length();
    for (int i = 0; i < strLen; i++) {
        char ch = str.charAt(i);
        boolean chFound = searchChars.indexOf(ch) >= 0;
        if (i + 1 < strLen && Character.isHighSurrogate(ch)) {
            char ch2 = str.charAt(i + 1);
            if (chFound && searchChars.indexOf(ch2) < 0) {
                ret = i;
            }
        } else {
            if (!chFound) {
            ret = i;
            }
        }
    }
    return ret;
}

> StringUtils.lastIndexOfAnyBut() function desired
> ------------------------------------------------
>
>                 Key: LANG-622
>                 URL: https://issues.apache.org/jira/browse/LANG-622
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>            Reporter: david cogen
>            Priority: Minor
>             Fix For: 3.1
>
>
> class StringUtils needs the function lastIndexOfAnyBut()
> This would be like indexOfAnyBut() except searches from the end rather than the beginning.
> It would be like lastIndexOfAny() except looks for a character other than those in the string rather than for those in the string.
> This is the only one of the four combinations of "from beginning"/"from end" and "for any"/"for any but" that is not provided.
> Interestingly, the class header doc. mentions "LastIndexOfAnyBut" but the function does not exist - even as a private, as determined by class introspection.
> (This is not a frivolous request. I actually did need this function and ended up having to code a search loop.)

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (LANG-622) StringUtils.lastIndexOfAnyBut() function desired

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/LANG-622?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Minhaj Mehmood updated LANG-622:
--------------------------------

    Attachment: StringUtilslLastIndexOfAnyButTest.java

Test class for the methods lastIndexOfAnyBut(String, String) and lastIndexOfAnyBut(CharSequence char[]).

> StringUtils.lastIndexOfAnyBut() function desired
> ------------------------------------------------
>
>                 Key: LANG-622
>                 URL: https://issues.apache.org/jira/browse/LANG-622
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>            Reporter: david cogen
>            Priority: Minor
>             Fix For: 3.1
>
>         Attachments: StringUtilslLastIndexOfAnyButTest.java
>
>
> class StringUtils needs the function lastIndexOfAnyBut()
> This would be like indexOfAnyBut() except searches from the end rather than the beginning.
> It would be like lastIndexOfAny() except looks for a character other than those in the string rather than for those in the string.
> This is the only one of the four combinations of "from beginning"/"from end" and "for any"/"for any but" that is not provided.
> Interestingly, the class header doc. mentions "LastIndexOfAnyBut" but the function does not exist - even as a private, as determined by class introspection.
> (This is not a frivolous request. I actually did need this function and ended up having to code a search loop.)

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.