From 6a8393ec02eba05b5a0932a923417de00357dcc2 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 17 Mar 2017 20:26:04 -0700 Subject: [PATCH] ircd: Add unquote() util for quoted string views. --- include/ircd/lexical.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/include/ircd/lexical.h b/include/ircd/lexical.h index 28b579f3b..0f05a15d3 100644 --- a/include/ircd/lexical.h +++ b/include/ircd/lexical.h @@ -181,15 +181,21 @@ bool endswith(const string_view &str, const char &val); template bool endswith_any(const string_view &str, const It &begin, const It &end); bool startswith(const string_view &str, const string_view &val); bool startswith(const string_view &str, const char &val); +string_view unquote(string_view str); } // namespace ircd -template -ircd::string_view -ircd::lex_cast(const T &t) +inline ircd::string_view +ircd::unquote(string_view str) { - return lex_cast(t, nullptr, 0); + if(startswith(str, '"')) + str = { str.data() + 1, str.data() + str.size() }; + + if(endswith(str, '"')) + str = { str.data(), str.data() + str.size() - 1 }; + + return str; } inline bool