summaryrefslogtreecommitdiff
path: root/core/fxcrt/include/fx_string.h
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-04-06 16:48:26 -0700
committerCommit bot <commit-bot@chromium.org>2016-04-06 16:48:26 -0700
commit46bf0331229a7b7fe73cbe111550f5dd467b184a (patch)
tree4b99e9337e0c58c96bbf325e960401e23dff34ce /core/fxcrt/include/fx_string.h
parent6334af71040b6148e9001aad4bd134a6c6c14a8d (diff)
downloadpdfium-46bf0331229a7b7fe73cbe111550f5dd467b184a.tar.xz
Make wide strings use StringData template
Shuffled the order of methods in fx_basic_wstring.cpp to match those in fx_basic_bstring.cpp. The way to review this patch is to diff those two files against each other. They are beginning to converge. Re-ordered some parameters in Concat() so that the string comes before its length. It feels wrong otherwise. Review URL: https://codereview.chromium.org/1846793002
Diffstat (limited to 'core/fxcrt/include/fx_string.h')
-rw-r--r--core/fxcrt/include/fx_string.h65
1 files changed, 17 insertions, 48 deletions
diff --git a/core/fxcrt/include/fx_string.h b/core/fxcrt/include/fx_string.h
index 7595795011..382e141dc2 100644
--- a/core/fxcrt/include/fx_string.h
+++ b/core/fxcrt/include/fx_string.h
@@ -482,16 +482,9 @@ class CFX_WideString {
public:
typedef FX_WCHAR value_type;
- CFX_WideString() : m_pData(nullptr) {}
-
- // Copy constructor.
- CFX_WideString(const CFX_WideString& str);
-
- // Move constructor.
- CFX_WideString(CFX_WideString&& other) {
- m_pData = other.m_pData;
- other.m_pData = nullptr;
- }
+ CFX_WideString() {}
+ CFX_WideString(const CFX_WideString& other) : m_pData(other.m_pData) {}
+ CFX_WideString(CFX_WideString&& other) { m_pData.Swap(other.m_pData); }
CFX_WideString(const FX_WCHAR* ptr)
: CFX_WideString(ptr, ptr ? FXSYS_wcslen(ptr) : 0) {}
@@ -527,9 +520,12 @@ class CFX_WideString {
return CFX_WideStringC(c_str(), GetLength());
}
- void Empty();
- bool IsEmpty() const { return !GetLength(); }
+ // Deprecated -- use clear().
+ void Empty() { m_pData.Reset(); }
+ void clear() { m_pData.Reset(); }
+
FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; }
+ bool IsEmpty() const { return !GetLength(); }
const CFX_WideString& operator=(const FX_WCHAR* str);
const CFX_WideString& operator=(const CFX_WideString& stringSrc);
@@ -587,11 +583,11 @@ class CFX_WideString {
void TrimRight();
void TrimRight(FX_WCHAR chTarget);
- void TrimRight(const FX_WCHAR* lpszTargets);
+ void TrimRight(const CFX_WideStringC& pTargets);
void TrimLeft();
void TrimLeft(FX_WCHAR chTarget);
- void TrimLeft(const FX_WCHAR* lpszTargets);
+ void TrimLeft(const CFX_WideStringC& pTargets);
void Reserve(FX_STRSIZE len);
FX_WCHAR* GetBuffer(FX_STRSIZE len);
@@ -600,53 +596,26 @@ class CFX_WideString {
int GetInteger() const;
FX_FLOAT GetFloat() const;
- FX_STRSIZE Find(const FX_WCHAR* lpszSub, FX_STRSIZE start = 0) const;
+ FX_STRSIZE Find(const CFX_WideStringC& pSub, FX_STRSIZE start = 0) const;
FX_STRSIZE Find(FX_WCHAR ch, FX_STRSIZE start = 0) const;
- FX_STRSIZE Replace(const FX_WCHAR* lpszOld, const FX_WCHAR* lpszNew);
+ FX_STRSIZE Replace(const CFX_WideStringC& pOld, const CFX_WideStringC& pNew);
FX_STRSIZE Remove(FX_WCHAR ch);
CFX_ByteString UTF8Encode() const;
CFX_ByteString UTF16LE_Encode() const;
protected:
- class StringData {
- public:
- static StringData* Create(int nLen);
- void Retain() { ++m_nRefs; }
- void Release() {
- if (--m_nRefs <= 0)
- FX_Free(this);
- }
+ using StringData = CFX_StringDataTemplate<FX_WCHAR>;
- intptr_t m_nRefs; // Would prefer ssize_t, but no windows support.
- FX_STRSIZE m_nDataLength;
- FX_STRSIZE m_nAllocLength;
- FX_WCHAR m_String[1];
-
- private:
- StringData(FX_STRSIZE dataLen, FX_STRSIZE allocLen)
- : m_nRefs(1), m_nDataLength(dataLen), m_nAllocLength(allocLen) {
- FXSYS_assert(dataLen >= 0);
- FXSYS_assert(allocLen >= 0);
- FXSYS_assert(dataLen <= allocLen);
- m_String[dataLen] = 0;
- }
- ~StringData() = delete;
- };
-
- void CopyBeforeWrite();
+ void ReallocBeforeWrite(FX_STRSIZE nLen);
void AllocBeforeWrite(FX_STRSIZE nLen);
- void ConcatInPlace(FX_STRSIZE nSrcLen, const FX_WCHAR* lpszSrcData);
- void ConcatCopy(FX_STRSIZE nSrc1Len,
- const FX_WCHAR* lpszSrc1Data,
- FX_STRSIZE nSrc2Len,
- const FX_WCHAR* lpszSrc2Data);
- void AssignCopy(FX_STRSIZE nSrcLen, const FX_WCHAR* lpszSrcData);
void AllocCopy(CFX_WideString& dest,
FX_STRSIZE nCopyLen,
FX_STRSIZE nCopyIndex) const;
+ void AssignCopy(const FX_WCHAR* pSrcData, FX_STRSIZE nSrcLen);
+ void Concat(const FX_WCHAR* lpszSrcData, FX_STRSIZE nSrcLen);
- StringData* m_pData;
+ CFX_RetainPtr<StringData> m_pData;
friend class fxcrt_WideStringConcatInPlace_Test;
};