5#ifndef CORE_FXCRT_SPAN_UTIL_H_
6#define CORE_FXCRT_SPAN_UTIL_H_
13#include "core/fxcrt/check_op.h"
14#include "core/fxcrt/fx_memcpy_wrappers.h"
15#include "core/fxcrt/span.h"
36 UNSAFE_BUFFERS(FXSYS_memcpy(dst.data(), src.data(), src.size_bytes()));
37 return dst.subspan(src.size());
57 UNSAFE_BUFFERS(FXSYS_memmove(dst.data(), src.data(), src.size_bytes()));
58 return dst.subspan(src.size());
75 if (dst.size() < src.size()) {
81 UNSAFE_BUFFERS(FXSYS_memcpy(dst.data(), src.data(), src.size_bytes()));
99 if (dst.size() < src.size()) {
105 UNSAFE_BUFFERS(FXSYS_memmove(dst.data(), src.data(), src.size_bytes()));
111template <
typename T1,
123 return s1.size_bytes() == s2.size_bytes() &&
124 UNSAFE_BUFFERS(FXSYS_memcmp(s1.data(), s2.data(), s1.size_bytes())) ==
135 pdfium::span<U> needle) {
136 if (needle.empty() || needle.size() > haystack.size()) {
141 size_t end_pos = haystack.size() - needle.size();
142 for (size_t haystack_pos = 0; haystack_pos <= end_pos; ++haystack_pos) {
143 auto candidate = haystack.subspan(haystack_pos, needle.size());
144 if (
fxcrt::span_equals(candidate, needle)) {
156 CHECK(
alignof(T) ==
alignof(U) ||
157 reinterpret_cast<uintptr_t>(s.data()) %
alignof(T) == 0u);
160 s.size_bytes() /
sizeof(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)
int32_t FXSYS_atoi(const char *str)
uint32_t FXSYS_atoui(const char *str)
int FXSYS_wcsicmp(const wchar_t *str1, const wchar_t *str2)
int32_t FXSYS_wtoi(const wchar_t *str)
int FXSYS_stricmp(const char *str1, const char *str2)
int64_t FXSYS_atoi64(const char *str)
char * FXSYS_strlwr(char *str)
wchar_t * FXSYS_wcsupr(wchar_t *str)
char * FXSYS_strupr(char *str)
wchar_t * FXSYS_wcslwr(wchar_t *str)
#define FXSYS_IsFloatZero(f)
uint32_t FXSYS_GetLastError()
const char * FXSYS_i64toa(int64_t value, char *str, int radix)
int FXSYS_roundf(float f)
int FXSYS_round(double d)
char * FXSYS_itoa(int value, char *str, int radix)
void FXSYS_SetLastError(uint32_t err)
float FXSYS_sqrt2(float a, float b)
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)
bool span_equals(pdfium::span< T1, N1, P1 > s1, pdfium::span< T2, N2, P2 > s2)
ByteString operator+(ByteStringView str1, const char *str2)
bool operator<(const ByteStringView &lhs, const ByteString &rhs)
StringViewTemplate< wchar_t > WideStringView
pdfium::span< T > reinterpret_span(pdfium::span< U > s) noexcept
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)
std::optional< size_t > spanpos(pdfium::span< T > haystack, pdfium::span< U > needle)
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)
pdfium::span< T1 > spanmove(pdfium::span< T1, N1, P1 > dst, pdfium::span< T2, N2, P2 > src)
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)
bool try_spanmove(pdfium::span< T1, N1, P1 > dst, pdfium::span< T2, N2, P2 > src)
pdfium::span< T1 > spancpy(pdfium::span< T1, N1, P1 > dst, pdfium::span< T2, N2, P2 > src)
bool try_spancpy(pdfium::span< T1, N1, P1 > dst, pdfium::span< T2, N2, P2 > src)
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