Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/bopomofo.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ static int HsuPhoInput(ChewingData *pgdata, int key)
&& (pBopomofo->pho_inx[0] || pBopomofo->pho_inx[1])) {
/* if inx !=0 */
searchTimes = 2; /* possible infinite loop here */
} else if (12 <= inx && inx <= 14) {
/* ㄐㄑㄒ always come with ㄧㄩ, so set ㄓㄔㄕ as default. */
pBopomofo->pho_inx[0] = inx + 3;
} else
break;
} else if (type == 1 && inx == 1) { /* handle i and e */
Expand All @@ -258,15 +261,18 @@ static int HsuPhoInput(ChewingData *pgdata, int key)
pBopomofo->pho_inx[0] = 12;
}

/* ㄐㄑㄒ must be followed by ㄧㄩ, if not, convert them to ㄓㄔㄕ */
if (type == 1 && inx == 2 && 12 <= pBopomofo->pho_inx[0] && pBopomofo->pho_inx[0] <= 14) {
/* followed by ㄨ */
pBopomofo->pho_inx[0] += 3;
/* ㄐㄑㄒ must be followed by ㄧ or ㄩ. If not, convert them to ㄓㄔㄕ. */
if (12 <= pBopomofo->pho_inx[0] && pBopomofo->pho_inx[0] <= 14) {
if ((type == 1 && inx == 2) || (type == 2 && pBopomofo->pho_inx[1] == 0)) {
pBopomofo->pho_inx[0] += 3;
}
}

if (type == 2 && pBopomofo->pho_inx[1] == 0 && 12 <= pBopomofo->pho_inx[0] && pBopomofo->pho_inx[0] <= 14) {
/* followed by other phones */
pBopomofo->pho_inx[0] += 3;
/* Likeweis, when ㄓㄔㄕ is followed by ㄧ or ㄩ, convert them to ㄐㄑㄒ. */
if (15 <= pBopomofo->pho_inx[0] && pBopomofo->pho_inx[0] <= 17) {
if ((type == 1) && (inx == 1 || inx == 3)) {
pBopomofo->pho_inx[0] -= 3;
}
}

if (type == 3) { /* the key is NOT a phone */
Expand Down
49 changes: 42 additions & 7 deletions test/test-bopomofo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1450,13 +1450,6 @@ void test_KB_HSU()
ok_preedit_buffer(ctx, "\xE9\xAA\xAF" /* 骯 */);
chewing_clean_preedit_buf(ctx);

type_keystroke_by_string(ctx, "j");
ok_bopomofo_buffer(ctx, "\xE3\x84\x90" /* ㄐ */);
type_keystroke_by_string(ctx, " "); /* convert "ㄐ,ㄑ,ㄒ" to "ㄓ,ㄔ,ㄕ" */
ok_bopomofo_buffer(ctx, "");
ok_preedit_buffer(ctx, "\xE4\xB9\x8B" /* 之 */);
chewing_clean_preedit_buf(ctx);

type_keystroke_by_string(ctx, "l");
ok_bopomofo_buffer(ctx, "\xE3\x84\x8C" /* ㄌ */);
type_keystroke_by_string(ctx, "f"); /* convert "ㄌ" to "ㄦ" */
Expand Down Expand Up @@ -1518,6 +1511,47 @@ void test_KB_HSU_choice_append()
chewing_delete(ctx);
}

void test_KB_HSU_JVC()
{
static const struct {
char *keystroke;
char *bopomofo;
char *cand;
} DATA[] = {
{ "j", "\xE3\x84\x93", /* ㄓ */ "\xE4\xB9\x8B", /* 之 */ },
{ "v", "\xE3\x84\x94", /* ㄔ */ "\xE5\x90\x83", /* 吃 */ },
{ "c", "\xE3\x84\x95", /* ㄕ */ "\xE5\xA4\xB1", /* 失 */ },
};

ChewingContext *ctx;
ctx = chewing_new();
start_testcase(ctx, fd);
chewing_set_KBType(ctx, KB_HSU);

for (int i = 0; i < ARRAY_SIZE(DATA); ++i) {
type_keystroke_by_string(ctx, DATA[i].keystroke);
ok_bopomofo_buffer(ctx, DATA[i].bopomofo);
type_keystroke_by_string(ctx, " ");
ok_bopomofo_buffer(ctx, "");
ok_preedit_buffer(ctx, DATA[i].cand);

chewing_cand_close(ctx);
chewing_clean_preedit_buf(ctx);
}

type_keystroke_by_string(ctx, "cek");
ok_bopomofo_buffer(ctx, "\xE3\x84\x92\xE3\x84\xA7\xE3\x84\xA4" /* ㄒㄧㄤ */ );
type_keystroke_by_string(ctx, "<EE>");

type_keystroke_by_string(ctx, "cke");
ok_bopomofo_buffer(ctx, "\xE3\x84\x92\xE3\x84\xA7\xE3\x84\xA4" /* ㄒㄧㄤ */ );
type_keystroke_by_string(ctx, "<B><B>k");
ok_bopomofo_buffer(ctx, "\xE3\x84\x95\xE3\x84\xA4" /* ㄕㄤ */ );
chewing_clean_preedit_buf(ctx);

chewing_delete(ctx);
}

void test_KB_ET26()
{
ChewingContext *ctx;
Expand Down Expand Up @@ -1783,6 +1817,7 @@ void test_KB()
{
test_KB_HSU();
test_KB_HSU_choice_append();
test_KB_HSU_JVC();
test_KB_ET26();
test_KB_ET26_choice_append();
test_KB_DACHEN_CP26();
Expand Down