mirror of
https://github.com/MontFerret/ferret.git
synced 2025-11-27 22:08:15 +02:00
Implement FROM_BASE64 function (#115)
This commit is contained in:
31
pkg/stdlib/strings/decode.go
Normal file
31
pkg/stdlib/strings/decode.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package strings
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/runtime/values"
|
||||
|
||||
"github.com/MontFerret/ferret/pkg/runtime/core"
|
||||
)
|
||||
|
||||
/*
|
||||
* Returns the value of a base64 representation.
|
||||
* @param base64String (String) - The string to decode.
|
||||
* @returns value (String) - The decoded string.
|
||||
*/
|
||||
func FromBase64(_ context.Context, args ...core.Value) (core.Value, error) {
|
||||
err := core.ValidateArgs(args, 1, 1)
|
||||
if err != nil {
|
||||
return values.EmptyString, err
|
||||
}
|
||||
|
||||
value := args[0].String()
|
||||
|
||||
out, err := base64.StdEncoding.DecodeString(value)
|
||||
if err != nil {
|
||||
return values.EmptyString, err
|
||||
}
|
||||
|
||||
return values.NewString(string(out)), nil
|
||||
}
|
||||
Reference in New Issue
Block a user