7#ifndef CORE_FXCRT_STRING_VIEW_TEMPLATE_H_
8#define CORE_FXCRT_STRING_VIEW_TEMPLATE_H_
18#include "core/fxcrt/compiler_specific.h"
19#include "core/fxcrt/fx_memcpy_wrappers.h"
20#include "core/fxcrt/fx_system.h"
21#include "core/fxcrt/span.h"
22#include "core/fxcrt/span_util.h"
58 const pdfium::span<
const CharType>& other)
noexcept {
60 m_Span = reinterpret_span<
const UnsignedType>(other);
67 const pdfium::span<
const UnsignedType>& other)
noexcept {
97 pdfium::make_span(
reinterpret_cast<
const UnsignedType*>(src),
98 src ? std::char_traits<CharType>::length(src) : 0));
108 return reinterpret_cast<const_iterator>(m_Span.begin());
111 return reinterpret_cast<const_iterator>(m_Span.end());
121 return std::equal(m_Span.begin(), m_Span.end(), other.m_Span.begin(),
126 return *
this == other;
130 return !(*
this == other);
134 for (
auto c : *
this) {
135 if (c <= 0 || c > 127)
142 size_t length = GetLength();
143 if (length != that.GetLength())
146 for (size_t i = 0; i < length; ++i) {
148 if (c <= 0 || c > 127 || c != that[i])
155 size_t length = GetLength();
156 if (length != that.GetLength())
159 for (size_t i = 0; i < length; ++i) {
161 if (c <= 0 || c > 127 || tolower(c) != tolower(that[i]))
172 size_t size = std::min(
static_cast<size_t>(4), m_Span.size());
173 for (size_t i = 0; i < size; i++)
174 strid = strid * 256 + m_Span[i];
176 return strid << ((4 - size) * 8);
181 return reinterpret_span<
const CharType>(m_Span);
184 return m_Span.data();
187 return reinterpret_cast<
const CharType*>(m_Span.data());
191 bool IsEmpty()
const {
return m_Span.empty(); }
192 bool IsValidIndex(size_t index)
const {
return index < m_Span.size(); }
197 return m_Span[index];
202 return static_cast<CharType>(m_Span[index]);
215 reinterpret_cast<
const UnsignedType*>(std::char_traits<CharType>::find(
216 reinterpret_cast<
const CharType*>(m_Span.data()), m_Span.size(),
219 return found ? std::optional<size_t>(found - m_Span.data()) : std::nullopt;
227 return Substr(offset, GetLength() - offset);
234 if (!IsValidIndex(first))
237 if (count == 0 || !IsValidLength(count))
240 if (!IsValidIndex(first + count - 1))
244 return UNSAFE_BUFFERS(StringViewTemplate(m_Span.data() + first, count));
248 return Substr(0, count);
254 return Substr(GetLength() - count, count);
261 size_t pos = GetLength();
262 while (pos && CharAt(pos - 1) == ch)
273 const size_t common_size = std::min(m_Span.size(), that.m_Span.size());
275 common_size ? std::char_traits<CharType>::compare(
276 reinterpret_cast<
const CharType*>(m_Span.data()),
277 reinterpret_cast<
const CharType*>(that.m_Span.data()),
280 return result < 0 || (result == 0 && m_Span.size() < that.m_Span.size());
284 const size_t common_size = std::min(m_Span.size(), that.m_Span.size());
286 common_size ? std::char_traits<CharType>::compare(
287 reinterpret_cast<
const CharType*>(m_Span.data()),
288 reinterpret_cast<
const CharType*>(that.m_Span.data()),
291 return result > 0 || (result == 0 && m_Span.size() > that.m_Span.size());
301 void* operator
new(size_t)
throw() {
return nullptr; }
317extern template class StringViewTemplate<
char>;
318extern template class StringViewTemplate<
wchar_t>;
uint32_t FX_HashCode_GetLoweredAsIfW(ByteStringView str)
fxcrt::ByteString ByteString
uint32_t FX_HashCode_GetLoweredA(ByteStringView str)
uint32_t FX_HashCode_GetAsIfW(ByteStringView str)
uint32_t FX_HashCode_GetA(ByteStringView str)
ByteString(const char *ptr)
bool EqualNoCase(ByteStringView str) const
static ByteString Format(const char *pFormat,...)
ByteString & operator+=(const ByteString &str)
bool operator!=(ByteStringView str) const
ByteString Substr(size_t first, size_t count) const
bool operator==(ByteStringView str) const
intptr_t ReferenceCountForTesting() const
ByteString & operator+=(char ch)
ByteString(ByteStringView bstrc)
static ByteString FormatInteger(int i)
bool operator==(const ByteString &other) const
bool operator==(const char *ptr) const
UNSAFE_BUFFER_USAGE ByteString(const char *pStr, size_t len)
bool operator<(ByteStringView str) const
ByteString(wchar_t)=delete
ByteString & operator+=(const char *str)
ByteString & operator+=(ByteStringView str)
UNSAFE_BUFFER_USAGE ByteString(const uint8_t *pStr, size_t len)
bool operator!=(const ByteString &other) const
ByteString & operator=(ByteStringView str)
ByteString(ByteStringView str1, ByteStringView str2)
ByteString & operator=(const char *str)
void TrimWhitespaceFront()
static ByteString FormatV(const char *pFormat, va_list argList)
ByteString Substr(size_t offset) const
ByteString & operator=(const ByteString &that)
ByteString & operator=(ByteString &&that) noexcept
ByteString(ByteString &&other) noexcept=default
bool operator<(const ByteString &other) const
ByteString(const std::initializer_list< ByteStringView > &list)
bool operator!=(const char *ptr) const
int Compare(ByteStringView str) const
ByteString(const ByteString &other)=default
ByteString(const fxcrt::ostringstream &outStream)
ByteString First(size_t count) const
void TrimWhitespaceBack()
bool operator<(const char *ptr) const
ByteString Last(size_t count) const
RetainPtr & operator=(const RetainPtr< U > &that)
RetainPtr(std::nullptr_t ptr)
void Reset(T *obj=nullptr)
bool operator!=(const RetainPtr &that) const
void Swap(RetainPtr &that)
RetainPtr() noexcept=default
RetainPtr(RetainPtr &&that) noexcept
bool operator!=(const U &that) const
RetainPtr & operator=(const RetainPtr &that)
bool operator==(const RetainPtr &that) const
bool operator==(const U &that) const
RetainPtr & operator=(RetainPtr &&that) noexcept
RetainPtr & operator=(RetainPtr< U > &&that) noexcept
RetainPtr(const RetainPtr< U > &that)
bool operator<(const RetainPtr &that) const
RetainPtr(const RetainPtr &that) noexcept
operator T*() const noexcept
RetainPtr & operator=(std::nullptr_t) noexcept
RetainPtr(RetainPtr< U > &&that) noexcept
RetainPtr< U > As() const
RetainPtr(T *pObj) noexcept
virtual ~Retainable()=default
pdfium::span< CharType > alloc_span()
pdfium::span< CharType > span()
pdfium::span< const CharType > span_with_terminator() const
const size_t m_nAllocLength
pdfium::span< const CharType > span() const
size_t GetStringLength() const
pdfium::span< CharType > capacity_span()
void CopyContents(const StringDataTemplate &other)
static RetainPtr< StringDataTemplate > Create(size_t nLen)
void CopyContentsAt(size_t offset, pdfium::span< const CharType > str)
void CopyContents(pdfium::span< const CharType > str)
bool CanOperateInPlace(size_t nTotalLen) const
pdfium::span< const CharType > capacity_span() const
pdfium::span< const CharType > alloc_span() const
pdfium::span< T > GetBuffer(size_t nMinBufLength)
size_t Delete(size_t index, size_t count=1)
const_iterator begin() const
void AllocBeforeWrite(size_t nNewLen)
pdfium::span< const UnsignedType > unsigned_span_with_terminator() const
size_t Replace(StringView oldstr, StringView newstr)
StringTemplate(const StringTemplate &other)=default
pdfium::span< const CharType > span_with_terminator() const
~StringTemplate()=default
StringView AsStringView() const
void ReleaseBuffer(size_t nNewLength)
CharType operator[](const size_t index) const
pdfium::span< const UnsignedType > unsigned_span() const
StringDataTemplate< T > StringData
std::optional< size_t > ReverseFind(T ch) const
StringViewTemplate< T > StringView
void AssignCopy(const T *pSrcData, size_t nSrcLen)
RetainPtr< StringData > m_pData
std::optional< size_t > Find(StringView str, size_t start=0) const
void SetAt(size_t index, T ch)
const_reverse_iterator rbegin() const
const_iterator end() const
bool IsValidIndex(size_t index) const
bool Contains(T ch, size_t start=0) const
typename std::make_unsigned< CharType >::type UnsignedType
void TrimBack(StringView targets)
void Trim(StringView targets)
StringTemplate(StringTemplate &&other) noexcept=default
std::reverse_iterator< const_iterator > const_reverse_iterator
bool Contains(StringView str, size_t start=0) const
void Concat(const T *pSrcData, size_t nSrcLen)
size_t InsertAtFront(T ch)
size_t InsertAtBack(T ch)
std::optional< size_t > Find(T ch, size_t start=0) const
pdfium::span< const CharType > span() const
const UnsignedType * unsigned_str() const
bool IsValidLength(size_t length) const
size_t GetStringLength() const
void ReallocBeforeWrite(size_t nNewLen)
void TrimFront(StringView targets)
size_t Insert(size_t index, T ch)
const_reverse_iterator rend() const
const CharType * c_str() const
bool operator>(const StringViewTemplate &that) const
StringViewTemplate(const CharType *ptr) noexcept
bool operator<(const StringViewTemplate &that) const
bool IsValidLength(size_t length) const
UnsignedType Back() const
bool operator!=(const CharType *ptr) const
typename std::make_unsigned< CharType >::type UnsignedType
StringViewTemplate TrimmedRight(CharType ch) const
pdfium::span< const UnsignedType > m_Span
bool EqualsASCII(const StringViewTemplate< char > &that) const
std::optional< size_t > Find(CharType ch) const
const CharType * unterminated_c_str() const
bool operator==(const CharType *ptr) const
bool Contains(CharType ch) const
bool EqualsASCIINoCase(const StringViewTemplate< char > &that) const
StringViewTemplate Substr(size_t first, size_t count) const
std::reverse_iterator< const_iterator > const_reverse_iterator
UNSAFE_BUFFER_USAGE constexpr StringViewTemplate(const CharType *ptr, size_t size) noexcept
bool operator==(const StringViewTemplate &other) const
const_iterator end() const
const UnsignedType & operator[](const size_t index) const
const CharType * const_iterator
StringViewTemplate Last(size_t count) const
const UnsignedType * unterminated_unsigned_str() const
CharType CharAt(const size_t index) const
bool operator!=(const StringViewTemplate &other) const
StringViewTemplate First(size_t count) const
constexpr StringViewTemplate(const pdfium::span< const CharType > &other) noexcept
constexpr StringViewTemplate(const StringViewTemplate &src) noexcept=default
const_iterator begin() const
StringViewTemplate & operator=(const StringViewTemplate &src)
const_reverse_iterator rend() const
UnsignedType Front() const
StringViewTemplate & operator=(const CharType *src)
StringViewTemplate Substr(size_t offset) const
constexpr StringViewTemplate() noexcept=default
constexpr StringViewTemplate(const CharType &ch) noexcept
UNSAFE_BUFFER_USAGE constexpr StringViewTemplate(const UnsignedType *ptr, size_t size) noexcept
pdfium::span< const CharType > span() const
const_reverse_iterator rbegin() const
bool IsValidIndex(size_t index) const
constexpr StringViewTemplate(const pdfium::span< const UnsignedType > &other) noexcept
pdfium::span< const UnsignedType > unsigned_span() const
#define UNSAFE_BUFFERS(...)
#define UNSAFE_BUFFER_USAGE
CRYPT_md5_context CRYPT_MD5Start()
TEST(FXCRYPT, CryptToBase16)
TEST(FXCRYPT, MD5GenerateEmtpyData)
std::string CryptToBase16(const uint8_t *digest)
bool operator==(const char *lhs, const ByteString &rhs)
bool operator<(const ByteStringView &lhs, const char *rhs)
ByteString operator+(const ByteString &str1, const ByteString &str2)
ByteString operator+(ByteStringView str1, const char *str2)
bool operator<(const ByteStringView &lhs, const ByteString &rhs)
StringViewTemplate< wchar_t > WideStringView
bool operator==(const T *lhs, const StringViewTemplate< T > &rhs)
bool operator<(const T *lhs, const StringViewTemplate< T > &rhs)
ByteString operator+(const ByteString &str1, char ch)
ByteString operator+(const ByteString &str1, const char *str2)
void PrintTo(const ByteString &str, std::ostream *os)
bool operator!=(const T *lhs, const StringViewTemplate< T > &rhs)
ByteString operator+(char ch, const ByteString &str2)
ByteString operator+(const ByteString &str1, ByteStringView str2)
ByteString operator+(const char *str1, const ByteString &str2)
constexpr const wchar_t * EmptyString(wchar_t *)
StringViewTemplate< char > ByteStringView
bool operator!=(ByteStringView lhs, const ByteString &rhs)
bool operator!=(const char *lhs, const ByteString &rhs)
ByteString operator+(ByteStringView str1, ByteStringView str2)
ByteString operator+(ByteStringView str1, char ch)
constexpr const char * EmptyString(char *)
bool operator<(const char *lhs, const ByteString &rhs)
ByteString operator+(char ch, ByteStringView str2)
ByteString operator+(ByteStringView str1, const ByteString &str2)
ByteString operator+(const char *str1, ByteStringView str2)
bool operator==(ByteStringView lhs, const ByteString &rhs)
RetainPtr< T > MakeRetain(Args &&... args)
RetainPtr< T > WrapRetain(T *that)
fxcrt::ByteStringView ByteStringView
fxcrt::WideStringView WideStringView
void operator()(T *ptr) const
size_t operator()(const ByteString &str) const