Provide a public method to get StringRef's underlying pointer

This allows reducing the amount of friends needed for its interface
and some extra tricks later.

The bad part is that the pointer can become invalidated via
calls to other StringRef's public methods, but c'est la vie.
This commit is contained in:
Martin Hořeňovský 2018-02-28 22:05:01 +01:00
parent 950ccf4749
commit 05cd05743a
6 changed files with 21 additions and 26 deletions

View file

@ -43,7 +43,7 @@ namespace Catch {
const_cast<StringRef*>( this )->takeOwnership();
return m_start;
}
auto StringRef::data() const noexcept -> char const* {
auto StringRef::currentData() const noexcept -> char const* {
return m_start;
}
@ -112,11 +112,11 @@ namespace Catch {
}
auto operator << ( std::ostream& os, StringRef const& str ) -> std::ostream& {
return os.write(str.m_start, str.m_size);
return os.write(str.currentData(), str.size());
}
auto operator+=( std::string& lhs, StringRef const& rhs ) -> std::string& {
lhs.append(rhs.m_start, rhs.m_size);
lhs.append(rhs.currentData(), rhs.size());
return lhs;
}