aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/codepoint_iterator.cc5
-rw-r--r--src/codepoint_iterator.h2
-rw-r--r--test.cc6
3 files changed, 10 insertions, 3 deletions
diff --git a/src/codepoint_iterator.cc b/src/codepoint_iterator.cc
index b2f6d81..59cb23b 100644
--- a/src/codepoint_iterator.cc
+++ b/src/codepoint_iterator.cc
@@ -34,6 +34,11 @@ bool CodepointIterator::operator!=(
return this->iterator_ != src;
}
+std::ptrdiff_t CodepointIterator::operator-(
+ const std::string::const_iterator& src) const {
+ return this->iterator_ - src;
+}
+
char32_t CodepointIterator::operator*() {
std::uint8_t currByte = *(this->iterator_);
char32_t codePoint = 0;
diff --git a/src/codepoint_iterator.h b/src/codepoint_iterator.h
index b505587..d1806e5 100644
--- a/src/codepoint_iterator.h
+++ b/src/codepoint_iterator.h
@@ -22,6 +22,8 @@ class CodepointIterator : public std::iterator<std::bidirectional_iterator_tag,
bool operator!=(const CodepointIterator&) const;
bool operator!=(const std::string::const_iterator&) const;
+ std::ptrdiff_t operator-(const std::string::const_iterator&) const;
+
char32_t operator*();
CodepointIterator& operator++();
diff --git a/test.cc b/test.cc
index 0693970..f0feb74 100644
--- a/test.cc
+++ b/test.cc
@@ -43,7 +43,7 @@ class CodepointIteratorTest : public ::testing::Test {
};
TEST_F(CodepointIteratorTest, ForwardIteration) {
- for ( auto tmp : this->sample_ ) {
+ for ( auto&& tmp : this->sample_ ) {
size_t length = 0;
for ( UTF8::CodepointIterator iter(tmp.text.cbegin());
@@ -57,7 +57,7 @@ TEST_F(CodepointIteratorTest, ForwardIteration) {
}
TEST_F(CodepointIteratorTest, ReverseIteration) {
- for ( auto tmp : this->sample_ ) {
+ for ( auto&& tmp : this->sample_ ) {
size_t length = 0;
for ( UTF8::CodepointIterator iter(tmp.text.cend());
@@ -71,7 +71,7 @@ TEST_F(CodepointIteratorTest, ReverseIteration) {
}
TEST_F(CodepointIteratorTest, Dereferencing) {
- for ( auto tmp : this->sample_ ) {
+ for ( auto&& tmp : this->sample_ ) {
size_t index = 0;
for ( UTF8::CodepointIterator iter(tmp.text.cbegin());