diff --git a/runtime/Cpp/runtime/antlr4cpp-vs2019.vcxproj b/runtime/Cpp/runtime/antlr4cpp-vs2019.vcxproj index 42a81fc06b..54f0aeb14b 100644 --- a/runtime/Cpp/runtime/antlr4cpp-vs2019.vcxproj +++ b/runtime/Cpp/runtime/antlr4cpp-vs2019.vcxproj @@ -182,6 +182,7 @@ 4251 true false + /Zc:__cplusplus %(AdditionalOptions) Windows @@ -201,6 +202,7 @@ 4251 true false + /Zc:__cplusplus %(AdditionalOptions) Windows @@ -220,6 +222,7 @@ 4251 true false + /Zc:__cplusplus %(AdditionalOptions) Windows @@ -239,6 +242,7 @@ 4251 true false + /Zc:__cplusplus %(AdditionalOptions) Windows @@ -259,6 +263,7 @@ 4251 true + /Zc:__cplusplus %(AdditionalOptions) Windows @@ -281,6 +286,7 @@ 4251 true + /Zc:__cplusplus %(AdditionalOptions) Windows @@ -303,6 +309,7 @@ 4251 true + /Zc:__cplusplus %(AdditionalOptions) Windows @@ -325,6 +332,7 @@ 4251 true + /Zc:__cplusplus %(AdditionalOptions) Windows diff --git a/runtime/Cpp/runtime/src/ANTLRInputStream.cpp b/runtime/Cpp/runtime/src/ANTLRInputStream.cpp index a5e21618eb..2e06c5efc7 100755 --- a/runtime/Cpp/runtime/src/ANTLRInputStream.cpp +++ b/runtime/Cpp/runtime/src/ANTLRInputStream.cpp @@ -17,7 +17,11 @@ using namespace antlrcpp; using misc::Interval; +#if __cplusplus >= 201703L +ANTLRInputStream::ANTLRInputStream(std::string_view input) { +#else ANTLRInputStream::ANTLRInputStream(const std::string &input) { +#endif InitializeInstanceFields(); load(input); } @@ -31,6 +35,16 @@ ANTLRInputStream::ANTLRInputStream(std::istream &stream) { load(stream); } +#if __cplusplus >= 201703L +void ANTLRInputStream::load(std::string_view input) { + // Remove the UTF-8 BOM if present. + constexpr std::string_view bom = "\xef\xbb\xbf"; + if (input.compare(0, 3, bom) == 0) + input.remove_prefix(3); + _data = antlrcpp::utf8_to_utf32(input.data(), input.data() + input.size()); + p = 0; +} +#else void ANTLRInputStream::load(const std::string &input) { // Remove the UTF-8 BOM if present. const char bom[4] = "\xef\xbb\xbf"; @@ -40,6 +54,7 @@ void ANTLRInputStream::load(const std::string &input) { _data = antlrcpp::utf8_to_utf32(input.data(), input.data() + input.size()); p = 0; } +#endif void ANTLRInputStream::load(std::istream &stream) { if (!stream.good() || stream.eof()) // No fail, bad or EOF. diff --git a/runtime/Cpp/runtime/src/ANTLRInputStream.h b/runtime/Cpp/runtime/src/ANTLRInputStream.h index e9850504d8..7b575df2e9 100755 --- a/runtime/Cpp/runtime/src/ANTLRInputStream.h +++ b/runtime/Cpp/runtime/src/ANTLRInputStream.h @@ -25,11 +25,19 @@ namespace antlr4 { /// What is name or source of this char stream? std::string name; +#if __cplusplus >= 201703L + ANTLRInputStream(std::string_view input = ""); +#else ANTLRInputStream(const std::string &input = ""); +#endif ANTLRInputStream(const char data_[], size_t numberOfActualCharsInArray); ANTLRInputStream(std::istream &stream); +#if __cplusplus >= 201703L + virtual void load(std::string_view input); +#else virtual void load(const std::string &input); +#endif virtual void load(std::istream &stream); /// Reset the stream so that it's in the same state it was