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

feat(string): add assignment operator for const char* r-value #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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;
}
}

void RCString::operator=(const char* rval) {
this->Copy(rval);
}
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;
void operator=(const char* rval);
};

#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=", "string") {
SECTION("assigns the value of const char* rval to the calling RCString object") {
auto str = "foo";
RCString rcStr;
rcStr = str;
REQUIRE(!SStrCmp(str, rcStr.GetString(), STORM_MAX_STR));
}
}