mirror of
https://github.com/WerWolv/ImHex-Patterns.git
synced 2026-03-27 23:37:04 -05:00
includes/std: Added checks to ends_with and starts_with to prevent failure (#295)
Fixing cases where part is longer than string, this cases should both return false instead of failing. Co-authored-by: Nik <werwolv98@gmail.com>
This commit is contained in:
@@ -125,6 +125,8 @@ namespace auto std::string {
|
||||
@return True if the string starts with the substring, false otherwise.
|
||||
*/
|
||||
fn starts_with(str string, str part) {
|
||||
if (std::string::length(string) < std::string::length(part))
|
||||
return false;
|
||||
return std::string::substr(string, 0, std::string::length(part)) == part;
|
||||
};
|
||||
|
||||
@@ -135,6 +137,8 @@ namespace auto std::string {
|
||||
@return True if the string ends with the substring, false otherwise.
|
||||
*/
|
||||
fn ends_with(str string, str part) {
|
||||
if (std::string::length(string) < std::string::length(part))
|
||||
return false;
|
||||
return std::string::substr(string, std::string::length(string) - std::string::length(part), std::string::length(part)) == part;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user