# emoji-test-regex-pattern

Precomputed regex patterns and text assets that match every RGI emoji symbol
and sequence in the Unicode `emoji-test.txt` file, for Emoji versions 13.0
through 17.0.

The patterns follow Unicode Technical Standard #51. Each pattern is built to
match every emoji string for its version in full on its target engine. The test
suite verifies this for the `javascript` and `javascript-u` forms with the Rust
`regex` crate. The crate ships eight assets per version: a human-readable index,
a plain list of emoji strings, a CSS `unicode-range` value, three JavaScript
patterns (no flag, `u` flag, `v` flag), a Java pattern, and a Google RE2
pattern.

## Installation

```toml
[dependencies]
emoji-test-regex-pattern = "0.1"
```

## Usage

```rust
use emoji_test_regex_pattern::{output, EmojiVersion, OutputKind};

// The JavaScript u-flag pattern for the newest version.
let pattern = output(EmojiVersion::Latest, OutputKind::JavaScriptU);

// The CSS unicode-range for Emoji 13.0.
let css = output(EmojiVersion::V13_0, OutputKind::Css);
```

The JavaScript, Java, and RE2 patterns target foreign engines. To match emoji
directly in Rust with the `regex` crate, use `OutputKind::CppRe2`. Its `\x{...}`
escapes are the form `regex` accepts, and it matches full emoji sequences:

```rust
use emoji_test_regex_pattern::{output, EmojiVersion, OutputKind};

let pattern = output(EmojiVersion::Latest, OutputKind::CppRe2);
let re = regex::Regex::new(pattern).unwrap();
assert_eq!(re.find("\u{1F44D}\u{1F3FF}").unwrap().as_str(), "\u{1F44D}\u{1F3FF}");
```

`EmojiVersion::Latest` resolves to the highest version. Read any version with
its enum variant or parse it from a string:

```rust
use emoji_test_regex_pattern::EmojiVersion;

let version: EmojiVersion = "15.1".parse().unwrap();

// Unknown input reports the offending string.
let err = "12.0".parse::<EmojiVersion>().unwrap_err();
assert_eq!(err.to_string(), "unknown emoji version: 12.0");
```

The index, index-strings, and CSS assets end with a newline. The five regex
patterns do not. Call `OutputKind::has_trailing_newline` to check.

## Regenerating the text assets

The index, index-strings, and CSS assets are also produced by pure functions in
the `generate` module. Give them a list of emoji strings and they rebuild the
asset text. The five regex patterns come from a trie minimizer and ship as data.

## License

Licensed under the [MIT license](LICENSE).
