From 02186451ee65f4c7a5c3aa798cbbb5f1c402d26c Mon Sep 17 00:00:00 2001
From: Xavier L'Heureux <xavier.lheureux@icloud.com>
Date: Thu, 27 Jun 2019 16:02:16 -0400
Subject: [PATCH] Use the std-native functions instead of hand-rolled ones

---
 src/lib/parser/statement/functions.rs |  4 +--
 src/lib/parser/statement/mod.rs       | 38 ---------------------------
 2 files changed, 2 insertions(+), 40 deletions(-)

diff --git a/src/lib/parser/statement/functions.rs b/src/lib/parser/statement/functions.rs
index fccbb54c..ad6b94a4 100644
--- a/src/lib/parser/statement/functions.rs
+++ b/src/lib/parser/statement/functions.rs
@@ -1,4 +1,3 @@
-use super::split_pattern;
 use crate::parser::lexers::assignments::{KeyBuf, KeyIterator, TypeError};
 use err_derive::Error;
 
@@ -14,7 +13,8 @@ pub enum FunctionParseError {
 /// converted into a tuple consisting of a `KeyIterator` iterator, which will collect type
 /// information, and an optional description of the function.
 pub fn parse_function(arg: &str) -> (KeyIterator<'_>, Option<&str>) {
-    let (args, description) = split_pattern(arg, "--");
+    let mut parts = arg.splitn(2, "--");
+    let (args, description) = (parts.next().unwrap().trim(), parts.next().map(str::trim));
     (KeyIterator::new(args), description)
 }
 
diff --git a/src/lib/parser/statement/mod.rs b/src/lib/parser/statement/mod.rs
index 18883805..9610c08d 100644
--- a/src/lib/parser/statement/mod.rs
+++ b/src/lib/parser/statement/mod.rs
@@ -103,41 +103,3 @@ pub fn parse_and_validate<'b>(
         StatementVariant::Default(statement) => parse(statement, builtins),
     }
 }
-
-/// Splits a string into two, based on a given pattern. We know that the first string will always
-/// exist, but if the pattern is not found, or no string follows the pattern, then the second
-/// string will not exist. Useful for splitting the function expression by the "--" pattern.
-fn split_pattern<'a>(arg: &'a str, pattern: &str) -> (&'a str, Option<&'a str>) {
-    match arg.find(pattern) {
-        Some(pos) => {
-            let args = &arg[..pos].trim();
-            let comment = &arg[pos + pattern.len()..].trim();
-            if comment.is_empty() {
-                (args, None)
-            } else {
-                (args, Some(comment))
-            }
-        }
-        None => (arg, None),
-    }
-}
-
-#[cfg(test)]
-mod tests {
-    use super::*;
-
-    #[test]
-    fn statement_pattern_splitting() {
-        let (args, description) = split_pattern("a:int b:bool -- a comment", "--");
-        assert_eq!(args, "a:int b:bool");
-        assert_eq!(description, Some("a comment"));
-
-        let (args, description) = split_pattern("a --", "--");
-        assert_eq!(args, "a");
-        assert_eq!(description, None);
-
-        let (args, description) = split_pattern("a", "--");
-        assert_eq!(args, "a");
-        assert_eq!(description, None);
-    }
-}
-- 
GitLab