This commit is contained in:
Andras Schmelczer 2024-11-17 22:12:27 +00:00
parent a471bf6855
commit 7f6973389f
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
21 changed files with 30682 additions and 236 deletions

View file

@ -0,0 +1 @@
pub mod token;

View file

@ -0,0 +1,26 @@
#[derive(Debug, Clone)]
pub struct Token {
pub normalised: String,
pub original: String,
}
impl Token {
pub fn new(normalised: String, original: String) -> Self {
Token {
normalised,
original,
}
}
pub fn tokenize(text: &str) -> Vec<Token> {
text.split_inclusive(|c: char| c.is_whitespace())
.map(|s| Token::new(s.to_string(), s.to_string()))
.collect()
}
}
impl PartialEq for Token {
fn eq(&self, other: &Self) -> bool {
self.normalised == other.normalised
}
}