aboutsummaryrefslogtreecommitdiff
path: root/src/framework
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2018-04-05 13:19:44 +0200
committeracdenisSK <[email protected]>2018-04-05 13:20:19 +0200
commit24d2233ba583221b35eca02cf321e7a4a1adf76d (patch)
treeed4bae58339f03823ca0d551b87fe20eed88770a /src/framework
parentFix is_empty behaviour again (diff)
downloadserenity-24d2233ba583221b35eca02cf321e7a4a1adf76d.tar.xz
serenity-24d2233ba583221b35eca02cf321e7a4a1adf76d.zip
Add `full_quoted`
Diffstat (limited to 'src/framework')
-rw-r--r--src/framework/standard/args.rs53
1 files changed, 52 insertions, 1 deletions
diff --git a/src/framework/standard/args.rs b/src/framework/standard/args.rs
index 1c8d075..928715b 100644
--- a/src/framework/standard/args.rs
+++ b/src/framework/standard/args.rs
@@ -204,12 +204,63 @@ impl Args {
/// ```rust
/// use serenity::framework::standard::Args;
///
- /// let mut args = Args::new("42 69", &[" ".to_string()]);
+ /// let args = Args::new("42 69", &[" ".to_string()]);
///
/// assert_eq!(args.full(), "42 69");
/// ```
pub fn full(&self) -> &str { &self.message }
+ /// Accesses the current state of the internal string, but
+ /// with quotes removed if it has both opening and closing quotes;
+ /// otherwise returns the string as is.
+ ///
+ /// # Examples
+ ///
+ /// ```rust
+ /// use serenity::framework::standard::Args;
+ ///
+ /// let args = Args::new("\"42 69\"", &[" ".to_string()]);
+ ///
+ /// assert_eq!(args.full_quoted(), "42 69");
+ /// ```
+ ///
+ /// ```rust
+ /// use serenity::framework::standard::Args;
+ ///
+ /// let args = Args::new("\"42 69", &[" ".to_string()]);
+ ///
+ /// assert_eq!(args.full_quoted(), "\"42 69");
+ /// ```
+ ///
+ /// ```rust
+ /// use serenity::framework::standard::Args;
+ ///
+ /// let args = Args::new("42 69\"", &[" ".to_string()]);
+ ///
+ /// assert_eq!(args.full_quoted(), "42 69\"");
+ /// ```
+ pub fn full_quoted(&self) -> &str {
+ let s = &self.message;
+
+ if !s.starts_with('"') {
+ return s;
+ }
+
+ let end = s.rfind('"');
+ if end.is_none() {
+ return s;
+ }
+
+ let end = end.unwrap();
+
+ // If it got the quote at the start, then there's no closing quote.
+ if end == 0 {
+ return s;
+ }
+
+ &s[1..end]
+ }
+
/// The amount of args.
///
/// # Examples