Skip to content

Commit

Permalink
stdlib update
Browse files Browse the repository at this point in the history
Signed-off-by: George Lemon <[email protected]>
  • Loading branch information
georgelemon committed Feb 15, 2025
1 parent 580c5ca commit d6d123f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/timpkg/engine/stdlib.nim
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,24 @@ macro initStandardLibrary() =
boolNode.bVal = re.match(args[0].value.sVal, re(args[1].value.sVal))
boolNode

template strStartsWithStream =
let boolNode = ast.newNode(ntLitBool)
if args[1].value.streamContent.kind == JString:
boolNode.bVal = strutils.startsWith(args[0].value.sVal, args[1].value.streamContent.str)
boolNode

template strStreamStartsWith =
let boolNode = ast.newNode(ntLitBool)
if args[0].value.streamContent.kind == JString:
boolNode.bVal = strutils.startsWith(args[0].value.streamContent.str, args[1].value.sVal)
boolNode

let
fnStrings = @[
fwd("endsWith", ntLitBool, [(ntLitString, "s"), (ntLitString, "suffix")]),
fwd("startsWith", ntLitBool, [(ntLitString, "s"), (ntLitString, "prefix")]),
fwd("startsWith", ntLitBool, [(ntLitString, "s"), (ntStream, "prefix")], wrapper = getAst(strStartsWithStream())),
fwd("startsWith", ntLitBool, [(ntStream, "s"), (ntLitString, "prefix")], wrapper = getAst(strStreamStartsWith())),
fwd("capitalizeAscii", ntLitString, [(ntLitString, "s")], "capitalize"),
fwd("replace", ntLitString, [(ntLitString, "s"), (ntLitString, "sub"), (ntLitString, "by")]),
fwd("toLowerAscii", ntLitString, [(ntLitString, "s")], "toLower"),
Expand Down

0 comments on commit d6d123f

Please sign in to comment.