github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/strings/unescape.go (about)

     1  package strings
     2  
     3  import (
     4  	"context"
     5  	"html"
     6  
     7  	"github.com/MontFerret/ferret/pkg/runtime/core"
     8  	"github.com/MontFerret/ferret/pkg/runtime/values"
     9  )
    10  
    11  // UNESCAPE_HTML unescapes entities like "&lt;" to become "<". It unescapes a
    12  // larger range of entities than EscapeString escapes. For example, "&aacute;"
    13  // unescapes to "รก", as does "&#225;" and "&#xE1;".
    14  // UnescapeString(EscapeString(s)) == s always holds, but the converse isn't
    15  // always true.
    16  // @param {String} uri - Uri to escape.
    17  // @return {String} - Escaped string.
    18  func UnescapeHTML(_ context.Context, args ...core.Value) (core.Value, error) {
    19  	err := core.ValidateArgs(args, 1, 1)
    20  
    21  	if err != nil {
    22  		return values.None, err
    23  	}
    24  
    25  	return values.NewString(html.UnescapeString(args[0].String())), nil
    26  }