SmallString: Add span helpers
This commit is contained in:
parent
d3246deb77
commit
ff3214b8f7
|
@ -506,6 +506,26 @@ std::wstring SmallStringBase::wstring() const
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
std::span<const char> SmallStringBase::cspan() const
|
||||||
|
{
|
||||||
|
return std::span<const char>(m_buffer, m_length);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::span<char> SmallStringBase::span()
|
||||||
|
{
|
||||||
|
return std::span<char>(m_buffer, m_length);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::span<const u8> SmallStringBase::cbspan() const
|
||||||
|
{
|
||||||
|
return std::span<const u8>(reinterpret_cast<const u8*>(m_buffer), m_length);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::span<u8> SmallStringBase::bspan()
|
||||||
|
{
|
||||||
|
return std::span<u8>(reinterpret_cast<u8*>(m_buffer), m_length);
|
||||||
|
}
|
||||||
|
|
||||||
void SmallStringBase::vformat(fmt::string_view fmt, fmt::format_args args)
|
void SmallStringBase::vformat(fmt::string_view fmt, fmt::format_args args)
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <span>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
|
@ -207,10 +208,18 @@ public:
|
||||||
std::wstring wstring() const;
|
std::wstring wstring() const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// span creators
|
||||||
|
std::span<const char> cspan() const;
|
||||||
|
std::span<char> span();
|
||||||
|
std::span<const u8> cbspan() const;
|
||||||
|
std::span<u8> bspan();
|
||||||
|
|
||||||
// accessor operators
|
// accessor operators
|
||||||
ALWAYS_INLINE operator const char*() const { return c_str(); }
|
ALWAYS_INLINE operator const char*() const { return c_str(); }
|
||||||
ALWAYS_INLINE operator char*() { return data(); }
|
ALWAYS_INLINE operator char*() { return data(); }
|
||||||
ALWAYS_INLINE operator std::string_view() const { return view(); }
|
ALWAYS_INLINE operator std::string_view() const { return view(); }
|
||||||
|
ALWAYS_INLINE operator std::span<const char>() const { return cspan(); }
|
||||||
|
ALWAYS_INLINE operator std::span<char>() { return span(); }
|
||||||
|
|
||||||
// comparative operators
|
// comparative operators
|
||||||
ALWAYS_INLINE bool operator==(const char* str) const { return equals(str); }
|
ALWAYS_INLINE bool operator==(const char* str) const { return equals(str); }
|
||||||
|
|
Loading…
Reference in New Issue