diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-10-06 12:12:36 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-10-06 12:12:36 +0200 |
commit | 6e80e03bb6d6af47aba2b339f160e4895ab5afba (patch) | |
tree | 98ecdfd1d73065ae45846320ccf43e5eb8c8cced /src/util | |
parent | b75d7976cfe8db43783b930c1f4774f2ad4936f5 (diff) | |
download | markdown-rs-6e80e03bb6d6af47aba2b339f160e4895ab5afba.tar.gz markdown-rs-6e80e03bb6d6af47aba2b339f160e4895ab5afba.tar.bz2 markdown-rs-6e80e03bb6d6af47aba2b339f160e4895ab5afba.zip |
Refactor to share identifier methods
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/identifier.rs | 15 | ||||
-rw-r--r-- | src/util/mod.rs | 1 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/util/identifier.rs b/src/util/identifier.rs new file mode 100644 index 0000000..4887e02 --- /dev/null +++ b/src/util/identifier.rs @@ -0,0 +1,15 @@ +//! Info on JavaScript identifiers. + +use unicode_id::UnicodeID; + +/// Check if a character can start a JS identifier. +pub fn id_start(char: char) -> bool { + UnicodeID::is_id_start(char) || matches!(char, '$' | '_') +} + +/// Check if a character can continue a JS (or JSX) identifier. +pub fn id_cont(char: char, jsx: bool) -> bool { + UnicodeID::is_id_continue(char) + || matches!(char, '\u{200c}' | '\u{200d}') + || (jsx && char == '-') +} diff --git a/src/util/mod.rs b/src/util/mod.rs index edc7e14..ac93be0 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -6,6 +6,7 @@ pub mod constant; pub mod edit_map; pub mod encode; pub mod gfm_tagfilter; +pub mod identifier; pub mod infer; pub mod mdx_collect; pub mod normalize_identifier; |