summaryrefslogtreecommitdiff
path: root/core/fxcrt/cfx_bytestring.h
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-09-13 09:45:14 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-09-13 20:31:57 +0000
commite762774c7571dbfcc08a0928ea1bae684b605713 (patch)
treef27c1290e2e9de4e10d3e791d4408ba67818b09b /core/fxcrt/cfx_bytestring.h
parentb4a6948a97575b194d373e5801fe83d297cdc46f (diff)
downloadpdfium-e762774c7571dbfcc08a0928ea1bae684b605713.tar.xz
Add reverse iterators to CFX String classes.
Reverse iteration with signed lengths and indices is kinda icky without this abstraction, and STL provides this pretty much "for free" given the existing forward iterator. Change-Id: I97c36c8bd23c0aa48195bc17da7c672292b4cde2 Reviewed-on: https://pdfium-review.googlesource.com/13770 Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcrt/cfx_bytestring.h')
-rw-r--r--core/fxcrt/cfx_bytestring.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/core/fxcrt/cfx_bytestring.h b/core/fxcrt/cfx_bytestring.h
index 432f28a06d..b976287617 100644
--- a/core/fxcrt/cfx_bytestring.h
+++ b/core/fxcrt/cfx_bytestring.h
@@ -8,6 +8,7 @@
#define CORE_FXCRT_CFX_BYTESTRING_H_
#include <functional>
+#include <iterator>
#include <sstream>
#include <utility>
@@ -25,6 +26,7 @@ class CFX_ByteString {
public:
using CharType = char;
using const_iterator = const CharType*;
+ using const_reverse_iterator = std::reverse_iterator<const_iterator>;
CFX_ByteString();
CFX_ByteString(const CFX_ByteString& other);
@@ -77,6 +79,14 @@ class CFX_ByteString {
return m_pData ? m_pData->m_String + m_pData->m_nDataLength : nullptr;
}
+ // Note: Any subsequent modification of |this| will invalidate iterators.
+ const_reverse_iterator rbegin() const {
+ return const_reverse_iterator(end());
+ }
+ const_reverse_iterator rend() const {
+ return const_reverse_iterator(begin());
+ }
+
FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; }
FX_STRSIZE GetStringLength() const {
return m_pData ? FXSYS_strlen(m_pData->m_String) : 0;