Skip to content

Commit

Permalink
Merge branch 'release/0.8.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
kanru committed Jul 10, 2024
2 parents 329d547 + 9be4851 commit 1073a32
Show file tree
Hide file tree
Showing 14 changed files with 189 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.24.0)
project(libchewing LANGUAGES C)

set(CMAKE_PROJECT_VERSION 0.8.3)
set(CMAKE_PROJECT_VERSION 0.8.5)
set(LIBCHEWING_VERSION ${CMAKE_PROJECT_VERSION})
set(PACKAGE_VERSION ${CMAKE_PROJECT_VERSION})
set(LIBCHEWING_BINARY_VERSION 1.0.0)
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "chewing"
description = "The Chewing (酷音) intelligent Zhuyin input method."
documentation = "https://docs.rs/chewing"
license = "LGPL-2.1-or-later"
version = "0.8.3"
version = "0.8.5"
rust-version = "1.70"
edition = "2021"

Expand Down
13 changes: 13 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
What's New in libchewing 0.8.5 (July 8, 2024)
---------------------------------------------------------

* Changed
- Bump default Corrosion version to v0.5

* Bug fixed
- Hanyu Pinyin empty rime handling. (#585, introduced in v0.8.0, reported by
Jidanni)
- Printable non A-Z chars should output symbols in pinyin. (#592, introduced
in v0.8.0, reported by Jidanni)


What's New in libchewing 0.8.4 (Jun 1, 2024)
---------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
name = "chewing_capi"
description = "The Chewing (酷音) intelligent Zhuyin input method."
license = "LGPL-2.1-or-later"
version = "0.8.3"
version = "0.8.5"
rust-version = "1.70"
edition = "2021"

[lib]
crate-type = ["rlib", "staticlib"]

[dependencies]
chewing = { version = "0.8.3", path = ".." }
chewing = { version = "0.8.5", path = ".." }
env_logger = { version = ">= 0.10.2", default-features = false }
log = { workspace = true }

Expand Down
4 changes: 2 additions & 2 deletions doc/chewing-cli.1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.TH chewing-cli 1 "chewing-cli 0.8.3"
.TH chewing-cli 1 "chewing-cli 0.8.5"
.SH NAME
chewing\-cli \- Tools of the Chewing (酷音) intelligent Zhuyin input method.
.SH SYNOPSIS
Expand All @@ -25,4 +25,4 @@ Display information about the dictionary
chewing\-cli\-dump(1)
Dump the dictionary entries into tsi.src formatted stream
.SH VERSION
v0.8.3
v0.8.5
4 changes: 2 additions & 2 deletions fuzzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
chewing = { version = "0.8.3", path = ".." }
chewing_capi = { version = "0.8.3", path = "../capi" }
chewing = { version = "0.8.5", path = ".." }
chewing_capi = { version = "0.8.5", path = "../capi" }
log = "0.4.21"
env_logger = { version = ">= 0.10.2", default-features = false }
11 changes: 11 additions & 0 deletions src/editor/keyboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ impl KeyCode {
_ => None,
}
}
#[rustfmt::skip]
pub const fn is_atoz(&self) -> bool {
matches!(self, A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z)
}
}

use KeyCode::*;
Expand All @@ -248,6 +252,13 @@ pub struct KeyEvent {
pub modifiers: Modifiers,
}

impl KeyEvent {
pub(crate) fn is_printable(&self) -> bool {
// FIXME refactor
self.unicode != '�'
}
}

