Change to use ToStdStringView() in a few other BIFs

This commit is contained in:
Tim Wojtulewicz 2024-01-16 15:13:29 -07:00 committed by Tim Wojtulewicz
parent c77f8cc898
commit 012acb17cc
2 changed files with 6 additions and 6 deletions

View file

@ -1247,8 +1247,8 @@ function reverse%(str: string%) : string
## ##
function count_substr%(str: string, sub: string%) : count function count_substr%(str: string, sub: string%) : count
%{ %{
string s = str->ToStdString(); auto s = str->ToStdStringView();
string sub_s = sub->ToStdString(); auto sub_s = sub->ToStdStringView();
size_t count = 0; size_t count = 0;
size_t pos = s.find(sub_s); size_t pos = s.find(sub_s);

View file

@ -1986,7 +1986,7 @@ function enum_names%(et: any%): string_set
if ( et->GetType()->Tag() == TYPE_STRING ) if ( et->GetType()->Tag() == TYPE_STRING )
{ {
const auto& id = zeek::detail::global_scope()->Find(et->AsStringVal()->ToStdString()); const auto& id = zeek::detail::global_scope()->Find(et->AsStringVal()->ToStdStringView());
if ( id && id->IsType() ) if ( id && id->IsType() )
t = id->GetType(); t = id->GetType();
} }
@ -2184,7 +2184,7 @@ function global_options%(%): string_set
## the string ``"<unknown id>"`` or ``"<no ID value>"`` is returned. ## the string ``"<unknown id>"`` or ``"<no ID value>"`` is returned.
function lookup_ID%(id: string%) : any function lookup_ID%(id: string%) : any
%{ %{
const auto& i = zeek::detail::global_scope()->Find(id->CheckString()); const auto& i = zeek::detail::global_scope()->Find(id->ToStdStringView());
if ( ! i ) if ( ! i )
return zeek::make_intrusive<zeek::StringVal>("<unknown id>"); return zeek::make_intrusive<zeek::StringVal>("<unknown id>");
@ -2214,7 +2214,7 @@ function record_fields%(rec: any%): record_field_table
if ( rec->GetType()->Tag() == zeek::TYPE_STRING ) if ( rec->GetType()->Tag() == zeek::TYPE_STRING )
{ {
const auto& id = zeek::detail::global_scope()->Find(rec->AsStringVal()->ToStdString()); const auto& id = zeek::detail::global_scope()->Find(rec->AsStringVal()->ToStdStringView());
if ( ! id || ! id->IsType() || id->GetType()->Tag() != zeek::TYPE_RECORD ) if ( ! id || ! id->IsType() || id->GetType()->Tag() != zeek::TYPE_RECORD )
{ {
@ -5106,7 +5106,7 @@ function from_json%(s: string, t: any, key_func: string_mapper &default=from_jso
## Returns: a compressed version of the input path. ## Returns: a compressed version of the input path.
function compress_path%(dir: string%): string function compress_path%(dir: string%): string
%{ %{
return zeek::make_intrusive<zeek::StringVal>(zeek::util::detail::normalize_path(dir->ToStdString())); return zeek::make_intrusive<zeek::StringVal>(zeek::util::detail::normalize_path(dir->ToStdStringView()));
%} %}
## Returns true if the given tag belongs to a protocol analyzer. ## Returns true if the given tag belongs to a protocol analyzer.