Rename builtin upcase,downcase -> to_uppercase, to_lowercase.
This commit is contained in:
parent
7c6b6d4319
commit
d72334c246
@ -214,12 +214,12 @@ This crate offers a set of builtin functions.
|
|||||||
|------------|-----------------|-------------|
|
|------------|-----------------|-------------|
|
||||||
| min | >= 1 | Returns the minimum of the arguments |
|
| min | >= 1 | Returns the minimum of the arguments |
|
||||||
| max | >= 1 | Returns the maximum of the arguments |
|
| max | >= 1 | Returns the maximum of the arguments |
|
||||||
| downcase | 1 | Returns lower-case version of string |
|
| to_lowercase | 1 | Returns lower-case version of string |
|
||||||
| len | 1 | Return the character length of string argument |
|
| len | 1 | Return the character length of string argument |
|
||||||
| regex_matches | 2 | Returns true if first string argument matches regex in second |
|
| regex_matches | 2 | Returns true if first string argument matches regex in second |
|
||||||
| regex_replace | 3 | Returns string with matches replaced by third argument |
|
| regex_replace | 3 | Returns string with matches replaced by third argument |
|
||||||
| trim | 1 | Strips whitespace from start and end of string |
|
| trim | 1 | Strips whitespace from start and end of string |
|
||||||
| upcase | 1 | Returns upper-case version of string |
|
| to_uppercase | 1 | Returns upper-case version of string |
|
||||||
|
|
||||||
The `min` and `max` functions can deal with a mixture of integer and floating point arguments.
|
The `min` and `max` functions can deal with a mixture of integer and floating point arguments.
|
||||||
They return the result as the type it was passed into the function. The regex functions require
|
They return the result as the type it was passed into the function. The regex functions require
|
||||||
|
@ -340,7 +340,7 @@ pub fn expect_number(actual: &Value) -> EvalexprResult<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns Ok(()) if the given value is a string or a numeric
|
/// Returns `Ok(())` if the given value is a string or a numeric
|
||||||
pub fn expect_number_or_string(actual: &Value) -> EvalexprResult<()> {
|
pub fn expect_number_or_string(actual: &Value) -> EvalexprResult<()> {
|
||||||
match actual {
|
match actual {
|
||||||
Value::String(_) | Value::Float(_) | Value::Int(_) => Ok(()),
|
Value::String(_) | Value::Float(_) | Value::Int(_) => Ok(()),
|
||||||
|
@ -60,7 +60,7 @@ pub fn builtin_function(identifier: &str) -> Option<Function> {
|
|||||||
|
|
||||||
// string functions
|
// string functions
|
||||||
|
|
||||||
"downcase" => Some(Function::new(
|
"to_lowercase" => Some(Function::new(
|
||||||
Some(1),
|
Some(1),
|
||||||
Box::new(|arguments| {
|
Box::new(|arguments| {
|
||||||
let subject = expect_string(&arguments[0])?;
|
let subject = expect_string(&arguments[0])?;
|
||||||
@ -106,7 +106,7 @@ pub fn builtin_function(identifier: &str) -> Option<Function> {
|
|||||||
Ok(Value::from(subject.trim()))
|
Ok(Value::from(subject.trim()))
|
||||||
}),
|
}),
|
||||||
)),
|
)),
|
||||||
"upcase" => Some(Function::new(
|
"to_uppercase" => Some(Function::new(
|
||||||
Some(1),
|
Some(1),
|
||||||
Box::new(|arguments| {
|
Box::new(|arguments| {
|
||||||
let subject = expect_string(&arguments[0])?;
|
let subject = expect_string(&arguments[0])?;
|
||||||
|
@ -288,7 +288,7 @@ fn test_builtin_functions() {
|
|||||||
Ok(Value::Float(4.0))
|
Ok(Value::Float(4.0))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
eval("downcase(\"FOOBAR\")"),
|
eval("to_lowercase(\"FOOBAR\")"),
|
||||||
Ok(Value::from("foobar"))
|
Ok(Value::from("foobar"))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -300,7 +300,7 @@ fn test_builtin_functions() {
|
|||||||
Ok(Value::from("foo bar"))
|
Ok(Value::from("foo bar"))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
eval("upcase(\"foobar\")"),
|
eval("to_uppercase(\"foobar\")"),
|
||||||
Ok(Value::from("FOOBAR"))
|
Ok(Value::from("FOOBAR"))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user