diff --git a/src/ID.cc b/src/ID.cc index bf8972f324..da0bc8e6ae 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -31,45 +31,49 @@ IntrusivePtr zeek::id::count_set; IntrusivePtr zeek::id::string_vec; IntrusivePtr zeek::id::index_vec; -const IntrusivePtr& zeek::id::lookup(const char* name) +const IntrusivePtr& zeek::id::lookup(std::string_view name) { return global_scope()->Find(name); } -const IntrusivePtr& zeek::id::lookup_type(const char* name) +const IntrusivePtr& zeek::id::lookup_type(std::string_view name) { auto id = global_scope()->Find(name); if ( ! id ) - reporter->InternalError("Failed to find type named: %s", name); + reporter->InternalError("Failed to find type named: %s", + std::string(name).data()); return id->GetType(); } -const IntrusivePtr& zeek::id::lookup_val(const char* name) +const IntrusivePtr& zeek::id::lookup_val(std::string_view name) { auto id = global_scope()->Find(name); if ( ! id ) - reporter->InternalError("Failed to find variable named: %s", name); + reporter->InternalError("Failed to find variable named: %s", + std::string(name).data()); return id->GetVal(); } -const IntrusivePtr& zeek::id::lookup_const(const char* name) +const IntrusivePtr& zeek::id::lookup_const(std::string_view name) { auto id = global_scope()->Find(name); if ( ! id ) - reporter->InternalError("Failed to find variable named: %s", name); + reporter->InternalError("Failed to find variable named: %s", + std::string(name).data()); if ( ! id->IsConst() ) - reporter->InternalError("Variable is not 'const', but expected to be: %s", name); + reporter->InternalError("Variable is not 'const', but expected to be: %s", + std::string(name).data()); return id->GetVal(); } -IntrusivePtr zeek::id::lookup_func(const char* name) +IntrusivePtr zeek::id::lookup_func(std::string_view name) { const auto& v = zeek::id::lookup_val(name); @@ -77,7 +81,8 @@ IntrusivePtr zeek::id::lookup_func(const char* name) return nullptr; if ( ! IsFunc(v->GetType()->Tag()) ) - reporter->InternalError("Expected variable '%s' to be a function", name); + reporter->InternalError("Expected variable '%s' to be a function", + std::string(name).data()); return {NewRef{}, v->AsFunc()}; } diff --git a/src/ID.h b/src/ID.h index d80be7f7c9..7582dd5c81 100644 --- a/src/ID.h +++ b/src/ID.h @@ -10,6 +10,7 @@ #include #include +#include #include class Val; @@ -165,7 +166,7 @@ namespace zeek { namespace id { * @return The identifier, which may reference a nil object if no such * name exists. */ -const IntrusivePtr& lookup(const char* name); +const IntrusivePtr& lookup(std::string_view name); /** * Lookup an ID by its name and return its type. A fatal occurs if the ID @@ -173,7 +174,7 @@ const IntrusivePtr& lookup(const char* name); * @param name The identifier name to lookup * @return The type of the identifier. */ -const IntrusivePtr& lookup_type(const char* name); +const IntrusivePtr& lookup_type(std::string_view name); /** * Lookup an ID by its name and return its type (as cast to @c T). @@ -182,7 +183,7 @@ const IntrusivePtr& lookup_type(const char* name); * @return The type of the identifier. */ template -IntrusivePtr lookup_type(const char* name) +IntrusivePtr lookup_type(std::string_view name) { return cast_intrusive(lookup_type(name)); } /** @@ -191,7 +192,7 @@ IntrusivePtr lookup_type(const char* name) * @param name The identifier name to lookup * @return The current value of the identifier */ -const IntrusivePtr& lookup_val(const char* name); +const IntrusivePtr& lookup_val(std::string_view name); /** * Lookup an ID by its name and return its value (as cast to @c T). @@ -200,7 +201,7 @@ const IntrusivePtr& lookup_val(const char* name); * @return The current value of the identifier. */ template -IntrusivePtr lookup_val(const char* name) +IntrusivePtr lookup_val(std::string_view name) { return cast_intrusive(lookup_val(name)); } /** @@ -209,7 +210,7 @@ IntrusivePtr lookup_val(const char* name) * @param name The identifier name to lookup * @return The current value of the identifier */ -const IntrusivePtr& lookup_const(const char* name); +const IntrusivePtr& lookup_const(std::string_view name); /** * Lookup an ID by its name and return the function it references. @@ -217,7 +218,7 @@ const IntrusivePtr& lookup_const(const char* name); * @param name The identifier name to lookup * @return The current function value the identifier references. */ -IntrusivePtr lookup_func(const char* name); +IntrusivePtr lookup_func(std::string_view name); extern IntrusivePtr conn_id; extern IntrusivePtr endpoint;