From 0789098d7d163da9c28a5d6d1efe86cb5ca07368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sun, 17 Apr 2022 09:19:47 +0300 Subject: [PATCH] Add some convenience API to QuotedOrUnquoted --- src/parser.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/parser.rs b/src/parser.rs index 962f5bb..03633d0 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -628,6 +628,29 @@ impl Default for QuotedOrUnquoted { } } +impl QuotedOrUnquoted { + pub fn as_str(&self) -> &str { + match self { + QuotedOrUnquoted::Quoted(s) => s.as_str(), + QuotedOrUnquoted::Unquoted(s) => s.as_str(), + } + } + + pub fn as_unquoted(&self) -> Option<&str> { + match self { + QuotedOrUnquoted::Unquoted(s) => Some(s.as_str()), + _ => None, + } + } + + pub fn as_quoted(&self) -> Option<&str> { + match self { + QuotedOrUnquoted::Quoted(s) => Some(s.as_str()), + _ => None, + } + } +} + impl From<&str> for QuotedOrUnquoted { fn from(s: &str) -> Self { if s.starts_with('"') && s.ends_with('"') {