summaryrefslogtreecommitdiff
path: root/xfa/fde/cfde_txtedtbuf.h
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-01-10 16:35:58 -0500
committerChromium commit bot <commit-bot@chromium.org>2017-01-10 21:50:44 +0000
commit0e6438e40a95702edb8327286c8253aa269c9826 (patch)
tree5d3b07277b5fa4a1fb96a9d2a23108a3d02bdc9e /xfa/fde/cfde_txtedtbuf.h
parent6c0c48227aa024aa6e188ed7adf4d7c3d410cff9 (diff)
downloadpdfium-0e6438e40a95702edb8327286c8253aa269c9826.tar.xz
Remove custom allocator from CFDE_TxtEdtBuf.
This CL removes the custom allocator from CFDE_TxtEdtBuf and uses std::vector<std::unique_ptr>> instead. The Iterator code has been made an inner class of the buffer and rename to CFDE_TxtEdtBuf::Iterator instead of CFDE_TxtEdtBufIter. Change-Id: Ied8e844dea700e0ef37087f0d3fad4882d9eada1 Reviewed-on: https://pdfium-review.googlesource.com/2159 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa/fde/cfde_txtedtbuf.h')
-rw-r--r--xfa/fde/cfde_txtedtbuf.h56
1 files changed, 38 insertions, 18 deletions
diff --git a/xfa/fde/cfde_txtedtbuf.h b/xfa/fde/cfde_txtedtbuf.h
index 63edbf6167..9eeee5632e 100644
--- a/xfa/fde/cfde_txtedtbuf.h
+++ b/xfa/fde/cfde_txtedtbuf.h
@@ -8,22 +8,48 @@
#define XFA_FDE_CFDE_TXTEDTBUF_H_
#include <memory>
+#include <tuple>
+#include <vector>
#include "core/fxcrt/fx_basic.h"
#include "core/fxcrt/fx_system.h"
+#include "xfa/fde/ifx_chariter.h"
-class IFX_MemoryAllocator;
class IFX_Pause;
class CFDE_TxtEdtBuf {
public:
+ class Iterator : public IFX_CharIter {
+ public:
+ explicit Iterator(CFDE_TxtEdtBuf* pBuf, FX_WCHAR wcAlias = 0);
+ ~Iterator() override;
+
+ bool Next(bool bPrev = false) override;
+ FX_WCHAR GetChar() override;
+
+ void SetAt(int32_t nIndex) override;
+ int32_t GetAt() const override;
+
+ bool IsEOF(bool bTail = true) const override;
+ IFX_CharIter* Clone() override;
+
+ private:
+ CFDE_TxtEdtBuf* m_pBuf;
+ int32_t m_nCurChunk;
+ int32_t m_nCurIndex;
+ int32_t m_nIndex;
+ FX_WCHAR m_Alias;
+ };
+
CFDE_TxtEdtBuf();
~CFDE_TxtEdtBuf();
int32_t GetChunkSize() const;
int32_t GetTextLength() const;
+
void SetText(const CFX_WideString& wsText);
CFX_WideString GetText() const;
+
FX_WCHAR GetCharByIndex(int32_t nIndex) const;
CFX_WideString GetRange(int32_t nBegin, int32_t nCount) const;
@@ -32,31 +58,25 @@ class CFDE_TxtEdtBuf {
void Clear(bool bRelease);
private:
- friend class CFDE_TxtEdtBufIter;
+ friend class Iterator;
friend class CFDE_TxtEdtBufTest;
- struct FDE_CHUNKHEADER {
- int32_t nUsed;
- FX_WCHAR wChars[1];
- };
+ class ChunkHeader {
+ public:
+ ChunkHeader();
+ ~ChunkHeader();
- struct FDE_CHUNKPLACE {
- int32_t nChunkIndex;
- int32_t nCharIndex;
+ int32_t nUsed;
+ std::unique_ptr<FX_WCHAR, FxFreeDeleter> wChars;
};
- void ResetChunkBuffer(int32_t nDefChunkCount, int32_t nChunkSize);
- int32_t CP2Index(const FDE_CHUNKPLACE& cp) const;
- void Index2CP(int32_t nIndex, FDE_CHUNKPLACE& cp) const;
-
void SetChunkSizeForTesting(size_t size);
+ std::tuple<int32_t, int32_t> Index2CP(int32_t nIndex) const;
+ std::unique_ptr<ChunkHeader> NewChunk();
- int32_t m_nChunkSize;
-
+ size_t m_chunkSize;
int32_t m_nTotal;
- bool m_bChanged;
- CFX_ArrayTemplate<FDE_CHUNKHEADER*> m_Chunks;
- std::unique_ptr<IFX_MemoryAllocator> m_pAllocator;
+ std::vector<std::unique_ptr<ChunkHeader>> m_chunks;
};
#endif // XFA_FDE_CFDE_TXTEDTBUF_H_