From c9f728967008147073bb1af07b56b10367d45dd9 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 16 Feb 2020 18:32:13 -0500 Subject: [PATCH] Error messages for string functions --- src/builtin/string.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/builtin/string.rs b/src/builtin/string.rs index 0255607..f87eea9 100644 --- a/src/builtin/string.rs +++ b/src/builtin/string.rs @@ -15,7 +15,7 @@ pub(crate) fn register(f: &mut BTreeMap) { let s: &Value = arg!(args, 0, "string"); match s.eval() { Value::Ident(i, q) => Ok(Value::Ident(i.to_ascii_uppercase(), q)), - _ => todo!("") + v => Err(format!("$string: {} is not a string.", v).into()), } }); decl!(f "to-lower-case", |args, _| { @@ -23,7 +23,7 @@ pub(crate) fn register(f: &mut BTreeMap) { let s: &Value = arg!(args, 0, "string"); match s.eval() { Value::Ident(i, q) => Ok(Value::Ident(i.to_ascii_lowercase(), q)), - _ => todo!("") + v => Err(format!("$string: {} is not a string.", v).into()), } }); decl!(f "str-length", |args, _| { @@ -31,7 +31,7 @@ pub(crate) fn register(f: &mut BTreeMap) { let s: &Value = arg!(args, 0, "string"); match s.eval() { Value::Ident(i, _) => Ok(Value::Dimension(Number::from(i.len()), Unit::None)), - _ => todo!("") + v => Err(format!("$string: {} is not a string.", v).into()), } }); decl!(f "quote", |args, _| { @@ -39,18 +39,22 @@ pub(crate) fn register(f: &mut BTreeMap) { let s = arg!(args, 0, "string").eval(); match s { Value::Ident(i, _) => Ok(Value::Ident(i, QuoteKind::Double)), - _ => todo!("") + v => Err(format!("$string: {} is not a string.", v).into()), } }); decl!(f "unquote", |args, _| { max_args!(args, 1); - Ok(arg!(args, 0, "string").eval().unquote()) + match arg!(args, 0, "string").eval() { + Value::Ident(i, QuoteKind::None) if i.is_empty() => Ok(Value::Null), + i @ Value::Ident(..) => Ok(i.unquote()), + v => Err(format!("$string: {} is not a string.", v).into()), + } }); decl!(f "str-slice", |args, _| { max_args!(args, 3); let (string, quotes) = match arg!(args, 0, "string").eval() { Value::Ident(s, q) => (s, q), - _ => todo!("____ is not a string") + v => return Err(format!("$string: {} is not a string.", v).into()), }; let str_len = string.len(); let start = match arg!(args, 1, "start-at").eval() {