-module(datadog_query@quote). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/datadog_query/quote.gleam"). -export([value/1]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -file("src/datadog_query/quote.gleam", 25). -spec needs_quoting(binary()) -> boolean(). needs_quoting(Input) -> case gleam_stdlib:contains_string(Input, <<"*"/utf8>>) of true -> false; false -> (((gleam_stdlib:contains_string(Input, <<" "/utf8>>) orelse gleam_stdlib:contains_string( Input, <<"\t"/utf8>> )) orelse gleam_stdlib:contains_string(Input, <<","/utf8>>)) orelse gleam_stdlib:contains_string(Input, <<"("/utf8>>)) orelse gleam_stdlib:contains_string(Input, <<")"/utf8>>) end. -file("src/datadog_query/quote.gleam", 18). ?DOC( " Wraps a value in double quotes when it contains characters that would\n" " otherwise be ambiguous to the Datadog scope parser. Embedded double quotes\n" " are escaped.\n" ). -spec value(binary()) -> binary(). value(Input) -> case needs_quoting(Input) of true -> <<<<"\""/utf8, (gleam@string:replace(Input, <<"\""/utf8>>, <<"\\\""/utf8>>))/binary>>/binary, "\""/utf8>>; false -> Input end.