Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String.h function lastIndexOf return value is not correct #51

Open
hunteras opened this issue Oct 6, 2016 · 0 comments
Open

String.h function lastIndexOf return value is not correct #51

hunteras opened this issue Oct 6, 2016 · 0 comments

Comments

@hunteras
Copy link

hunteras commented Oct 6, 2016

size_t lastIndexOf(char ch, size_t from = npos, CaseSensitivity cs = CaseSensitive) const
{
    if (cs == CaseSensitive)
        return mString.rfind(ch, from == npos ? std::string::npos : size_t(from));
    const char *data = mString.c_str();
    if (from == npos)
        from = mString.size() - 1;
    ch = tolower(ch);
    int f = static_cast<int>(from);
    while (f >= 0) {
        if (tolower(data[f]) == ch)
            return **from**;
        --f;
    }
    return npos;
}

this function should return f instead of from, from is always size() - 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant