- Added a default c-tor to the input stream to avoid an ambiquity.
- Changed the input stream API so that it can take a string pointer + length and use that for UTF conversion, avoiding so unnecessary copies. Convenience methods exist to use a std::string or a std::string_view.
- With that only a single load() method is necessary.
- In ANTLRFileStream the other c-tors are now also deleted, as they make no sense there.
A previous change to add std::string_view support to ANTLRInputStream for C++17 caused some trouble because of ABI changes. This has been changed to define 2 constructors, one for std::string_view (for C++17) and the original one for std::string.
This is turn caused an error in ANTLRFileStream, which also takes a string in the constructor (but handling it as file name instead of input). To make this clearer the c-tor taking a std::string has been deleted in ANTLRFileStream and the class now requires to load input via the loadFile() function. This might cause some trouble for those users who had used the std::string constructor of ANTLRFileStream, but I think the better error reporting outweighs the little annoyance.
Try to find system's utf8cpp first, instead of downloading it from
github. utf8cpp 3 defines a cmake package, so we can use find_package.
Older utf8cpps don't, so we try also find_path. If all that fails, we
still fall back to github download.
This is needed as distributions cannot download stuff from their build
systems. And people want to use libraries/headers from the distribution
anyway.
I had to reorder the file a bit, so that the libraries are defined
through the utf8cpp detection
On linux. Most users haven't installed libc++-dev, but ANTLR is passing
the "--stdlib=libc++" argument. As a result, this won't compile. Users
will see:
```
/tmp/antlr4/runtime/Cpp/runtime/src/antlr4-common.h:8:10: fatal error:
'algorithm' file not found
```
This is caused by the "WITH_LIBCXX" option.
It was introduced by:
d46ef90aa0
It causes the option "--stdlib=libc++" to be appended by default.
I believe its default value should have been left as "Off".
With "off" by default, clang will use its default C++ library, which is
always available.
The WITH_LIBCXX option is kept, being able to change the C++ library
might be useful?
BUG=https://github.com/antlr/antlr4/issues/2898
Defining a static const member in a header breaks ODR, as the object will be
defined in every translation unit that includes the header.
Instead, the members should either be declared `inline` (which is
implicitly the case for `constexpr` members) or initialized in a cpp.
Alternatively, using an anonymous enum allows the definition to remain
inside the header meaning that the compiler can still choose to inline
values.
This commit doesn't change the behavior, it contains few small improvements:
- prevent useless copy when creating the variable tokenName
- avoid to check if tokenName is empty twice
- use std::string::empty() instead of creating an empty string to compare with
- use std::string::clear() instead of assigning an empty C string to clear a string