add a string replace method
This commit is contained in:
parent
591402b428
commit
12caeedf68
4 changed files with 36 additions and 3 deletions
|
|
@ -84,6 +84,25 @@ func Split(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
|||
return res
|
||||
}
|
||||
|
||||
/* Takes three args
|
||||
* 1. source string
|
||||
* 2. token to be replaced
|
||||
* 3. token to swap in place
|
||||
* All three args are strings
|
||||
* Returns final string
|
||||
*/
|
||||
func Replace(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||
body := in.Value()
|
||||
sub := in.Next.Value()
|
||||
tok := in.Next.Next.Value()
|
||||
|
||||
body = strings.ReplaceAll(body, sub, tok)
|
||||
|
||||
res := &ast.Token{Tag: ast.STRING}
|
||||
res.Set(body)
|
||||
return res
|
||||
}
|
||||
|
||||
/* Takes two args, a delimiter and a list of strings
|
||||
* Returns the list of strings concatenated together with the delimiter in between each element
|
||||
* On error returns nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue