Provides an interface for translating a string into various common encodings.
Currently provided are: base64, idna, stringprep.
local encodings = require "util.encodings"; print(encodings.base64.encode("Hello world!")) -- prints "SGVsbG8gd29ybGQh" -- or individually -- local base64 = require "util.encodings".base64; local idna = require "util.encodings".idna; local stringprep = require "util.encodings".stringprep;
Returns a base64-encoded equivalent of a string.
Returns a decoded equivalent of a base64 string, or nil if the string is invalid base64.
IDNA provides a way to safely convert unicode domain names to an ASCII equivalent, and back again.
Returns an ASCII-safe version of a unicode domain name, or nil for an invalid domain.
Example:
print(encodings.idna.to_ascii("➡.ws"))
xn--hgi.ws
Returns the original unicode version of an ASCII IDNA-encoded domain.
Example:
print(encodings.idna.to_ascii("➡.ws"))
➡.ws
Stringprep defines a way of processing and normalizing strings according to a set of rules (a profile). Prosody implements 4profiles:
Example:
print(encodings.stringprep.nodeprep("HelloWorld"))
helloworld
All stringprep functions return nil when the input is not a valid string in that particular profile.