[BUG] String


#1

First of all - great library ! :slight_smile:

It seems there are few bugs in these functions

const String String::fromFirstOccurrenceOf (const tchar* const sub,
                                            const bool includeSubString,
                                            const bool ignoreCase) const throw()
{
    //Error here?
    const int i = ignoreCase ? indexOf (sub)
                             : indexOfIgnoreCase (sub);

    if (i < 0)
        return empty;
    else
        return substring ((includeSubString) ? i : i + CharacterFunctions::length (sub));
}


const String String::fromLastOccurrenceOf (const tchar* const sub,
                                           const bool includeSubString,
                                           const bool ignoreCase) const throw()
{
    //Error here?
    const int i = ignoreCase ? lastIndexOf (sub)
                             : lastIndexOfIgnoreCase (sub);

    if (i < 0)
        return *this;
    else
        return substring ((includeSubString) ? i : i + CharacterFunctions::length (sub));
}

shoudn’t these be something like this

const String String::fromFirstOccurrenceOf (const tchar* const sub,
                                            const bool includeSubString,
                                            const bool ignoreCase) const throw()
{
    const int i = ignoreCase ? indexOfIgnoreCase  (sub)
                             : indexOf(sub);

    if (i < 0)
        return empty;
    else
        return substring ((includeSubString) ? i : i + CharacterFunctions::length (sub));
}


const String String::fromLastOccurrenceOf (const tchar* const sub,
                                           const bool includeSubString,
                                           const bool ignoreCase) const throw()
{
    const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
                             : lastIndexOf(sub);

    if (i < 0)
        return *this;
    else
        return substring ((includeSubString) ? i : i + CharacterFunctions::length (sub));
}

#2

:oops:

Wow. I can’t believe:
a) that I’d make such a dumb typo
b) it’d sit there in the code for at least a couple of years without anyone noticing!

But thanks very much for spotting it!