Skip to content

Commit d6b8fa1

Browse files
committed
Fix an idempotency issue in Hsu and ETen26 layouts
Certain sequences should have the equivalent output, such as ai/ia with Hsu (both should yield ㄘㄞ). While "ia" might be a mistake on the user's part, since it is the equivalent of "ai", the layout code still should honor it.
1 parent 8a8a43e commit d6b8fa1

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

Source/Engine/Mandarin/Mandarin.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,16 @@ class BopomofoKeyboardLayout {
302302
syllable += head;
303303
} else if (syllable.maskType() < follow.maskType()) {
304304
syllable += follow;
305+
} else if ((syllable.maskType() == follow.maskType()) &&
306+
syllable.maskType() == BPMF::VowelMask) {
307+
// if the existing syllable contains only a vowel, and the
308+
// next character has 2+ possibilities, and the second (follow)
309+
// one is also a vowel, we know that the user may have typed the
310+
// sequence in the wrong order (since the first or head is always
311+
// a consonant); if we come all the way here, the only possibility
312+
// for the second is an EI or E, but since we don't allow them to
313+
// be standalone in Hsu or ETen26, we will pick the consonant.
314+
syllable += head;
305315
} else {
306316
syllable += ending;
307317
}

Source/Engine/Mandarin/MandarinTest.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,27 @@ TEST(MandarinTest, ETen26Layout) {
101101
ASSERT_EQ(buf.composedString(), "ㄗㄢˋ");
102102
}
103103

104+
TEST(MandarinTest, ETen26LayoutIdempotentSequence) {
105+
BopomofoReadingBuffer buf(BopomofoKeyboardLayout::ETen26Layout());
106+
buf.combineKey('q');
107+
buf.combineKey('a');
108+
ASSERT_EQ(buf.composedString(), "ㄗㄚ");
109+
110+
buf.clear();
111+
buf.combineKey('a'); // ㄚ first
112+
buf.combineKey('q'); // even if q can be ㄟ, a vowel is already in place
113+
ASSERT_EQ(buf.composedString(), "ㄗㄚ");
114+
115+
buf.clear();
116+
buf.combineKey('q');
117+
buf.combineKey('i');
118+
ASSERT_EQ(buf.composedString(), "ㄗㄞ");
119+
120+
buf.clear();
121+
buf.combineKey('i');
122+
buf.combineKey('q');
123+
ASSERT_EQ(buf.composedString(), "ㄗㄞ");
124+
}
104125
TEST(MandarinTest, HsuLayout) {
105126
BopomofoReadingBuffer buf(BopomofoKeyboardLayout::HsuLayout());
106127
buf.combineKey('f');
@@ -109,6 +130,28 @@ TEST(MandarinTest, HsuLayout) {
109130
ASSERT_EQ(buf.composedString(), "ㄈㄟˇ");
110131
}
111132

133+
TEST(MandarinTest, HsuLayoutIdempotentSequence) {
134+
BopomofoReadingBuffer buf(BopomofoKeyboardLayout::HsuLayout());
135+
buf.combineKey('a');
136+
buf.combineKey('i');
137+
ASSERT_EQ(buf.composedString(), "ㄘㄞ");
138+
139+
buf.clear();
140+
buf.combineKey('i'); // ㄞ first
141+
buf.combineKey('a'); // even if a can be ㄟ, a vowel is already in place
142+
ASSERT_EQ(buf.composedString(), "ㄘㄞ");
143+
144+
buf.clear();
145+
buf.combineKey('a');
146+
buf.combineKey('y');
147+
ASSERT_EQ(buf.composedString(), "ㄘㄚ");
148+
149+
buf.clear();
150+
buf.combineKey('y');
151+
buf.combineKey('a');
152+
ASSERT_EQ(buf.composedString(), "ㄘㄚ");
153+
}
154+
112155
TEST(MandarinTest, IBMLayout) {
113156
BopomofoReadingBuffer buf(BopomofoKeyboardLayout::IBMLayout());
114157
buf.combineKey('9');

0 commit comments

Comments
 (0)