diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2019-12-08 05:15:06 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2019-12-08 05:15:06 +0300 |
commit | a46c1928480761b4005487d6a4c1fd4d2e6a3d6d (patch) | |
tree | a987bfe37e0ea68c4ddb4c0d58f355d85d21a6dc /server | |
parent | server: proper integer types (diff) | |
download | math-server-a46c1928480761b4005487d6a4c1fd4d2e6a3d6d.tar.gz math-server-a46c1928480761b4005487d6a4c1fd4d2e6a3d6d.zip |
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.
Diffstat (limited to 'server')
-rw-r--r-- | server/lexer/lexer.cpp | 22 |
1 files changed, 15 insertions, 7 deletions
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<std::size_t>(match[0].length())}; } std::optional<double> parse_number(const std::string_view& input, std::string_view& token) { @@ -49,7 +53,7 @@ std::optional<double> 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<token::Type> 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 {}; } |