Skip to content

Commit

Permalink
Merge pull request #229 from calcit-lang/starts-with
Browse files Browse the repository at this point in the history
extend arguments of starts-with?
  • Loading branch information
NoEgAm committed Dec 4, 2023
2 parents 3cd04d2 + bd90ea0 commit e11e3e0
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "calcit"
version = "0.8.13"
version = "0.8.14"
authors = ["jiyinyiyong <[email protected]>"]
edition = "2021"
license = "MIT"
Expand Down
1 change: 1 addition & 0 deletions calcit/test-string.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
assert= true $ starts-with? |01234 |01
assert= false $ starts-with? |01234 |12
assert= true $ starts-with? :a/b :a/
assert= true $ starts-with? :a/b |a/
assert= true $ ends-with? |01234 |34
assert= true $ ends-with? |01234 |4
assert= false $ ends-with? |01234 |23
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@calcit/procs",
"version": "0.8.13",
"version": "0.8.14",
"main": "./lib/calcit.procs.mjs",
"devDependencies": {
"@types/node": "^20.10.0",
"@types/node": "^20.10.2",
"typescript": "^5.3.2"
},
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/builtins/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ pub fn starts_with_ques(xs: &CalcitItems) -> Result<Calcit, CalcitErr> {
match (xs.get(0), xs.get(1)) {
(Some(Calcit::Str(s)), Some(Calcit::Str(pattern))) => Ok(Calcit::Bool(s.starts_with(&**pattern))),
(Some(Calcit::Tag(s)), Some(Calcit::Tag(pattern))) => Ok(Calcit::Bool((*s.to_str()).starts_with(&*pattern.to_str()))),
(Some(Calcit::Tag(s)), Some(Calcit::Str(pattern))) => Ok(Calcit::Bool((*s.to_str()).starts_with(&**pattern))),
(Some(a), Some(b)) => CalcitErr::err_str(format!("starts-with? expected 2 strings, got: {a} {b}")),
(_, _) => CalcitErr::err_str("starts-with? expected 2 arguments, got nothing"),
}
Expand Down
3 changes: 3 additions & 0 deletions ts-src/calcit.procs.mts
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,9 @@ export let starts_with_$q_ = (xs: CalcitValue, y: CalcitValue): boolean => {
if (xs instanceof CalcitTag && y instanceof CalcitTag) {
return xs.value.startsWith(y.value);
}
if (xs instanceof CalcitTag && typeof y === "string") {
return xs.value.startsWith(y);
}
throw new Error("expected strings or tags");
};
export let ends_with_$q_ = (xs: string, y: string): boolean => {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e11e3e0

Please sign in to comment.