mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-03 00:47:53 +00:00
Cleanup symbol pattern matching
This commit is contained in:
1 parent
376b19fc06
commit
e8ab38fda0
2 files changed
+23
-52
No files matched your search
@@ -9,12 +9,14 @@ Audio Samples
|
||||
|
||||
Tokenizing
|
||||
- Plurals
|
||||
- Decimal numbers
|
||||
- Times (9 p.m. ET)
|
||||
|
||||
Parsing
|
||||
- (Everything in tokenizing)
|
||||
- CamelCase
|
||||
- hyphenated-words
|
||||
- Monetary units ($10 -> ten dollars, $10 million -> ten million dollars)
|
||||
- Dates
|
||||
- Numbers that are years (2016)!
|
||||
- Twitter hashtags, usernames
|
||||
|
||||
+21
-52
@@ -142,58 +142,27 @@ impl Tokenizer {
|
||||
continue;
|
||||
}
|
||||
|
||||
// FIXME: Speed up by converting to a hash lookup.
|
||||
// Rogue puncuation
|
||||
if unknown == "," {
|
||||
output.push_back(Token::comma());
|
||||
continue;
|
||||
} else if unknown == "." {
|
||||
output.push_back(Token::period());
|
||||
continue;
|
||||
}
|
||||
|
||||
// Symbols
|
||||
// FIXME: Map lookup for speedup.
|
||||
if unknown == "@" {
|
||||
output.push_back(Token::at_sign());
|
||||
continue;
|
||||
} else if unknown == "&" {
|
||||
output.push_back(Token::ampersand());
|
||||
continue;
|
||||
} else if unknown == "%" {
|
||||
output.push_back(Token::percent());
|
||||
continue;
|
||||
} else if unknown == "<" {
|
||||
output.push_back(Token::less_than());
|
||||
continue;
|
||||
} else if unknown == ">" {
|
||||
output.push_back(Token::greater_than());
|
||||
continue;
|
||||
} else if unknown == "+" {
|
||||
output.push_back(Token::plus());
|
||||
continue;
|
||||
}
|
||||
|
||||
// Currency Symbols
|
||||
// FIXME: Map lookup for speedup.
|
||||
if unknown == "Ƀ" {
|
||||
output.push_back(Token::bitcoin());
|
||||
continue;
|
||||
} else if unknown == "¢" {
|
||||
output.push_back(Token::cent());
|
||||
continue;
|
||||
} else if unknown == "$" {
|
||||
output.push_back(Token::dollar());
|
||||
continue;
|
||||
} else if unknown == "€" {
|
||||
output.push_back(Token::euro());
|
||||
continue;
|
||||
} else if unknown == "£" || unknown == "₤" {
|
||||
output.push_back(Token::pound());
|
||||
continue;
|
||||
} else if unknown == "¥" {
|
||||
output.push_back(Token::yen());
|
||||
continue;
|
||||
// Handle single characters
|
||||
// FIXME: Is a hash lookup faster?
|
||||
match unknown.as_ref() {
|
||||
// Punctuation
|
||||
"," => { output.push_back(Token::comma()); continue; },
|
||||
"." => { output.push_back(Token::period()); continue; },
|
||||
// Symbols
|
||||
"@" => { output.push_back(Token::at_sign()); continue; },
|
||||
"&" => { output.push_back(Token::ampersand()); continue; },
|
||||
"%" => { output.push_back(Token::percent()); continue; },
|
||||
"<" => { output.push_back(Token::less_than()); continue; },
|
||||
">" => { output.push_back(Token::greater_than()); continue; },
|
||||
"+" => { output.push_back(Token::plus()); continue; },
|
||||
// Currency symbols
|
||||
"Ƀ" => { output.push_back(Token::bitcoin()); continue; },
|
||||
"¢" => { output.push_back(Token::cent()); continue; },
|
||||
"$" => { output.push_back(Token::dollar()); continue; },
|
||||
"€" => { output.push_back(Token::euro()); continue; },
|
||||
"£" | "₤" => { output.push_back(Token::pound()); continue; },
|
||||
"¥" => { output.push_back(Token::yen()); continue; },
|
||||
_ => {},
|
||||
}
|
||||
|
||||
if URL.is_match(&unknown) {
|
||||
|
||||
Reference in new issue
Block a user