#![doc = include_str!("../README.md")]
use gstring::{GString, GStringTrait, Grapheme};
use std::collections::BTreeMap;
#[allow(clippy::unicode_not_nfc)]
pub const MATCHING: &[(&str, &str)] = &[
("(", ")"),
("[", "]"),
("{", "}"),
("«", "»"),
("‘", "’"),
("“", "”"),
("‹", "›"),
("⁅", "⁆"),
("⁽", "⁾"),
("₍", "₎"),
("⌈", "⌉"),
("⌊", "⌋"),
("〈", "〉"),
("❨", "❩"),
("❪", "❫"),
("❬", "❭"),
("❮", "❯"),
("❰", "❱"),
("❲", "❳"),
("❴", "❵"),
("⟅", "⟆"),
("⟦", "⟧"),
("⟨", "⟩"),
("⟪", "⟫"),
("⟬", "⟭"),
("⟮", "⟯"),
("⦃", "⦄"),
("⦅", "⦆"),
("⦇", "⦈"),
("⦉", "⦊"),
("⦋", "⦌"),
("⦍", "⦎"),
("⦏", "⦐"),
("⦑", "⦒"),
("⦓", "⦔"),
("⦕", "⦖"),
("⦗", "⦘"),
("⧘", "⧙"),
("⧚", "⧛"),
("⧼", "⧽"),
("⸂", "⸃"),
("⸄", "⸅"),
("⸉", "⸊"),
("⸌", "⸍"),
("⸜", "⸝"),
("⸠", "⸡"),
("⸢", "⸣"),
("⸤", "⸥"),
("⸦", "⸧"),
("⸨", "⸩"),
("⹕", "⹖"),
("⹗", "⹘"),
("⹙", "⹚"),
("⹛", "⹜"),
("〈", "〉"),
("《", "》"),
("「", "」"),
("『", "』"),
("【", "】"),
("〔", "〕"),
("〖", "〗"),
("〘", "〙"),
("〚", "〛"),
("﴾", "﴿"),
("︗", "︘"),
("︵", "︶"),
("︷", "︸"),
("︹", "︺"),
("︻", "︼"),
("︽", "︾"),
("︿", "﹀"),
("﹁", "﹂"),
("﹃", "﹄"),
("﹇", "﹈"),
("﹙", "﹚"),
("﹛", "﹜"),
("﹝", "﹞"),
("(", ")"),
("[", "]"),
("{", "}"),
("⦅", "⦆"),
("「", "」"),
];
#[must_use]
pub fn close() -> BTreeMap<&'static str, &'static str> {
MATCHING.iter().copied().collect()
}
#[must_use]
pub fn open() -> BTreeMap<&'static str, &'static str> {
MATCHING
.iter()
.copied()
.map(|(open, close)| (close, open))
.collect()
}
#[must_use]
pub fn matching() -> BTreeMap<&'static str, &'static str> {
MATCHING
.iter()
.copied()
.flat_map(|(open, close)| [(open, close), (close, open)])
.collect()
}
#[allow(clippy::unicode_not_nfc)]
pub const BRACKETS: &[(&str, &str)] = &[
("(", ")"),
("[", "]"),
("{", "}"),
("༺", "༻"),
("༼", "༽"),
("᚛", "᚜"),
("⁅", "⁆"),
("⁽", "⁾"),
("₍", "₎"),
("⌈", "⌉"),
("⌊", "⌋"),
("〈", "〉"),
("❨", "❩"),
("❪", "❫"),
("❬", "❭"),
("❮", "❯"),
("❰", "❱"),
("❲", "❳"),
("❴", "❵"),
("⟅", "⟆"),
("⟦", "⟧"),
("⟨", "⟩"),
("⟪", "⟫"),
("⟬", "⟭"),
("⟮", "⟯"),
("⦃", "⦄"),
("⦅", "⦆"),
("⦇", "⦈"),
("⦉", "⦊"),
("⦋", "⦌"),
("⦍", "⦐"),
("⦏", "⦎"),
("⦑", "⦒"),
("⦓", "⦔"),
("⦕", "⦖"),
("⦗", "⦘"),
("⧘", "⧙"),
("⧚", "⧛"),
("⧼", "⧽"),
("⸢", "⸣"),
("⸤", "⸥"),
("⸦", "⸧"),
("⸨", "⸩"),
("⹕", "⹖"),
("⹗", "⹘"),
("⹙", "⹚"),
("⹛", "⹜"),
("〈", "〉"),
("《", "》"),
("「", "」"),
("『", "』"),
("【", "】"),
("〔", "〕"),
("〖", "〗"),
("〘", "〙"),
("〚", "〛"),
("﹙", "﹚"),
("﹛", "﹜"),
("﹝", "﹞"),
("(", ")"),
("[", "]"),
("{", "}"),
("⦅", "⦆"),
("「", "」"),
];
#[must_use]
pub fn close_brackets() -> BTreeMap<&'static str, &'static str> {
BRACKETS.iter().copied().collect()
}
#[must_use]
pub fn open_brackets() -> BTreeMap<&'static str, &'static str> {
BRACKETS
.iter()
.copied()
.map(|(open, close)| (close, open))
.collect()
}
#[must_use]
pub fn matching_brackets() -> BTreeMap<&'static str, &'static str> {
BRACKETS
.iter()
.copied()
.flat_map(|(open, close)| [(open, close), (close, open)])
.collect()
}
#[allow(clippy::unicode_not_nfc)]
pub const MIRRORING: &[(&str, &str)] = &[
("(", ")"),
("<", ">"),
("[", "]"),
("{", "}"),
("«", "»"),
("༺", "༻"),
("༼", "༽"),
("᚛", "᚜"),
("‹", "›"),
("⁅", "⁆"),
("⁽", "⁾"),
("₍", "₎"),
("∈", "∋"),
("∉", "∌"),
("∊", "∍"),
("∕", "⧵"),
("∟", "⯾"),
("∠", "⦣"),
("∡", "⦛"),
("∢", "⦠"),
("∤", "⫮"),
("∼", "∽"),
("≃", "⋍"),
("≅", "≌"),
("≒", "≓"),
("≔", "≕"),
("≤", "≥"),
("≦", "≧"),
("≨", "≩"),
("≪", "≫"),
("≮", "≯"),
("≰", "≱"),
("≲", "≳"),
("≴", "≵"),
("≶", "≷"),
("≸", "≹"),
("≺", "≻"),
("≼", "≽"),
("≾", "≿"),
("⊀", "⊁"),
("⊂", "⊃"),
("⊄", "⊅"),
("⊆", "⊇"),
("⊈", "⊉"),
("⊊", "⊋"),
("⊏", "⊐"),
("⊑", "⊒"),
("⊘", "⦸"),
("⊢", "⊣"),
("⊦", "⫞"),
("⊨", "⫤"),
("⊩", "⫣"),
("⊫", "⫥"),
("⊰", "⊱"),
("⊲", "⊳"),
("⊴", "⊵"),
("⊶", "⊷"),
("⊸", "⟜"),
("⋉", "⋊"),
("⋋", "⋌"),
("⋐", "⋑"),
("⋖", "⋗"),
("⋘", "⋙"),
("⋚", "⋛"),
("⋜", "⋝"),
("⋞", "⋟"),
("⋠", "⋡"),
("⋢", "⋣"),
("⋤", "⋥"),
("⋦", "⋧"),
("⋨", "⋩"),
("⋪", "⋫"),
("⋬", "⋭"),
("⋰", "⋱"),
("⋲", "⋺"),
("⋳", "⋻"),
("⋴", "⋼"),
("⋶", "⋽"),
("⋷", "⋾"),
("⌈", "⌉"),
("⌊", "⌋"),
("〈", "〉"),
("❨", "❩"),
("❪", "❫"),
("❬", "❭"),
("❮", "❯"),
("❰", "❱"),
("❲", "❳"),
("❴", "❵"),
("⟃", "⟄"),
("⟅", "⟆"),
("⟈", "⟉"),
("⟋", "⟍"),
("⟕", "⟖"),
("⟝", "⟞"),
("⟢", "⟣"),
("⟤", "⟥"),
("⟦", "⟧"),
("⟨", "⟩"),
("⟪", "⟫"),
("⟬", "⟭"),
("⟮", "⟯"),
("⦃", "⦄"),
("⦅", "⦆"),
("⦇", "⦈"),
("⦉", "⦊"),
("⦋", "⦌"),
("⦍", "⦐"),
("⦎", "⦏"),
("⦑", "⦒"),
("⦓", "⦔"),
("⦕", "⦖"),
("⦗", "⦘"),
("⦤", "⦥"),
("⦨", "⦩"),
("⦪", "⦫"),
("⦬", "⦭"),
("⦮", "⦯"),
("⧀", "⧁"),
("⧄", "⧅"),
("⧏", "⧐"),
("⧑", "⧒"),
("⧔", "⧕"),
("⧘", "⧙"),
("⧚", "⧛"),
("⧨", "⧩"),
("⧸", "⧹"),
("⧼", "⧽"),
("⨫", "⨬"),
("⨭", "⨮"),
("⨴", "⨵"),
("⨼", "⨽"),
("⩤", "⩥"),
("⩹", "⩺"),
("⩻", "⩼"),
("⩽", "⩾"),
("⩿", "⪀"),
("⪁", "⪂"),
("⪃", "⪄"),
("⪅", "⪆"),
("⪇", "⪈"),
("⪉", "⪊"),
("⪋", "⪌"),
("⪍", "⪎"),
("⪏", "⪐"),
("⪑", "⪒"),
("⪓", "⪔"),
("⪕", "⪖"),
("⪗", "⪘"),
("⪙", "⪚"),
("⪛", "⪜"),
("⪝", "⪞"),
("⪟", "⪠"),
("⪡", "⪢"),
("⪦", "⪧"),
("⪨", "⪩"),
("⪪", "⪫"),
("⪬", "⪭"),
("⪯", "⪰"),
("⪱", "⪲"),
("⪳", "⪴"),
("⪵", "⪶"),
("⪷", "⪸"),
("⪹", "⪺"),
("⪻", "⪼"),
("⪽", "⪾"),
("⪿", "⫀"),
("⫁", "⫂"),
("⫃", "⫄"),
("⫅", "⫆"),
("⫇", "⫈"),
("⫉", "⫊"),
("⫋", "⫌"),
("⫍", "⫎"),
("⫏", "⫐"),
("⫑", "⫒"),
("⫓", "⫔"),
("⫕", "⫖"),
("⫬", "⫭"),
("⫷", "⫸"),
("⫹", "⫺"),
("⸂", "⸃"),
("⸄", "⸅"),
("⸉", "⸊"),
("⸌", "⸍"),
("⸜", "⸝"),
("⸠", "⸡"),
("⸢", "⸣"),
("⸤", "⸥"),
("⸦", "⸧"),
("⸨", "⸩"),
("⹕", "⹖"),
("⹗", "⹘"),
("⹙", "⹚"),
("⹛", "⹜"),
("〈", "〉"),
("《", "》"),
("「", "」"),
("『", "』"),
("【", "】"),
("〔", "〕"),
("〖", "〗"),
("〘", "〙"),
("〚", "〛"),
("﹙", "﹚"),
("﹛", "﹜"),
("﹝", "﹞"),
("﹤", "﹥"),
("(", ")"),
("<", ">"),
("[", "]"),
("{", "}"),
("⦅", "⦆"),
("「", "」"),
];
#[must_use]
pub fn close_mirroring() -> BTreeMap<&'static str, &'static str> {
MIRRORING.iter().copied().collect()
}
#[must_use]
pub fn open_mirroring() -> BTreeMap<&'static str, &'static str> {
MIRRORING
.iter()
.copied()
.map(|(open, close)| (close, open))
.collect()
}
#[must_use]
pub fn matching_mirroring() -> BTreeMap<&'static str, &'static str> {
MIRRORING
.iter()
.copied()
.flat_map(|(open, close)| [(open, close), (close, open)])
.collect()
}
#[allow(clippy::unicode_not_nfc)]
pub const BRACKETS_MATCHING: &[(&str, &str)] = &[
("(", ")"),
("[", "]"),
("{", "}"),
("«", "»"),
("༺", "༻"),
("༼", "༽"),
("᚛", "᚜"),
("‘", "’"),
("“", "”"),
("‹", "›"),
("⁅", "⁆"),
("⁽", "⁾"),
("₍", "₎"),
("⌈", "⌉"),
("⌊", "⌋"),
("〈", "〉"),
("❨", "❩"),
("❪", "❫"),
("❬", "❭"),
("❮", "❯"),
("❰", "❱"),
("❲", "❳"),
("❴", "❵"),
("⟅", "⟆"),
("⟦", "⟧"),
("⟨", "⟩"),
("⟪", "⟫"),
("⟬", "⟭"),
("⟮", "⟯"),
("⦃", "⦄"),
("⦅", "⦆"),
("⦇", "⦈"),
("⦉", "⦊"),
("⦋", "⦌"),
("⦍", "⦎"),
("⦏", "⦐"),
("⦑", "⦒"),
("⦓", "⦔"),
("⦕", "⦖"),
("⦗", "⦘"),
("⧘", "⧙"),
("⧚", "⧛"),
("⧼", "⧽"),
("⸂", "⸃"),
("⸄", "⸅"),
("⸉", "⸊"),
("⸌", "⸍"),
("⸜", "⸝"),
("⸠", "⸡"),
("⸢", "⸣"),
("⸤", "⸥"),
("⸦", "⸧"),
("⸨", "⸩"),
("⹕", "⹖"),
("⹗", "⹘"),
("⹙", "⹚"),
("⹛", "⹜"),
("〈", "〉"),
("《", "》"),
("「", "」"),
("『", "』"),
("【", "】"),
("〔", "〕"),
("〖", "〗"),
("〘", "〙"),
("〚", "〛"),
("﴾", "﴿"),
("︗", "︘"),
("︵", "︶"),
("︷", "︸"),
("︹", "︺"),
("︻", "︼"),
("︽", "︾"),
("︿", "﹀"),
("﹁", "﹂"),
("﹃", "﹄"),
("﹇", "﹈"),
("﹙", "﹚"),
("﹛", "﹜"),
("﹝", "﹞"),
("(", ")"),
("[", "]"),
("{", "}"),
("⦅", "⦆"),
("「", "」"),
];
#[must_use]
pub fn close_brackets_matching() -> BTreeMap<&'static str, &'static str> {
BRACKETS_MATCHING.iter().copied().collect()
}
#[must_use]
pub fn open_brackets_matching() -> BTreeMap<&'static str, &'static str> {
BRACKETS_MATCHING
.iter()
.copied()
.map(|(open, close)| (close, open))
.collect()
}
#[must_use]
pub fn matching_brackets_matching() -> BTreeMap<&'static str, &'static str> {
BRACKETS_MATCHING
.iter()
.copied()
.flat_map(|(open, close)| [(open, close), (close, open)])
.collect()
}
#[allow(clippy::unicode_not_nfc)]
pub const BRACKETS_MIRRORING: &[(&str, &str)] = &[
("(", ")"),
("<", ">"),
("[", "]"),
("{", "}"),
("«", "»"),
("༺", "༻"),
("༼", "༽"),
("᚛", "᚜"),
("‹", "›"),
("⁅", "⁆"),
("⁽", "⁾"),
("₍", "₎"),
("∈", "∋"),
("∉", "∌"),
("∊", "∍"),
("∕", "⧵"),
("∟", "⯾"),
("∠", "⦣"),
("∡", "⦛"),
("∢", "⦠"),
("∤", "⫮"),
("∼", "∽"),
("≃", "⋍"),
("≅", "≌"),
("≒", "≓"),
("≔", "≕"),
("≤", "≥"),
("≦", "≧"),
("≨", "≩"),
("≪", "≫"),
("≮", "≯"),
("≰", "≱"),
("≲", "≳"),
("≴", "≵"),
("≶", "≷"),
("≸", "≹"),
("≺", "≻"),
("≼", "≽"),
("≾", "≿"),
("⊀", "⊁"),
("⊂", "⊃"),
("⊄", "⊅"),
("⊆", "⊇"),
("⊈", "⊉"),
("⊊", "⊋"),
("⊏", "⊐"),
("⊑", "⊒"),
("⊘", "⦸"),
("⊢", "⊣"),
("⊦", "⫞"),
("⊨", "⫤"),
("⊩", "⫣"),
("⊫", "⫥"),
("⊰", "⊱"),
("⊲", "⊳"),
("⊴", "⊵"),
("⊶", "⊷"),
("⊸", "⟜"),
("⋉", "⋊"),
("⋋", "⋌"),
("⋐", "⋑"),
("⋖", "⋗"),
("⋘", "⋙"),
("⋚", "⋛"),
("⋜", "⋝"),
("⋞", "⋟"),
("⋠", "⋡"),
("⋢", "⋣"),
("⋤", "⋥"),
("⋦", "⋧"),
("⋨", "⋩"),
("⋪", "⋫"),
("⋬", "⋭"),
("⋰", "⋱"),
("⋲", "⋺"),
("⋳", "⋻"),
("⋴", "⋼"),
("⋶", "⋽"),
("⋷", "⋾"),
("⌈", "⌉"),
("⌊", "⌋"),
("〈", "〉"),
("❨", "❩"),
("❪", "❫"),
("❬", "❭"),
("❮", "❯"),
("❰", "❱"),
("❲", "❳"),
("❴", "❵"),
("⟃", "⟄"),
("⟅", "⟆"),
("⟈", "⟉"),
("⟋", "⟍"),
("⟕", "⟖"),
("⟝", "⟞"),
("⟢", "⟣"),
("⟤", "⟥"),
("⟦", "⟧"),
("⟨", "⟩"),
("⟪", "⟫"),
("⟬", "⟭"),
("⟮", "⟯"),
("⦃", "⦄"),
("⦅", "⦆"),
("⦇", "⦈"),
("⦉", "⦊"),
("⦋", "⦌"),
("⦍", "⦐"),
("⦎", "⦏"),
("⦏", "⦎"),
("⦑", "⦒"),
("⦓", "⦔"),
("⦕", "⦖"),
("⦗", "⦘"),
("⦤", "⦥"),
("⦨", "⦩"),
("⦪", "⦫"),
("⦬", "⦭"),
("⦮", "⦯"),
("⧀", "⧁"),
("⧄", "⧅"),
("⧏", "⧐"),
("⧑", "⧒"),
("⧔", "⧕"),
("⧘", "⧙"),
("⧚", "⧛"),
("⧨", "⧩"),
("⧸", "⧹"),
("⧼", "⧽"),
("⨫", "⨬"),
("⨭", "⨮"),
("⨴", "⨵"),
("⨼", "⨽"),
("⩤", "⩥"),
("⩹", "⩺"),
("⩻", "⩼"),
("⩽", "⩾"),
("⩿", "⪀"),
("⪁", "⪂"),
("⪃", "⪄"),
("⪅", "⪆"),
("⪇", "⪈"),
("⪉", "⪊"),
("⪋", "⪌"),
("⪍", "⪎"),
("⪏", "⪐"),
("⪑", "⪒"),
("⪓", "⪔"),
("⪕", "⪖"),
("⪗", "⪘"),
("⪙", "⪚"),
("⪛", "⪜"),
("⪝", "⪞"),
("⪟", "⪠"),
("⪡", "⪢"),
("⪦", "⪧"),
("⪨", "⪩"),
("⪪", "⪫"),
("⪬", "⪭"),
("⪯", "⪰"),
("⪱", "⪲"),
("⪳", "⪴"),
("⪵", "⪶"),
("⪷", "⪸"),
("⪹", "⪺"),
("⪻", "⪼"),
("⪽", "⪾"),
("⪿", "⫀"),
("⫁", "⫂"),
("⫃", "⫄"),
("⫅", "⫆"),
("⫇", "⫈"),
("⫉", "⫊"),
("⫋", "⫌"),
("⫍", "⫎"),
("⫏", "⫐"),
("⫑", "⫒"),
("⫓", "⫔"),
("⫕", "⫖"),
("⫬", "⫭"),
("⫷", "⫸"),
("⫹", "⫺"),
("⸂", "⸃"),
("⸄", "⸅"),
("⸉", "⸊"),
("⸌", "⸍"),
("⸜", "⸝"),
("⸠", "⸡"),
("⸢", "⸣"),
("⸤", "⸥"),
("⸦", "⸧"),
("⸨", "⸩"),
("⹕", "⹖"),
("⹗", "⹘"),
("⹙", "⹚"),
("⹛", "⹜"),
("〈", "〉"),
("《", "》"),
("「", "」"),
("『", "』"),
("【", "】"),
("〔", "〕"),
("〖", "〗"),
("〘", "〙"),
("〚", "〛"),
("﹙", "﹚"),
("﹛", "﹜"),
("﹝", "﹞"),
("﹤", "﹥"),
("(", ")"),
("<", ">"),
("[", "]"),
("{", "}"),
("⦅", "⦆"),
("「", "」"),
];
#[must_use]
pub fn close_brackets_mirroring() -> BTreeMap<&'static str, &'static str> {
BRACKETS_MIRRORING.iter().copied().collect()
}
#[must_use]
pub fn open_brackets_mirroring() -> BTreeMap<&'static str, &'static str> {
BRACKETS_MIRRORING
.iter()
.copied()
.map(|(open, close)| (close, open))
.collect()
}
#[must_use]
pub fn matching_brackets_mirroring() -> BTreeMap<&'static str, &'static str> {
BRACKETS_MIRRORING
.iter()
.copied()
.flat_map(|(open, close)| [(open, close), (close, open)])
.collect()
}
#[allow(clippy::unicode_not_nfc)]
pub const MIRRORING_MATCHING: &[(&str, &str)] = &[
("(", ")"),
("<", ">"),
("[", "]"),
("{", "}"),
("«", "»"),
("༺", "༻"),
("༼", "༽"),
("᚛", "᚜"),
("‘", "’"),
("“", "”"),
("‹", "›"),
("⁅", "⁆"),
("⁽", "⁾"),
("₍", "₎"),
("∈", "∋"),
("∉", "∌"),
("∊", "∍"),
("∕", "⧵"),
("∟", "⯾"),
("∠", "⦣"),
("∡", "⦛"),
("∢", "⦠"),
("∤", "⫮"),
("∼", "∽"),
("≃", "⋍"),
("≅", "≌"),
("≒", "≓"),
("≔", "≕"),
("≤", "≥"),
("≦", "≧"),
("≨", "≩"),
("≪", "≫"),
("≮", "≯"),
("≰", "≱"),
("≲", "≳"),
("≴", "≵"),
("≶", "≷"),
("≸", "≹"),
("≺", "≻"),
("≼", "≽"),
("≾", "≿"),
("⊀", "⊁"),
("⊂", "⊃"),
("⊄", "⊅"),
("⊆", "⊇"),
("⊈", "⊉"),
("⊊", "⊋"),
("⊏", "⊐"),
("⊑", "⊒"),
("⊘", "⦸"),
("⊢", "⊣"),
("⊦", "⫞"),
("⊨", "⫤"),
("⊩", "⫣"),
("⊫", "⫥"),
("⊰", "⊱"),
("⊲", "⊳"),
("⊴", "⊵"),
("⊶", "⊷"),
("⊸", "⟜"),
("⋉", "⋊"),
("⋋", "⋌"),
("⋐", "⋑"),
("⋖", "⋗"),
("⋘", "⋙"),
("⋚", "⋛"),
("⋜", "⋝"),
("⋞", "⋟"),
("⋠", "⋡"),
("⋢", "⋣"),
("⋤", "⋥"),
("⋦", "⋧"),
("⋨", "⋩"),
("⋪", "⋫"),
("⋬", "⋭"),
("⋰", "⋱"),
("⋲", "⋺"),
("⋳", "⋻"),
("⋴", "⋼"),
("⋶", "⋽"),
("⋷", "⋾"),
("⌈", "⌉"),
("⌊", "⌋"),
("〈", "〉"),
("❨", "❩"),
("❪", "❫"),
("❬", "❭"),
("❮", "❯"),
("❰", "❱"),
("❲", "❳"),
("❴", "❵"),
("⟃", "⟄"),
("⟅", "⟆"),
("⟈", "⟉"),
("⟋", "⟍"),
("⟕", "⟖"),
("⟝", "⟞"),
("⟢", "⟣"),
("⟤", "⟥"),
("⟦", "⟧"),
("⟨", "⟩"),
("⟪", "⟫"),
("⟬", "⟭"),
("⟮", "⟯"),
("⦃", "⦄"),
("⦅", "⦆"),
("⦇", "⦈"),
("⦉", "⦊"),
("⦋", "⦌"),
("⦍", "⦎"),
("⦎", "⦏"),
("⦏", "⦐"),
("⦑", "⦒"),
("⦓", "⦔"),
("⦕", "⦖"),
("⦗", "⦘"),
("⦤", "⦥"),
("⦨", "⦩"),
("⦪", "⦫"),
("⦬", "⦭"),
("⦮", "⦯"),
("⧀", "⧁"),
("⧄", "⧅"),
("⧏", "⧐"),
("⧑", "⧒"),
("⧔", "⧕"),
("⧘", "⧙"),
("⧚", "⧛"),
("⧨", "⧩"),
("⧸", "⧹"),
("⧼", "⧽"),
("⨫", "⨬"),
("⨭", "⨮"),
("⨴", "⨵"),
("⨼", "⨽"),
("⩤", "⩥"),
("⩹", "⩺"),
("⩻", "⩼"),
("⩽", "⩾"),
("⩿", "⪀"),
("⪁", "⪂"),
("⪃", "⪄"),
("⪅", "⪆"),
("⪇", "⪈"),
("⪉", "⪊"),
("⪋", "⪌"),
("⪍", "⪎"),
("⪏", "⪐"),
("⪑", "⪒"),
("⪓", "⪔"),
("⪕", "⪖"),
("⪗", "⪘"),
("⪙", "⪚"),
("⪛", "⪜"),
("⪝", "⪞"),
("⪟", "⪠"),
("⪡", "⪢"),
("⪦", "⪧"),
("⪨", "⪩"),
("⪪", "⪫"),
("⪬", "⪭"),
("⪯", "⪰"),
("⪱", "⪲"),
("⪳", "⪴"),
("⪵", "⪶"),
("⪷", "⪸"),
("⪹", "⪺"),
("⪻", "⪼"),
("⪽", "⪾"),
("⪿", "⫀"),
("⫁", "⫂"),
("⫃", "⫄"),
("⫅", "⫆"),
("⫇", "⫈"),
("⫉", "⫊"),
("⫋", "⫌"),
("⫍", "⫎"),
("⫏", "⫐"),
("⫑", "⫒"),
("⫓", "⫔"),
("⫕", "⫖"),
("⫬", "⫭"),
("⫷", "⫸"),
("⫹", "⫺"),
("⸂", "⸃"),
("⸄", "⸅"),
("⸉", "⸊"),
("⸌", "⸍"),
("⸜", "⸝"),
("⸠", "⸡"),
("⸢", "⸣"),
("⸤", "⸥"),
("⸦", "⸧"),
("⸨", "⸩"),
("⹕", "⹖"),
("⹗", "⹘"),
("⹙", "⹚"),
("⹛", "⹜"),
("〈", "〉"),
("《", "》"),
("「", "」"),
("『", "』"),
("【", "】"),
("〔", "〕"),
("〖", "〗"),
("〘", "〙"),
("〚", "〛"),
("﴾", "﴿"),
("︗", "︘"),
("︵", "︶"),
("︷", "︸"),
("︹", "︺"),
("︻", "︼"),
("︽", "︾"),
("︿", "﹀"),
("﹁", "﹂"),
("﹃", "﹄"),
("﹇", "﹈"),
("﹙", "﹚"),
("﹛", "﹜"),
("﹝", "﹞"),
("﹤", "﹥"),
("(", ")"),
("<", ">"),
("[", "]"),
("{", "}"),
("⦅", "⦆"),
("「", "」"),
];
#[must_use]
pub fn close_mirroring_matching() -> BTreeMap<&'static str, &'static str> {
MIRRORING_MATCHING.iter().copied().collect()
}
#[must_use]
pub fn open_mirroring_matching() -> BTreeMap<&'static str, &'static str> {
MIRRORING_MATCHING
.iter()
.copied()
.map(|(open, close)| (close, open))
.collect()
}
#[must_use]
pub fn matching_mirroring_matching() -> BTreeMap<&'static str, &'static str> {
MIRRORING_MATCHING
.iter()
.copied()
.flat_map(|(open, close)| [(open, close), (close, open)])
.collect()
}
#[allow(clippy::unicode_not_nfc)]
pub const ALL: &[(&str, &str)] = &[
("(", ")"),
("<", ">"),
("[", "]"),
("{", "}"),
("«", "»"),
("༺", "༻"),
("༼", "༽"),
("᚛", "᚜"),
("‘", "’"),
("“", "”"),
("‹", "›"),
("⁅", "⁆"),
("⁽", "⁾"),
("₍", "₎"),
("∈", "∋"),
("∉", "∌"),
("∊", "∍"),
("∕", "⧵"),
("∟", "⯾"),
("∠", "⦣"),
("∡", "⦛"),
("∢", "⦠"),
("∤", "⫮"),
("∼", "∽"),
("≃", "⋍"),
("≅", "≌"),
("≒", "≓"),
("≔", "≕"),
("≤", "≥"),
("≦", "≧"),
("≨", "≩"),
("≪", "≫"),
("≮", "≯"),
("≰", "≱"),
("≲", "≳"),
("≴", "≵"),
("≶", "≷"),
("≸", "≹"),
("≺", "≻"),
("≼", "≽"),
("≾", "≿"),
("⊀", "⊁"),
("⊂", "⊃"),
("⊄", "⊅"),
("⊆", "⊇"),
("⊈", "⊉"),
("⊊", "⊋"),
("⊏", "⊐"),
("⊑", "⊒"),
("⊘", "⦸"),
("⊢", "⊣"),
("⊦", "⫞"),
("⊨", "⫤"),
("⊩", "⫣"),
("⊫", "⫥"),
("⊰", "⊱"),
("⊲", "⊳"),
("⊴", "⊵"),
("⊶", "⊷"),
("⊸", "⟜"),
("⋉", "⋊"),
("⋋", "⋌"),
("⋐", "⋑"),
("⋖", "⋗"),
("⋘", "⋙"),
("⋚", "⋛"),
("⋜", "⋝"),
("⋞", "⋟"),
("⋠", "⋡"),
("⋢", "⋣"),
("⋤", "⋥"),
("⋦", "⋧"),
("⋨", "⋩"),
("⋪", "⋫"),
("⋬", "⋭"),
("⋰", "⋱"),
("⋲", "⋺"),
("⋳", "⋻"),
("⋴", "⋼"),
("⋶", "⋽"),
("⋷", "⋾"),
("⌈", "⌉"),
("⌊", "⌋"),
("〈", "〉"),
("❨", "❩"),
("❪", "❫"),
("❬", "❭"),
("❮", "❯"),
("❰", "❱"),
("❲", "❳"),
("❴", "❵"),
("⟃", "⟄"),
("⟅", "⟆"),
("⟈", "⟉"),
("⟋", "⟍"),
("⟕", "⟖"),
("⟝", "⟞"),
("⟢", "⟣"),
("⟤", "⟥"),
("⟦", "⟧"),
("⟨", "⟩"),
("⟪", "⟫"),
("⟬", "⟭"),
("⟮", "⟯"),
("⦃", "⦄"),
("⦅", "⦆"),
("⦇", "⦈"),
("⦉", "⦊"),
("⦋", "⦌"),
("⦍", "⦎"),
("⦎", "⦏"),
("⦏", "⦐"),
("⦑", "⦒"),
("⦓", "⦔"),
("⦕", "⦖"),
("⦗", "⦘"),
("⦤", "⦥"),
("⦨", "⦩"),
("⦪", "⦫"),
("⦬", "⦭"),
("⦮", "⦯"),
("⧀", "⧁"),
("⧄", "⧅"),
("⧏", "⧐"),
("⧑", "⧒"),
("⧔", "⧕"),
("⧘", "⧙"),
("⧚", "⧛"),
("⧨", "⧩"),
("⧸", "⧹"),
("⧼", "⧽"),
("⨫", "⨬"),
("⨭", "⨮"),
("⨴", "⨵"),
("⨼", "⨽"),
("⩤", "⩥"),
("⩹", "⩺"),
("⩻", "⩼"),
("⩽", "⩾"),
("⩿", "⪀"),
("⪁", "⪂"),
("⪃", "⪄"),
("⪅", "⪆"),
("⪇", "⪈"),
("⪉", "⪊"),
("⪋", "⪌"),
("⪍", "⪎"),
("⪏", "⪐"),
("⪑", "⪒"),
("⪓", "⪔"),
("⪕", "⪖"),
("⪗", "⪘"),
("⪙", "⪚"),
("⪛", "⪜"),
("⪝", "⪞"),
("⪟", "⪠"),
("⪡", "⪢"),
("⪦", "⪧"),
("⪨", "⪩"),
("⪪", "⪫"),
("⪬", "⪭"),
("⪯", "⪰"),
("⪱", "⪲"),
("⪳", "⪴"),
("⪵", "⪶"),
("⪷", "⪸"),
("⪹", "⪺"),
("⪻", "⪼"),
("⪽", "⪾"),
("⪿", "⫀"),
("⫁", "⫂"),
("⫃", "⫄"),
("⫅", "⫆"),
("⫇", "⫈"),
("⫉", "⫊"),
("⫋", "⫌"),
("⫍", "⫎"),
("⫏", "⫐"),
("⫑", "⫒"),
("⫓", "⫔"),
("⫕", "⫖"),
("⫬", "⫭"),
("⫷", "⫸"),
("⫹", "⫺"),
("⸂", "⸃"),
("⸄", "⸅"),
("⸉", "⸊"),
("⸌", "⸍"),
("⸜", "⸝"),
("⸠", "⸡"),
("⸢", "⸣"),
("⸤", "⸥"),
("⸦", "⸧"),
("⸨", "⸩"),
("⹕", "⹖"),
("⹗", "⹘"),
("⹙", "⹚"),
("⹛", "⹜"),
("〈", "〉"),
("《", "》"),
("「", "」"),
("『", "』"),
("【", "】"),
("〔", "〕"),
("〖", "〗"),
("〘", "〙"),
("〚", "〛"),
("﴾", "﴿"),
("︗", "︘"),
("︵", "︶"),
("︷", "︸"),
("︹", "︺"),
("︻", "︼"),
("︽", "︾"),
("︿", "﹀"),
("﹁", "﹂"),
("﹃", "﹄"),
("﹇", "﹈"),
("﹙", "﹚"),
("﹛", "﹜"),
("﹝", "﹞"),
("﹤", "﹥"),
("(", ")"),
("<", ">"),
("[", "]"),
("{", "}"),
("⦅", "⦆"),
("「", "」"),
];
#[must_use]
pub fn close_all() -> BTreeMap<&'static str, &'static str> {
ALL.iter().copied().collect()
}
#[must_use]
pub fn open_all() -> BTreeMap<&'static str, &'static str> {
ALL.iter()
.copied()
.map(|(open, close)| (close, open))
.collect()
}
#[must_use]
pub fn matching_all() -> BTreeMap<&'static str, &'static str> {
ALL.iter()
.copied()
.flat_map(|(open, close)| [(open, close), (close, open)])
.collect()
}
pub trait FindMatching {
fn find_matching(
&self,
position: usize,
closing: &BTreeMap<&str, &str>,
opening: &BTreeMap<&str, &str>,
) -> usize;
}
impl FindMatching for str {
fn find_matching(
&self,
position: usize,
closing: &BTreeMap<&str, &str>,
opening: &BTreeMap<&str, &str>,
) -> usize {
self.gstring().find_matching(position, closing, opening)
}
}
impl FindMatching for GString {
fn find_matching(
&self,
position: usize,
closing: &BTreeMap<&str, &str>,
opening: &BTreeMap<&str, &str>,
) -> usize {
let v = self.graphemes();
if position >= v.len() {
return position;
}
let close = closing.get(&v[position].as_str());
let open = opening.get(&v[position].as_str());
if close.is_none() && open.is_none() {
return position;
}
let mut stack: Vec<(usize, &Grapheme)> = vec![];
for (i, g) in v.iter().enumerate() {
if let Some(open) = opening.get(&g.as_str()) {
if let Some(prev) = stack.pop() {
if prev.1 == open {
if prev.0 == position {
return i;
} else if i == position {
return prev.0;
}
} else if closing.contains_key(&g.as_str()) {
stack.push(prev);
stack.push((i, g));
} else {
return position;
}
} else if closing.contains_key(&g.as_str()) {
stack.push((i, g));
}
} else if closing.contains_key(&g.as_str()) {
stack.push((i, g));
}
}
position
}
}