From c87d8ec91f0e191dba6b744788167bb8d41d339e Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Wed, 16 Apr 2014 19:53:00 +0200 Subject: Added static assert of std::string::value_type size * CodepointIterator only supports UTF-8 encoded single-byte input strings ** this should prevent CodepointIterator from compiling on systems with larger char sizes while providing a helpful error message * improved const-correctness by marking currByte (iterator dereferencing cache) and helper method arguments as const --- src/codepoint_iterator.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/codepoint_iterator.cc') diff --git a/src/codepoint_iterator.cc b/src/codepoint_iterator.cc index 59cb23b..b96423a 100644 --- a/src/codepoint_iterator.cc +++ b/src/codepoint_iterator.cc @@ -40,8 +40,10 @@ std::ptrdiff_t CodepointIterator::operator-( } char32_t CodepointIterator::operator*() { - std::uint8_t currByte = *(this->iterator_); - char32_t codePoint = 0; + const std::uint8_t currByte( + static_cast(*(this->iterator_)) + ); + char32_t codePoint{}; if ( match(currByte, dtl::CodeUnitType::CONTINUATION) ) { if ( match(currByte, dtl::CodeUnitType::THREE) ) { @@ -94,7 +96,9 @@ char32_t CodepointIterator::operator*() { } CodepointIterator& CodepointIterator::operator++() { - std::uint8_t currByte(*(this->iterator_)); + const std::uint8_t currByte( + static_cast(*(this->iterator_)) + ); std::string::difference_type offset(1); if ( match(currByte, dtl::CodeUnitType::CONTINUATION) ) { -- cgit v1.2.3