mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-03 22:05:39 +02:00
Remove StringRef::isNullTerminated and StringRef::c_str
Both of them were fundamentally unsafe to use and shouldn't be used at all.
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
#include <catch2/internal/catch_enforce.hpp>
|
||||
#include <catch2/internal/catch_stringref.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -18,11 +17,6 @@ namespace Catch {
|
||||
: StringRef( rawChars, static_cast<StringRef::size_type>(std::strlen(rawChars) ) )
|
||||
{}
|
||||
|
||||
auto StringRef::c_str() const -> char const* {
|
||||
CATCH_ENFORCE(isNullTerminated(), "Called StringRef::c_str() on a non-null-terminated instance");
|
||||
return m_start;
|
||||
}
|
||||
|
||||
auto StringRef::operator == ( StringRef const& other ) const noexcept -> bool {
|
||||
return m_size == other.m_size
|
||||
&& (std::memcmp( m_start, other.m_start, m_size ) == 0);
|
||||
|
@@ -69,10 +69,6 @@ namespace Catch {
|
||||
return m_size;
|
||||
}
|
||||
|
||||
// Returns the current start pointer. If the StringRef is not
|
||||
// null-terminated, throws std::domain_exception
|
||||
auto c_str() const -> char const*;
|
||||
|
||||
public: // substrings and searches
|
||||
// Returns a substring of [start, start + length).
|
||||
// If start + length > size(), then the substring is [start, start + size()).
|
||||
@@ -91,10 +87,6 @@ namespace Catch {
|
||||
return m_start;
|
||||
}
|
||||
|
||||
constexpr auto isNullTerminated() const noexcept -> bool {
|
||||
return m_start[m_size] == '\0';
|
||||
}
|
||||
|
||||
public: // iterators
|
||||
constexpr const_iterator begin() const { return m_start; }
|
||||
constexpr const_iterator end() const { return m_start + m_size; }
|
||||
|
Reference in New Issue
Block a user