Skip to content

Instantly share code, notes, and snippets.

@eraserhd
Created May 3, 2022 16:02
Show Gist options
  • Save eraserhd/1a227dbac1ce1202463dffab95061489 to your computer and use it in GitHub Desktop.
Save eraserhd/1a227dbac1ce1202463dffab95061489 to your computer and use it in GitHub Desktop.
package conf
import (
"list"
"strings"
"text/template"
)
#URLEncoding: {
let doNotEncode = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_."
for c in strings.Split(doNotEncode, "")
{"\(c)": "\(c)"}
for n in list.Range(0, 127, 1)
if !strings.Contains(doNotEncode, template.Execute("{{printf \"%c\" .}}", n))
{"\(template.Execute("{{printf \"%c\" .}}", n))": template.Execute("{{printf \"%%%02X\" .}}", n)}
}
// Use: ((#URLEncode & {input: "foo"}).result)
#URLEncode: {
input: string
result: strings.Join([ for ch in strings.Split(input, "") {#URLEncoding[ch]}], "")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment