From eb5d3e5df99de2c3d8da2e8bc7b12ed427465dba Mon Sep 17 00:00:00 2001 From: B Stack Date: Sun, 9 Sep 2018 18:53:23 -0400 Subject: pull in latest 10.4 from upstream --- zen/utf.h | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'zen/utf.h') diff --git a/zen/utf.h b/zen/utf.h index 48269416..da6aaf97 100755 --- a/zen/utf.h +++ b/zen/utf.h @@ -10,7 +10,6 @@ #include #include #include "string_tools.h" //copyStringTo -#include "optional.h" namespace zen @@ -96,10 +95,10 @@ class Utf16Decoder public: Utf16Decoder(const Char16* str, size_t len) : it_(str), last_(str + len) {} - Opt getNext() + std::optional getNext() { if (it_ == last_) - return NoValue(); + return {}; const Char16 ch = *it_++; CodePoint cp = ch; @@ -190,10 +189,10 @@ class Utf8Decoder public: Utf8Decoder(const Char8* str, size_t len) : it_(str), last_(str + len) {} - Opt getNext() + std::optional getNext() { if (it_ == last_) - return NoValue(); + return std::nullopt; //GCC 8.2 bug: -Wmaybe-uninitialized for "return {};" const Char8 ch = *it_++; CodePoint cp = ch; @@ -268,7 +267,7 @@ class UtfDecoderImpl //UTF8-char { public: UtfDecoderImpl(const CharType* str, size_t len) : decoder_(reinterpret_cast(str), len) {} - Opt getNext() { return decoder_.getNext(); } + std::optional getNext() { return decoder_.getNext(); } private: Utf8Decoder decoder_; }; @@ -279,7 +278,7 @@ class UtfDecoderImpl //Windows: UTF16-wchar_t { public: UtfDecoderImpl(const CharType* str, size_t len) : decoder_(reinterpret_cast(str), len) {} - Opt getNext() { return decoder_.getNext(); } + std::optional getNext() { return decoder_.getNext(); } private: Utf16Decoder decoder_; }; @@ -290,10 +289,10 @@ class UtfDecoderImpl //other OS: UTF32-wchar_t { public: UtfDecoderImpl(const CharType* str, size_t len) : it_(reinterpret_cast(str)), last_(it_ + len) {} - Opt getNext() + std::optional getNext() { if (it_ == last_) - return NoValue(); + return {}; return *it_++; } private: @@ -314,7 +313,7 @@ bool isValidUtf(const UtfString& str) using namespace impl; UtfDecoder> decoder(strBegin(str), strLength(str)); - while (Opt cp = decoder.getNext()) + while (std::optional cp = decoder.getNext()) if (*cp == REPLACEMENT_CHAR) return false; @@ -344,7 +343,7 @@ UtfString getUnicodeSubstring(const UtfString& str, size_t uniPosFirst, size_t u return output; UtfDecoder decoder(strBegin(str), strLength(str)); - for (size_t uniPos = 0; Opt cp = decoder.getNext(); ++uniPos) //[!] declaration in condition part of the for-loop + for (size_t uniPos = 0; std::optional cp = decoder.getNext(); ++uniPos) //[!] declaration in condition part of the for-loop if (uniPosFirst <= uniPos) { if (uniPos >= uniPosLast) @@ -368,7 +367,7 @@ TargetString utfTo(const SourceString& str, std::false_type) TargetString output; UtfDecoder decoder(strBegin(str), strLength(str)); - while (Opt cp = decoder.getNext()) + while (std::optional cp = decoder.getNext()) codePointToUtf(*cp, [&](CharTrg c) { output += c; }); return output; -- cgit