From 8f7208fa026d4ce8b71bc08f5fcfd2682934c7ac Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 21 Jan 2026 14:42:22 +0000 Subject: [PATCH] Add beginsWith helper to rdcinflexiblestr --- renderdoc/api/replay/rdcstr.h | 36 ++++++++++++++++++++++++++ renderdoc/replay/basic_types_tests.cpp | 6 +++++ 2 files changed, 42 insertions(+) diff --git a/renderdoc/api/replay/rdcstr.h b/renderdoc/api/replay/rdcstr.h index 6441cbb76..caf358ef5 100644 --- a/renderdoc/api/replay/rdcstr.h +++ b/renderdoc/api/replay/rdcstr.h @@ -1121,6 +1121,42 @@ public: bool empty() const { return c_str()[0] == 0; } const char *c_str() const { return (const char *)(uintptr_t)pointer; } size_t size() const { return strlen(c_str()); } + bool beginsWith(const char *beginning) const + { + if(!beginning) + return false; + + const char *a = c_str(); + const char *b = beginning; + + // empty string we're checking against, degenerate case but true + if(*b == 0) + return true; + + // if we are an empty string we don't match any non-empty prefix + if(*a == 0) + return false; + + while(*a && *b) + { + if(*a != *b) + return false; + + a++; + b++; + + // if we reached the end of beginning before hitting a difference, we do begin with it + if(*b == 0) + return true; + + // if we reached the end of our own string but beginning still has something left, we don't begin with it + if(*a == 0) + return false; + } + + // should never reach here + return false; + } operator rdcstr() const { if(is_literal == 0) diff --git a/renderdoc/replay/basic_types_tests.cpp b/renderdoc/replay/basic_types_tests.cpp index a8e88e1c2..2fdd7c6df 100644 --- a/renderdoc/replay/basic_types_tests.cpp +++ b/renderdoc/replay/basic_types_tests.cpp @@ -2112,6 +2112,12 @@ TEST_CASE("Test string type", "[basictypes][string]") CHECK_FALSE(test == rdcinflexiblestr("Hello, World!")); CHECK_FALSE(test.empty()); + CHECK(test.beginsWith("Hello")); + CHECK(test.beginsWith("")); + CHECK_FALSE(test.beginsWith(NULL)); + CHECK_FALSE(test.beginsWith("Hello!")); + CHECK_FALSE(test.beginsWith("Hello, World!!")); + rdcstr str = test; CHECK(str == "Hello, World");