From a46c1928480761b4005487d6a4c1fd4d2e6a3d6d Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 8 Dec 2019 05:15:06 +0300 Subject: fix Visual Studio 2019 errors Some std::string_view::string_view couldn't be resolved. Additionally, couldn't construct std::string_view from an initializer list sometimes, similar to the infamous std::vector constructor woes. --- server/lexer/lexer.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'server/lexer') diff --git a/server/lexer/lexer.cpp b/server/lexer/lexer.cpp index c7eea6d..808fba3 100644 --- a/server/lexer/lexer.cpp +++ b/server/lexer/lexer.cpp @@ -24,8 +24,12 @@ std::string_view match_number(const std::string_view& input) { static const std::regex number_regex{R"REGEX(^(?:\d+(?:\.\d*)?|\.\d+)(e[+-]?(\d*))?)REGEX", flags}; std::cmatch match; - if (!std::regex_search(input.cbegin(), input.cend(), match, number_regex)) { - return {}; + { + const auto begin = input.data(); + const auto end = begin + input.length(); + if (!std::regex_search(begin, end, match, number_regex)) { + return {}; + } } { // If we have the numeric part of a number followed by 'e' and no digits, @@ -37,7 +41,7 @@ std::string_view match_number(const std::string_view& input) { throw LexerError{"exponent has no digits: " + match[0].str()}; } } - return {match[0].first, match[0].length()}; + return {match[0].first, static_cast(match[0].length())}; } std::optional parse_number(const std::string_view& input, std::string_view& token) { @@ -49,7 +53,7 @@ std::optional parse_number(const std::string_view& input, std::string_vi const auto result = std::stod(std::string{view}); token = view; return result; - } catch (const std::exception& e) { + } catch (const std::exception&) { throw LexerError{"internal: couldn't parse number from: " + std::string{view}}; } return {}; @@ -64,7 +68,7 @@ std::optional parse_const_token(const std::string_view& input, std: for (const auto type : token::const_tokens()) { const auto str = token::type_to_string(type); if (starts_with(input, str)) { - token = {input.cbegin(), str.length()}; + token = std::string_view(input.data(), str.length()); return {type}; } } @@ -89,8 +93,12 @@ std::string_view parse_whitespace(const std::string_view& input) { static const std::regex ws_regex{R"(^\s+)"}; std::cmatch match; - if (std::regex_search(input.cbegin(), input.cend(), match, ws_regex)) { - return {match[0].first, match[0].length()}; + { + const auto begin = input.data(); + const auto end = begin + input.length(); + if (std::regex_search(begin, end, match, ws_regex)) { + return std::string_view(match[0].first, match[0].length()); + } } return {}; } -- cgit v1.2.3