forked from jasder/antlr
Merge pull request #2847 from nburles/antlrinputstream_from_stringview
[C++ runtime] Add AntlrInputStream(std::string_view) constructor
This commit is contained in:
commit
9a646e0367
|
@ -182,6 +182,7 @@
|
|||
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
@ -201,6 +202,7 @@
|
|||
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
@ -220,6 +222,7 @@
|
|||
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
@ -239,6 +242,7 @@
|
|||
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
@ -259,6 +263,7 @@
|
|||
</ForcedIncludeFiles>
|
||||
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
@ -281,6 +286,7 @@
|
|||
</ForcedIncludeFiles>
|
||||
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
@ -303,6 +309,7 @@
|
|||
</ForcedIncludeFiles>
|
||||
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
@ -325,6 +332,7 @@
|
|||
</ForcedIncludeFiles>
|
||||
<DisableSpecificWarnings>4251</DisableSpecificWarnings>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue