Module fluent_syntax::unicode

source ·
Expand description

A set of helper functions for unescaping Fluent unicode escape sequences.

§Unicode

Fluent supports UTF-8 in all FTL resources, but it also allows unicode sequences to be escaped in String Literals.

Four byte sequences are encoded with \u and six byte sequences using \U.

§Example

use fluent_syntax::unicode::unescape_unicode_to_string;

assert_eq!(
    unescape_unicode_to_string("Foo \\u5bd2 Bar"),
    "Foo 寒 Bar"
);

assert_eq!(
    unescape_unicode_to_string("Foo \\U01F68A Bar"),
    "Foo 🚊 Bar"
);

§Other unescapes

This also allows for a char " to be present inside an FTL string literal, and for \ itself to be escaped.

§Example

use fluent_syntax::unicode::unescape_unicode_to_string;

assert_eq!(
    unescape_unicode_to_string("Foo \\\" Bar"),
    "Foo \" Bar"
);
assert_eq!(
    unescape_unicode_to_string("Foo \\\\ Bar"),
    "Foo \\ Bar"
);

Functions§