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::RFind does not work when using String::INVALID_INDEX as start index #82

Open
SamVanheer opened this issue Jun 16, 2021 · 0 comments

Comments

@SamVanheer
Copy link

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.

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