aboutsummaryrefslogtreecommitdiffstats
path: root/src/util/classify_character.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-09-09 10:54:13 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-09-09 10:54:13 +0200
commit13337d77954b4c92d1cf4592f43f01d94fce3c77 (patch)
treed5feef9a971c1af52e58b5c857d1dd9c9e7fedca /src/util/classify_character.rs
parent71dbc8c0189d6b2032f3d8f21cbfffa3f8fe0f12 (diff)
downloadmarkdown-rs-13337d77954b4c92d1cf4592f43f01d94fce3c77.tar.gz
markdown-rs-13337d77954b4c92d1cf4592f43f01d94fce3c77.tar.bz2
markdown-rs-13337d77954b4c92d1cf4592f43f01d94fce3c77.zip
Refactor to move byte, char info to own file
Diffstat (limited to '')
-rw-r--r--src/util/classify_character.rs72
1 files changed, 0 insertions, 72 deletions
diff --git a/src/util/classify_character.rs b/src/util/classify_character.rs
deleted file mode 100644
index 79ed46a..0000000
--- a/src/util/classify_character.rs
+++ /dev/null
@@ -1,72 +0,0 @@
-//! Utilities to classify characters as whitespace, punctuation, or rest.
-
-use crate::util::unicode::PUNCTUATION;
-
-/// Character kinds.
-#[derive(Debug, PartialEq, Eq)]
-pub enum Kind {
- /// Whitespace.
- ///
- /// ## Example
- ///
- /// ```markdown
- /// > | **a_b_ c**.
- /// ^ ^ ^
- /// ```
- Whitespace,
- /// Punctuation.
- ///
- /// ## Example
- ///
- /// ```markdown
- /// > | **a_b_ c**.
- /// ^^ ^ ^ ^
- /// ```
- Punctuation,
- /// Everything else.
- ///
- /// ## Example
- ///
- /// ```markdown
- /// > | **a_b_ c**.
- /// ^ ^ ^
- /// ```
- Other,
-}
-
-/// Classify whether a character code represents whitespace, punctuation, or
-/// something else.
-///
-/// Used for attention (emphasis, strong), whose sequences can open or close
-/// based on the class of surrounding characters.
-///
-/// > 👉 **Note** that eof (`None`) is seen as whitespace.
-///
-/// ## References
-///
-/// * [`micromark-util-classify-character` in `micromark`](https://github.com/micromark/micromark/blob/main/packages/micromark-util-classify-character/dev/index.js)
-pub fn classify(char: char) -> Kind {
- // Unicode whitespace.
- if char.is_whitespace() {
- Kind::Whitespace
- }
- // Unicode punctuation.
- else if PUNCTUATION.contains(&char) {
- Kind::Punctuation
- }
- // Everything else.
- else {
- Kind::Other
- }
-}
-
-/// Like [`classify`], but supports eof as whitespace.
-pub fn classify_opt(char_opt: Option<char>) -> Kind {
- if let Some(char) = char_opt {
- classify(char)
- }
- // EOF.
- else {
- Kind::Whitespace
- }
-}