mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-26 15:14:12 +00:00
add functions: prefix? suffix?
This commit is contained in:
parent
72dc10f369
commit
6475c5a253
@ -275,6 +275,8 @@ replace | `(replace "hello world" "hello" "bye")` | `"bye world"` | Replace subs
|
|||||||
split | `(split "-" "a-b-c")` | `("a" "b" "c")` | Split string using [explode](https://www.php.net/manual/en/function.explode.php).
|
split | `(split "-" "a-b-c")` | `("a" "b" "c")` | Split string using [explode](https://www.php.net/manual/en/function.explode.php).
|
||||||
join | `(join "-" "a" "b" "c")` | `"a-b-c"` | Join string together using [implode](https://www.php.net/manual/en/function.implode.php).
|
join | `(join "-" "a" "b" "c")` | `"a-b-c"` | Join string together using [implode](https://www.php.net/manual/en/function.implode.php).
|
||||||
format | `(format "%d %.2f" 56 4.5)` | `"56 4.50"` | Format string using [sprintf](https://www.php.net/manual/en/function.sprintf.php).
|
format | `(format "%d %.2f" 56 4.5)` | `"56 4.50"` | Format string using [sprintf](https://www.php.net/manual/en/function.sprintf.php).
|
||||||
|
prefix? | `(prefix? "hello world" "hello")` | `true` | Return true if the first argument starts with the second argument.
|
||||||
|
suffix? | `(suffix? "hello world" "world")` | `true` | Return true if the first argument ends with the second argument.
|
||||||
|
|
||||||
Note that support for multibyte characters in strings is limited because the provided functions do not use the [mbstring](https://www.php.net/manual/en/book.mbstring.php) extension.
|
Note that support for multibyte characters in strings is limited because the provided functions do not use the [mbstring](https://www.php.net/manual/en/book.mbstring.php) extension.
|
||||||
|
|
||||||
|
@ -48,5 +48,13 @@ class Strings implements ILib
|
|||||||
$env->set('format', new CoreFunc('format', 'Format the remaining arguments as string specified by the first argument.', 1, -1,
|
$env->set('format', new CoreFunc('format', 'Format the remaining arguments as string specified by the first argument.', 1, -1,
|
||||||
fn (string $a, ...$b) => sprintf($a, ...$b)
|
fn (string $a, ...$b) => sprintf($a, ...$b)
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$env->set('prefix?', new CoreFunc('prefix?', 'Return true if the first argument starts with the second argument.', 2, 2,
|
||||||
|
fn (string $str, string $start) => substr($str, 0, strlen($start)) === $start
|
||||||
|
));
|
||||||
|
|
||||||
|
$env->set('suffix?', new CoreFunc('suffix?', 'Return true if the first argument ends with the second argument.', 2, 2,
|
||||||
|
fn (string $str, string $end) => substr($str, strlen($str) - strlen($end)) === $end
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user