Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1495)

Unified Diff: third_party/WebKit/Source/core/editing/iterators/TextBufferBase.h

Issue 1650543002: Introduce ForwardsTextBuffer and BackwardsTextBuffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Stop the win compiler's complaint Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/editing/iterators/TextBufferBase.h
diff --git a/third_party/WebKit/Source/core/editing/iterators/TextBufferBase.h b/third_party/WebKit/Source/core/editing/iterators/TextBufferBase.h
new file mode 100644
index 0000000000000000000000000000000000000000..27f3be0fd5ba9145ffdbbcaa37a14a2409b5ffcc
--- /dev/null
+++ b/third_party/WebKit/Source/core/editing/iterators/TextBufferBase.h
@@ -0,0 +1,55 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TextBufferBase_h
+#define TextBufferBase_h
+
+#include "core/CoreExport.h"
+#include "wtf/Vector.h"
+#include "wtf/text/WTFString.h"
+
+namespace blink {
+
+class CORE_EXPORT TextBufferBase {
+ STACK_ALLOCATED();
+ WTF_MAKE_NONCOPYABLE(TextBufferBase);
+public:
+ void clear() { m_size = 0; }
+ size_t size() const { return m_size; }
+ bool isEmpty() const { return m_size == 0; }
+ const UChar& operator[](size_t index) const { ASSERT(index < m_size); return data()[index]; }
+ virtual const UChar* data() const = 0;
+
+ void pushCharacters(UChar, size_t length);
+
+ template<typename T>
+ void pushRange(const T* other, size_t length)
+ {
+ if (length == 0)
+ return;
+ std::copy(other, other + length, ensureDestination(length));
+ }
+
+protected:
+ TextBufferBase();
+ UChar* ensureDestination(size_t length);
+ void grow(size_t demand);
+
+ virtual UChar* calcDestination(size_t length) = 0;
+ virtual void shiftData(size_t oldCapacity);
+
+ size_t capacity() const { return m_buffer.capacity(); }
+ const UChar* bufferBegin() const { return m_buffer.begin(); }
+ const UChar* bufferEnd() const { return m_buffer.end(); }
+ UChar* bufferBegin() { return m_buffer.begin(); }
+ UChar* bufferEnd() { return m_buffer.end(); }
+
+private:
+ size_t m_size = 0;
+ Vector<UChar, 1024> m_buffer;
+};
+
+} // namespace blink
+
+#endif // TextBufferBase_h

Powered by Google App Engine
This is Rietveld 408576698