Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions common/string/RCString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ const char* RCString::GetString() const {
return nullptr;
}
}

RCString::operator const char*() const {
return this->GetString();
}
1 change: 1 addition & 0 deletions common/string/RCString.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class RCString : public TRefCnt {
void Copy(const RCString& source);
void Get(char* buf, size_t bufSize) const;
const char* GetString() const;
operator const char*() const;
};

#endif
9 changes: 9 additions & 0 deletions test/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,12 @@ TEST_CASE("RCString::GetString", "[string]") {
REQUIRE(rcStr1.GetString() != rcStr2.GetString());
}
}

TEST_CASE("RCString::operator const char*", "[string]") {
SECTION("casts a RCString object to a const char*") {
auto str = "foo";
RCString rcStr;
rcStr.Copy(str);
REQUIRE(!SStrCmp(str, (const char*)rcStr, STORM_MAX_STR));
}
}