pub fn encode(input: &str) -> StringExpand description
Encode a Unicode string into a valid UAX 31 identifier.
Returns input unchanged if already a valid XID identifier that doesn’t conflict with our encoding format.
§Examples
use namecode::encode;
// Valid identifiers pass through
assert_eq!(encode("foo"), "foo");
assert_eq!(encode("café"), "café");
// Non-identifier characters trigger encoding
assert_eq!(encode("hello world"), "_N_helloworld__fa0b");
assert_eq!(encode("foo-bar"), "_N_foobar__da1d");
// Idempotent: encoding twice gives the same result
let encoded = encode("hello world");
assert_eq!(encode(&encoded), encoded);