Check alternative kana, support romaji
This commit is contained in:
parent
1ff2aedc2d
commit
53fb1f3c4e
1 changed files with 39 additions and 2 deletions
|
@ -197,9 +197,46 @@ impl Server {
|
||||||
message: String::from("It's not your turn!"),
|
message: String::from("It's not your turn!"),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match lookup(&message) {
|
let query = if message.is_japanese() {
|
||||||
|
Some(message)
|
||||||
|
} else {
|
||||||
|
let kana = message.to_kana();
|
||||||
|
if kana.is_japanese() {
|
||||||
|
Some(kana)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// For some reason result will keep a reference to
|
||||||
|
// katakana_query and hiragana_query, meaning that
|
||||||
|
// these need to be kept around as a variable
|
||||||
|
// to prevent them from being dropped.
|
||||||
|
let (katakana_query, hiragana_query) = match &query {
|
||||||
|
Some(query) => (
|
||||||
|
Some(query.to_katakana()),
|
||||||
|
Some(query.to_hiragana())
|
||||||
|
),
|
||||||
|
None => (None, None),
|
||||||
|
};
|
||||||
|
let result = match &query {
|
||||||
|
Some(query) => match lookup(query) {
|
||||||
|
Some(result) => Some(result),
|
||||||
|
None => {
|
||||||
|
if query.is_hiragana() {
|
||||||
|
// looking up ごりら doesn't return ゴリラ
|
||||||
|
lookup(katakana_query.as_ref().unwrap())
|
||||||
|
} else if query.is_katakana() {
|
||||||
|
// looking up シリトリ doesn't return 尻取り
|
||||||
|
lookup(hiragana_query.as_ref().unwrap())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
match result {
|
||||||
Some(entry) => {
|
Some(entry) => {
|
||||||
println!("{}, {:?}", get_starting_mora(&entry.reading), self.next_mora);
|
|
||||||
if entry.reading.chars().last().unwrap().to_string().to_hiragana() == "ん" {
|
if entry.reading.chars().last().unwrap().to_string().to_hiragana() == "ん" {
|
||||||
MessageResponseData::Error {
|
MessageResponseData::Error {
|
||||||
message: String::from("Can't end with ん!"),
|
message: String::from("Can't end with ん!"),
|
||||||
|
|
Loading…
Add table
Reference in a new issue