impl fmt::Display for KeyEvent {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "key-{:?}-{:?}-{}-", self.index, self.code, self.unicode)?;
Expand Down
26 changes: 26 additions & 0 deletions src/editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,32 @@ impl State for Entering {
shared.com.insert(Symbol::from(symbol));
return self.spin_absorb();
}
if ev.is_printable() {
match shared.options.character_form {
CharacterForm::Halfwidth => {
if shared.com.is_empty() {
// FIXME we should ignore these keys if pre-edit is empty
shared.commit_buffer.clear();
shared.commit_buffer.push(ev.unicode);
return self.spin_commit();
} else {
shared.com.insert(Symbol::from(ev.unicode));
return self.spin_absorb();
}
}
CharacterForm::Fullwidth => {
let char_ = full_width_symbol_input(ev.unicode).unwrap();
if shared.com.is_empty() {
shared.commit_buffer.clear();
shared.commit_buffer.push(char_);
return self.spin_commit();
} else {
shared.com.insert(Symbol::from(char_));
return self.spin_absorb();
}
}
}
}
self.spin_bell()
}
LanguageMode::English => match shared.options.character_form {
Expand Down
95 changes: 94 additions & 1 deletion src/editor/zhuyin_layout/pinyin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ impl Pinyin {

impl SyllableEditor for Pinyin {
fn key_press(&mut self, key: KeyEvent) -> KeyBehavior {
if self.key_seq.is_empty() && !key.code.is_atoz() {
return KeyBehavior::KeyError;
}
if ![
KeyCode::Space,
KeyCode::N1,
Expand Down Expand Up @@ -180,7 +183,13 @@ impl SyllableEditor for Pinyin {
let mut medial = fina.and_then(|f| f.medial);
let mut rime = fina.and_then(|f| f.rime);

if let Some(Bopomofo::I) = rime {
/* Hanyu empty rime
* ㄓ/ㄔ/ㄕ/ㄖ/ㄗ/ㄘ/ㄙ + -i, -i is empty rime, not ㄧ
* */
if matches!(
(medial, rime),
(Some(Bopomofo::I), None) | (None, Some(Bopomofo::I))
) {
match initial {
Some(Bopomofo::ZH) | Some(Bopomofo::CH) | Some(Bopomofo::SH)
| Some(Bopomofo::R) | Some(Bopomofo::Z) | Some(Bopomofo::C) | Some(Bopomofo::S) => {
Expand All @@ -191,6 +200,11 @@ impl SyllableEditor for Pinyin {
}
}

/* Hanyu uan/un/u :
* ㄐ/ㄑ/ㄒ + -uan, -uan is ㄩㄢ, not ㄨㄢ
* ㄐ/ㄑ/ㄒ + -un, -un is ㄩㄣ, not ㄨㄣ
* ㄐ/ㄑ/ㄒ + -u, -u is ㄧ, not ㄨ
*/
match initial {
Some(Bopomofo::J) | Some(Bopomofo::Q) | Some(Bopomofo::X) => {
match (medial, rime) {
Expand All @@ -205,6 +219,13 @@ impl SyllableEditor for Pinyin {
_ => (),
}

/* THL/MPS2 s/sh/c/ch/j :
* s- + ー/ㄩ, s- is ㄒ, not ㄙ (THL/Tongyong)
* sh- + ー/ㄩ, sh- is ㄒ, not ㄕ (MPS2)
* c- + ー/ㄩ, c- is ㄑ, not ㄘ (Tongyong)
* ch- + ㄧ/ㄩ, ch- is ㄑ, not ㄔ (THL)
* j- + other than ー/ㄩ, j- is ㄓ, not ㄐ (MPS2)
*/
match medial {
Some(Bopomofo::I) | Some(Bopomofo::IU) => {
match initial {
Expand All @@ -224,6 +245,10 @@ impl SyllableEditor for Pinyin {
}
}

/* THL supplemental set
* ㄅ/ㄆ/ㄇ/ㄈ + -ㄨㄥ, -ㄨㄥ is another reading of -ㄥ
* ㄅ/ㄆ/ㄇ/ㄈ + -ㄨㄛ, -ㄨㄛ is another reading of -ㄛ
*/
match initial {
Some(Bopomofo::B) | Some(Bopomofo::P) | Some(Bopomofo::M) | Some(Bopomofo::F) => {
match (medial, rime) {
Expand Down Expand Up @@ -505,3 +530,71 @@ mod table {
fin!("z", None, None),
];
}

#[cfg(test)]
mod tests {
use crate::{
editor::{
keyboard::{AnyKeyboardLayout, KeyCode, KeyboardLayout},
zhuyin_layout::SyllableEditor,
},
syl,
zhuyin::Bopomofo,
};

use super::Pinyin;

#[test]
fn hanyu_empty_rime_zi() {
let keyboard = AnyKeyboardLayout::qwerty();
let mut hanyu = Pinyin::hanyu();

hanyu.key_press(keyboard.map(KeyCode::Z));
hanyu.key_press(keyboard.map(KeyCode::I));
hanyu.key_press(keyboard.map(KeyCode::N1));

assert_eq!(syl![Bopomofo::Z], hanyu.read());
}

#[test]
fn hanyu_empty_rime_zhi() {
let keyboard = AnyKeyboardLayout::qwerty();
let mut hanyu = Pinyin::hanyu();

hanyu.key_press(keyboard.map(KeyCode::Z));
hanyu.key_press(keyboard.map(KeyCode::H));
hanyu.key_press(keyboard.map(KeyCode::I));
hanyu.key_press(keyboard.map(KeyCode::N1));

assert_eq!(syl![Bopomofo::ZH], hanyu.read());
}

#[test]
fn hanyu_uan_un_u() {
let keyboard = AnyKeyboardLayout::qwerty();
let mut hanyu = Pinyin::hanyu();

hanyu.key_press(keyboard.map(KeyCode::J));
hanyu.key_press(keyboard.map(KeyCode::U));
hanyu.key_press(keyboard.map(KeyCode::A));
hanyu.key_press(keyboard.map(KeyCode::N));
hanyu.key_press(keyboard.map(KeyCode::N1));

assert_eq!(syl![Bopomofo::J, Bopomofo::IU, Bopomofo::AN], hanyu.read());

hanyu.clear();
hanyu.key_press(keyboard.map(KeyCode::Q));
hanyu.key_press(keyboard.map(KeyCode::U));
hanyu.key_press(keyboard.map(KeyCode::N));
hanyu.key_press(keyboard.map(KeyCode::N1));

assert_eq!(syl![Bopomofo::Q, Bopomofo::IU, Bopomofo::EN], hanyu.read());

hanyu.clear();
hanyu.key_press(keyboard.map(KeyCode::X));
hanyu.key_press(keyboard.map(KeyCode::U));
hanyu.key_press(keyboard.map(KeyCode::N1));

assert_eq!(syl![Bopomofo::X, Bopomofo::IU], hanyu.read());
}
}
23 changes: 23 additions & 0 deletions tests/test-bopomofo.c
Original file line number Diff line number Diff line change
Expand Up @@ -2013,6 +2013,28 @@ void test_KB_HANYU()
chewing_delete(ctx);
}

void test_KB_HANYU_direct_symbol_output()
{
ChewingContext *ctx;

ctx = chewing_new();
start_testcase(ctx, fd);

chewing_set_KBType(ctx, KB_HANYU_PINYIN);

type_keystroke_by_string(ctx, "pin yin 123 mo2shi4");
ok_preedit_buffer(ctx, "拼音 123 模式");
chewing_clean_preedit_buf(ctx);

chewing_set_KBType(ctx, KB_HANYU_PINYIN);
chewing_set_ShapeMode(ctx, FULLSHAPE_MODE);

type_keystroke_by_string(ctx, "pin yin 123 mo2shi4");
ok_preedit_buffer(ctx, "拼音 123 模式");
chewing_clean_preedit_buf(ctx);

chewing_delete(ctx);
}

void test_KB_THL()
{
Expand Down Expand Up @@ -2157,6 +2179,7 @@ void test_KB()
test_KB_COLEMAK_DH_ORTH();

test_KB_HANYU();
test_KB_HANYU_direct_symbol_output();
test_KB_THL();
test_KB_MPS2();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testhelper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
chewing = { version = "0.8.3", path = "../.." }
chewing = { version = "0.8.5", path = "../.." }

[features]
sqlite = ["chewing/sqlite"]
4 changes: 2 additions & 2 deletions tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
name = "chewing-cli"
description = "Tools of the Chewing (酷音) intelligent Zhuyin input method."
license = "LGPL-2.1-or-later"
version = "0.8.3"
version = "0.8.5"
edition = "2021"

[dependencies]
anyhow = "1.0.0"
chewing = { version = "0.8.3", path = "..", features = ["sqlite"] }
chewing = { version = "0.8.5", path = "..", features = ["sqlite"] }
clap = { version = "4.4.18", features = ["derive"] }
clap_mangen = { version = "0.2.12", optional = true }

Expand Down
16 changes: 8 additions & 8 deletions vet/imports.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# cargo-vet imports lock

[[unpublished.chewing]]
version = "0.8.3"
audited_as = "0.8.2"
version = "0.8.4"
audited_as = "0.8.3"

[[unpublished.chewing-cli]]
version = "0.8.3"
audited_as = "0.8.2"
version = "0.8.4"
audited_as = "0.8.3"

[[publisher.anstream]]
version = "0.6.14"
Expand Down Expand Up @@ -59,15 +59,15 @@ user-login = "Amanieu"
user-name = "Amanieu d'Antras"

[[publisher.chewing]]
version = "0.8.2"
when = "2024-05-21"
version = "0.8.3"
when = "2024-05-25"
user-id = 7551
user-login = "kanru"
user-name = "Kan-Ru Chen"

[[publisher.chewing-cli]]
version = "0.8.2"
when = "2024-05-21"
version = "0.8.3"
when = "2024-05-25"
user-id = 7551
user-login = "kanru"
user-name = "Kan-Ru Chen"
Expand Down

0 comments on commit 1073a32

Please sign in to comment.