diff options
-rw-r--r-- | include/openvic-dataloader/detail/SymbolIntern.hpp | 13 | ||||
-rw-r--r-- | include/openvic-dataloader/v2script/Parser.hpp | 1 | ||||
-rw-r--r-- | src/openvic-dataloader/v2script/Parser.cpp | 8 |
3 files changed, 22 insertions, 0 deletions
diff --git a/include/openvic-dataloader/detail/SymbolIntern.hpp b/include/openvic-dataloader/detail/SymbolIntern.hpp index d72a0ba..56576c5 100644 --- a/include/openvic-dataloader/detail/SymbolIntern.hpp +++ b/include/openvic-dataloader/detail/SymbolIntern.hpp @@ -173,6 +173,19 @@ namespace ovdl { return success; } + symbol find_intern(const CharT* str, std::size_t length) { + auto entry = _map.lookup_entry(typename traits::string_view { str, length }, traits { &_buffer }); + if (entry) + return symbol(_buffer.c_str(entry.get())); + + return symbol(); + } + template<std::size_t N> + symbol find_intern(const CharT (&literal)[N]) { + DRYAD_PRECONDITION(literal[N - 1] == CharT(0)); + return find_intern(literal, N - 1); + } + symbol intern(const CharT* str, std::size_t length) { if (_map.should_rehash()) _map.rehash(_resource, traits { &_buffer }); diff --git a/include/openvic-dataloader/v2script/Parser.hpp b/include/openvic-dataloader/v2script/Parser.hpp index 2518e61..c5f37be 100644 --- a/include/openvic-dataloader/v2script/Parser.hpp +++ b/include/openvic-dataloader/v2script/Parser.hpp @@ -51,6 +51,7 @@ namespace ovdl::v2script { const FileTree* get_file_node() const; std::string_view value(const ovdl::v2script::ast::FlatValue* node) const; + ovdl::symbol<char> find_intern(std::string_view string) const; std::string make_native_string() const; std::string make_list_string() const; diff --git a/src/openvic-dataloader/v2script/Parser.cpp b/src/openvic-dataloader/v2script/Parser.cpp index 9c6a0c5..2375a1a 100644 --- a/src/openvic-dataloader/v2script/Parser.cpp +++ b/src/openvic-dataloader/v2script/Parser.cpp @@ -12,6 +12,7 @@ #include <openvic-dataloader/detail/Concepts.hpp> #include <openvic-dataloader/detail/Encoding.hpp> #include <openvic-dataloader/detail/OStreamOutputIterator.hpp> +#include <openvic-dataloader/detail/SymbolIntern.hpp> #include <openvic-dataloader/detail/Utility.hpp> #include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp> @@ -269,6 +270,13 @@ std::string_view Parser::value(const ovdl::v2script::ast::FlatValue* node) const return node->value().view(); } +ovdl::symbol<char> Parser::find_intern(std::string_view string) const { + if (!_parse_handler->is_valid()) { + return ovdl::symbol<char>(); + } + return _parse_handler->parse_state().ast().symbol_interner().find_intern(string.data(), string.size()); +} + std::string Parser::make_native_string() const { return _parse_handler->parse_state().ast().make_native_visualizer(); } |