7#ifndef CORE_FXCRT_BYTESTRING_H_
8#define CORE_FXCRT_BYTESTRING_H_
20#include "core/fxcrt/fx_string_wrappers.h"
21#include "core/fxcrt/retain_ptr.h"
22#include "core/fxcrt/string_data_template.h"
23#include "core/fxcrt/string_view_template.h"
24#include "third_party/abseil-cpp/absl/types/optional.h"
25#include "third_party/base/check.h"
26#include "third_party/base/containers/span.h"
34 using CharType =
char;
35 using const_iterator =
const CharType*;
36 using const_reverse_iterator =
std::reverse_iterator<const_iterator>;
64 ByteString(ByteStringView str1, ByteStringView str2);
65 ByteString(
const std::initializer_list<ByteStringView>& list);
66 explicit ByteString(
const fxcrt::ostringstream& outStream);
76 const char*
c_str()
const {
return m_pData ? m_pData->m_String :
""; }
81 return m_pData ?
reinterpret_cast<
const uint8_t*>(m_pData->m_String)
88 return ByteStringView(raw_str(), GetLength());
93 pdfium::span<
const char> span()
const {
94 return pdfium::make_span(m_pData ? m_pData->m_String :
nullptr,
98 return pdfium::make_span(raw_str(), GetLength());
102 const_iterator
begin()
const {
return m_pData ? m_pData->m_String :
nullptr; }
103 const_iterator
end()
const {
104 return m_pData ? m_pData->m_String + m_pData->m_nDataLength :
nullptr;
109 return const_reverse_iterator(
end());
111 const_reverse_iterator
rend()
const {
112 return const_reverse_iterator(
begin());
117 return m_pData ? strlen(m_pData->m_String) : 0;
123 int Compare(ByteStringView str)
const;
126 bool operator==(
const char* ptr)
const;
127 bool operator==(ByteStringView str)
const;
130 bool operator!=(
const char* ptr)
const {
return !(*
this == ptr); }
131 bool operator!=(ByteStringView str)
const {
return !(*
this == str); }
134 bool operator<(
const char* ptr)
const;
135 bool operator<(ByteStringView str)
const;
151 CHECK(IsValidIndex(index));
152 return m_pData->m_String[index];
155 CharType
Front()
const {
return GetLength() ? (*
this)[0] : 0; }
156 CharType
Back()
const {
return GetLength() ? (*
this)[GetLength() - 1] : 0; }
158 void SetAt(size_t index,
char c);
172 pdfium::span<
char>
GetBuffer(size_t nMinBufLength);
187 bool Contains(ByteStringView lpszSub, size_t start = 0)
const {
188 return Find(lpszSub, start).has_value();
192 return Find(ch, start).has_value();
199 void Trim(
char target);
200 void Trim(ByteStringView targets);
204 void TrimLeft(ByteStringView targets);
213 uint32_t
GetID()
const {
return AsStringView().GetID(); }
221 void AssignCopy(
const char* pSrcData, size_t nSrcLen);
222 void Concat(
const char* pSrcData, size_t nSrcLen);
227 friend class ByteString_Assign_Test;
228 friend class ByteString_Concat_Test;
229 friend class ByteString_Construct_Test;
230 friend class StringPool_ByteString_Test;
251inline bool operator<(
const ByteStringView& lhs,
const char* rhs) {
252 return lhs < ByteStringView(rhs);
271 return ByteString(str1.AsStringView(), str2.AsStringView());
274 return ByteString(str1.AsStringView(), ByteStringView(ch));
277 return ByteString(ByteStringView(ch), str2.AsStringView());
293std::ostream& operator<<(
std::ostream& os, ByteStringView str);
314struct hash<ByteString> {
316 return FX_HashCode_GetA(str.AsStringView());
322extern template struct std::hash<ByteString>;
uint32_t FX_HashCode_GetLoweredAsIfW(ByteStringView str)
uint32_t FX_HashCode_GetLoweredA(ByteStringView str)
uint32_t FX_HashCode_GetAsIfW(ByteStringView str)
uint32_t FX_HashCode_GetA(ByteStringView str)
CPDF_Creator(CPDF_Document *pDoc, RetainPtr< IFX_RetainableWriteStream > archive)
bool SetFileVersion(int32_t fileVersion)
bool Create(uint32_t flags)
virtual FX_FILESIZE CurrentOffset() const =0
static RetainPtr< IFX_SeekableReadStream > CreateFromFilename(const char *filename)
virtual size_t ReadBlock(pdfium::span< uint8_t > buffer)
virtual FX_FILESIZE GetPosition()
virtual bool ReadBlockAtOffset(pdfium::span< uint8_t > buffer, FX_FILESIZE offset)=0
bool WriteBlock(pdfium::span< const uint8_t > buffer) override
virtual bool WriteBlockAtOffset(pdfium::span< const uint8_t > data, FX_FILESIZE offset)=0
bool WriteBlock(pdfium::span< const uint8_t > buffer) override
virtual FX_FILESIZE GetSize()=0
bool WriteFilesize(FX_FILESIZE size)
bool WriteByte(uint8_t byte)
bool WriteString(ByteStringView str)
virtual ~IFX_WriteStream()=default
bool WriteDWord(uint32_t i)
virtual bool WriteBlock(pdfium::span< const uint8_t > data)=0
void TrimLeft(ByteStringView targets)
bool IsValidLength(size_t length) const
bool Contains(ByteStringView lpszSub, size_t start=0) const
const_iterator begin() const
bool IsValidIndex(size_t index) const
static ByteString FormatFloat(float f)
ByteStringView AsStringView() const
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
size_t GetStringLength() const
size_t InsertAtBack(char ch)
bool operator==(ByteStringView str) const
pdfium::span< const uint8_t > raw_span() const
void AllocCopy(ByteString &dest, size_t nCopyLen, size_t nCopyIndex) const
void AssignCopy(const char *pSrcData, size_t nSrcLen)
bool Contains(char ch, size_t start=0) const
absl::optional< size_t > ReverseFind(char ch) const
intptr_t ReferenceCountForTesting() const
size_t Delete(size_t index, size_t count=1)
const_reverse_iterator rend() const
ByteString & operator+=(char ch)
const uint8_t * raw_str() const
void ReallocBeforeWrite(size_t nNewLen)
ByteString(ByteStringView bstrc)
RetainPtr< StringData > m_pData
static ByteString FormatInteger(int i)
pdfium::span< char > GetBuffer(size_t nMinBufLength)
bool operator==(const ByteString &other) const
bool operator==(const char *ptr) const
const_iterator end() const
ByteString(const ByteString &other)
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)
ByteString(const uint8_t *pStr, size_t len)
size_t Replace(ByteStringView pOld, ByteStringView pNew)
absl::optional< size_t > Find(ByteStringView subStr, size_t start=0) const
bool operator!=(const ByteString &other) const
void SetAt(size_t index, char c)
ByteString & operator=(ByteStringView str)
ByteString(ByteStringView str1, ByteStringView str2)
void Trim(ByteStringView targets)
ByteString & operator=(const char *str)
static ByteString FormatV(const char *pFormat, va_list argList)
void TrimRight(char target)
const char * c_str() const
ByteString Substr(size_t offset) const
ByteString & operator=(const ByteString &that)
ByteString & operator=(ByteString &&that) noexcept
void TrimRight(ByteStringView targets)
bool operator<(const ByteString &other) const
ByteString(const std::initializer_list< ByteStringView > &list)
CharType operator[](const size_t index) const
const_reverse_iterator rbegin() const
bool operator!=(const char *ptr) const
int Compare(ByteStringView str) const
size_t Insert(size_t index, char ch)
void ReleaseBuffer(size_t nNewLength)
ByteString(const fxcrt::ostringstream &outStream)
void TrimLeft(char target)
size_t InsertAtFront(char ch)
ByteString First(size_t count) const
void AllocBeforeWrite(size_t nNewLen)
bool operator<(const char *ptr) const
void Concat(const char *pSrcData, size_t nSrcLen)
absl::optional< size_t > Find(char ch, size_t start=0) const
ByteString(ByteString &&other) noexcept
ByteString Last(size_t count) const
#define FPDFCREATE_INCREMENTAL
#define FPDFCREATE_NO_ORIGINAL
void * FX_Random_MT_Start(uint32_t dwSeed)
uint32_t FX_Random_MT_Generate(void *pContext)
void FX_Random_MT_Close(void *pContext)
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)
ByteString operator+(const ByteString &str1, char ch)
ByteString operator+(const ByteString &str1, const char *str2)
void PrintTo(const ByteString &str, std::ostream *os)
ByteString operator+(char ch, const ByteString &str2)
ByteString operator+(const ByteString &str1, ByteStringView str2)
ByteString operator+(const char *str1, const ByteString &str2)
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)
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)
size_t operator()(const ByteString &str) const