Skip to content

string::RFind does not work when using String::INVALID_INDEX as start index #82

Description

@SamVanheer

The string::RFind method does not work properly when using String::INVALID_INDEX as the start index. This is the default value for RFind and is intended to start looking at the end of the string.

Instead it just returns String::INVALID_INDEX. This is because the method does not actually handle the String::INVALID_INDEX value correctly like std::string::rfind does:
https://github.com/Solokiller/HL_Tools/blob/a028f420f535c086eb22a9c0ee5d026f57dd4b8f/src/stdlib/utility/CString.cpp#L796-L825

string::FindLastOf does work correctly, but is not a replacement for RFind.

Here's an example where it returns the wrong value:

string hostname = "Sven Co-op listen server | diff: 95%";
		
uint index = hostname.RFind("|");

index should be 25 but is actually String::INVALID_INDEX.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions