 Chromium Code Reviews
 Chromium Code Reviews Issue 1647483003:
  Introduce TextBuffer as Output Type of copyTextTo() for Text Iterators  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1647483003:
  Introduce TextBuffer as Output Type of copyTextTo() for Text Iterators  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| Index: third_party/WebKit/Source/core/editing/iterators/TextBuffer.h | 
| diff --git a/third_party/WebKit/Source/core/editing/iterators/TextBuffer.h b/third_party/WebKit/Source/core/editing/iterators/TextBuffer.h | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..5e81ea2de85172d1bac32c7a05291b03f8fccd64 | 
| --- /dev/null | 
| +++ b/third_party/WebKit/Source/core/editing/iterators/TextBuffer.h | 
| @@ -0,0 +1,72 @@ | 
| +// 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 TextBuffer_h | 
| +#define TextBuffer_h | 
| + | 
| +#include "core/CoreExport.h" | 
| +#include "wtf/text/WTFString.h" | 
| 
yosin_UTC9
2016/01/28 09:06:17
nit: #include "wtf/Vector.h"
 | 
| + | 
| +namespace blink { | 
| + | 
| +class CORE_EXPORT TextBufferBase { | 
| + STACK_ALLOCATED(); | 
| 
yosin_UTC9
2016/01/28 09:06:17
WTF_MAKE_NONCOPYABLE(TextBufferBase) see wtf/Nonco
 | 
| +public: | 
| + TextBufferBase(); | 
| 
yosin_UTC9
2016/01/28 09:06:17
nit: |TextBufferBase()| ctor should be protected.
 | 
| + | 
| + 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, pushInternal(length)); | 
| + } | 
| + | 
| +protected: | 
| + UChar* pushInternal(size_t length); | 
| + void grow(size_t demand); | 
| + | 
| + virtual UChar* pushDestination(size_t length) = 0; | 
| + virtual void shiftData(size_t oldCapacity) {} | 
| 
yosin_UTC9
2016/01/28 09:06:17
nit: Don't inline virtual function.
 | 
| + | 
| + size_t m_size = 0; | 
| + Vector<UChar, 1024> m_buffer; | 
| +}; | 
| + | 
| +class CORE_EXPORT ForwardsTextBuffer final : public TextBufferBase { | 
| + STACK_ALLOCATED(); | 
| 
yosin_UTC9
2016/01/28 09:06:17
WTF_MAKE_NONCOPYABLE(ForwardsTextBuffer) see wtf/N
 | 
| +public: | 
| + const UChar* data() const override; | 
| + | 
| +private: | 
| + using TextBufferBase::m_size; | 
| 
yosin_UTC9
2016/01/28 09:06:17
nit: We should use protected member function inste
 | 
| + using TextBufferBase::m_buffer; | 
| + | 
| + UChar* pushDestination(size_t length) override; | 
| +}; | 
| + | 
| +class CORE_EXPORT BackwardsTextBuffer final : public TextBufferBase { | 
| + STACK_ALLOCATED(); | 
| 
yosin_UTC9
2016/01/28 09:06:17
WTF_MAKE_NONCOPYABLE(BackwardsTextBuffer) see wtf/
 | 
| +public: | 
| + const UChar* data() const override; | 
| + | 
| +private: | 
| + using TextBufferBase::m_size; | 
| + using TextBufferBase::m_buffer; | 
| + | 
| + UChar* pushDestination(size_t length) override; | 
| + void shiftData(size_t oldCapacity) override; | 
| +}; | 
| + | 
| +} // namespace blink | 
| + | 
| +#endif // TextBuffer_h |