From 4f14318128ba03b4fcceb06f7bb1fb71c3abc7a8 Mon Sep 17 00:00:00 2001 From: Alex Alabuzhev Date: Fri, 16 Feb 2018 19:00:46 +0000 Subject: [PATCH] Fix VS2017 string_view support --- include/fmt/core.h | 12 +++++++----- include/fmt/format.h | 18 +++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index eebce94943c3..2d830a8bc30d 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -663,7 +663,8 @@ class basic_arg { template class basic_parse_context : private ErrorHandler { private: - basic_string_view format_str_; + typename basic_string_view::iterator begin_; + typename basic_string_view::iterator end_; int next_arg_id_; public: @@ -672,20 +673,21 @@ class basic_parse_context : private ErrorHandler { explicit FMT_CONSTEXPR basic_parse_context( basic_string_view format_str, ErrorHandler eh = ErrorHandler()) - : ErrorHandler(eh), format_str_(format_str), next_arg_id_(0) {} + : ErrorHandler(eh), begin_(format_str.begin()), end_(format_str.end()), + next_arg_id_(0) {} // Returns an iterator to the beginning of the format string range being // parsed. FMT_CONSTEXPR iterator begin() const FMT_NOEXCEPT { - return format_str_.begin(); + return begin_; } // Returns an iterator past the end of the format string range being parsed. - FMT_CONSTEXPR iterator end() const FMT_NOEXCEPT { return format_str_.end(); } + FMT_CONSTEXPR iterator end() const FMT_NOEXCEPT { return end_; } // Advances the begin iterator to ``it``. FMT_CONSTEXPR void advance_to(iterator it) { - format_str_.remove_prefix(it - begin()); + begin_ = it; } // Returns the next argument index. diff --git a/include/fmt/format.h b/include/fmt/format.h index 15717fbd80c3..525296bc745d 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -567,7 +567,7 @@ template class null_terminating_iterator; template -FMT_CONSTEXPR_DECL const Char *pointer_from(null_terminating_iterator it); +FMT_CONSTEXPR_DECL typename null_terminating_iterator::pointer pointer_from(null_terminating_iterator it); // An iterator that produces a null terminator on *end. This simplifies parsing // and allows comparing the performance of processing a null-terminated string @@ -577,20 +577,20 @@ class null_terminating_iterator { public: typedef std::ptrdiff_t difference_type; typedef Char value_type; - typedef const Char* pointer; + typedef typename basic_string_view::iterator pointer; typedef const Char& reference; typedef std::random_access_iterator_tag iterator_category; null_terminating_iterator() : ptr_(0), end_(0) {} - FMT_CONSTEXPR null_terminating_iterator(const Char *ptr, const Char *end) + FMT_CONSTEXPR null_terminating_iterator(pointer ptr, pointer end) : ptr_(ptr), end_(end) {} template FMT_CONSTEXPR explicit null_terminating_iterator(const Range &r) : ptr_(r.begin()), end_(r.end()) {} - null_terminating_iterator &operator=(const Char *ptr) { + null_terminating_iterator &operator=(pointer ptr) { assert(ptr <= end_); ptr_ = ptr; return *this; @@ -642,19 +642,19 @@ class null_terminating_iterator { return ptr_ >= other.ptr_; } - friend FMT_CONSTEXPR_DECL const Char *pointer_from( + friend FMT_CONSTEXPR_DECL typename null_terminating_iterator::pointer pointer_from( null_terminating_iterator it); private: - const Char *ptr_; - const Char *end_; + pointer ptr_; + pointer end_; }; template FMT_CONSTEXPR const T *pointer_from(const T *p) { return p; } template -FMT_CONSTEXPR const Char *pointer_from(null_terminating_iterator it) { +FMT_CONSTEXPR typename null_terminating_iterator::pointer pointer_from(null_terminating_iterator it) { return it.ptr_; } @@ -1783,7 +1783,7 @@ FMT_CONSTEXPR Iterator parse_arg_id(Iterator it, IDHandler &&handler) { do { c = *++it; } while (is_name_start(c) || ('0' <= c && c <= '9')); - handler(basic_string_view(pointer_from(start), it - start)); + handler(basic_string_view(&*pointer_from(start), it - start)); return it; }