Skip to content

Commit

Permalink
Support full-width characters in romaji table
Browse files Browse the repository at this point in the history
BUG=
TEST=
REF_BUG=31444698
REF_CL=132973961,133089311
REF_TIME=2016-09-13T17:49:10+09:00
REF_TIME_RAW=1473756550 +0900
  • Loading branch information
Noriyuki Takahashi committed Sep 13, 2016
1 parent 08ba3f9 commit 2315f95
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/base/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ class Util {
static char32 UTF8ToUCS4(const char *begin,
const char *end,
size_t *mblen);
static char32 UTF8ToUCS4(StringPiece s) {
size_t mblen = 0;
return UTF8ToUCS4(s.data(), s.data() + s.size(), &mblen);
}

// Converts a UCS4 code point to UTF8 string.
static void UCS4ToUTF8(char32 c, string *output);
Expand Down
12 changes: 10 additions & 2 deletions src/composer/composer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,17 @@ void Composer::ApplyTemporaryInputMode(const string &input, bool caps_locked) {
const config::Config::ShiftKeyModeSwitch switch_mode =
config_->shift_key_mode_switch();

// Input is NOT an ASCII code.
// When input is not an ASCII code, reset the input mode to the one before
// temporary input mode.
if (Util::OneCharLen(input.c_str()) != 1) {
SetInputMode(comeback_input_mode_);
// Call SetInputMode() only when the current input mode is temporary, which
// is detected by the if-condition below. Without this check,
// SetInputMode() is called always for multi-byte charactesrs. This causes
// a bug that multi-byte characters is inserted to a new chunk because
// |is_new_input_| is set to true in SetInputMode(); see b/31444698.
if (comeback_input_mode_ != input_mode_) {
SetInputMode(comeback_input_mode_);
}
return;
}

Expand Down
46 changes: 46 additions & 0 deletions src/composer/composer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,52 @@ TEST_F(ComposerTest, ApplyTemporaryInputMode) {
}
}

TEST_F(ComposerTest, FullWidthCharRules_b31444698) {
// Construct the following romaji table:
//
// 1<tab><tab>{?}あ<tab>NewChunk NoTransliteration
// {?}あ1<tab><tab>{?}い<tab>
// か<tab><tab>{?}か<tab>NewChunk NoTransliteration
// {?}かか<tab><tab>{?}き<tab>
const int kAttrs =
TableAttribute::NEW_CHUNK | TableAttribute::NO_TRANSLITERATION;
table_->AddRuleWithAttributes("1", "",
"\x7B\x3F\x7D\xE3\x81\x82", // "{?}あ"
kAttrs);
table_->AddRule("\x7B\x3F\x7D\xE3\x81\x82\x31", // "{?}あ1"
"",
"\x7B\x3F\x7D\xE3\x81\x84"); // "{?}い"
table_->AddRuleWithAttributes("\xE3\x81\x8B", // "か"
"",
"\x7B\x3F\x7D\xE3\x81\x8B", // "{?}か"
kAttrs);
table_->AddRule("\x7B\x3F\x7D\xE3\x81\x8B\xE3\x81\x8B", // "{?}かか"
"",
"\x7B\x3F\x7D\xE3\x81\x8D"); // "{?}き"

// Test if "11" is transliterated to "い"
ASSERT_TRUE(InsertKeyWithMode("1", commands::HIRAGANA, composer_.get()));
EXPECT_EQ("\xE3\x81\x82", // "あ"
GetPreedit(composer_.get()));
ASSERT_TRUE(InsertKeyWithMode("1", commands::HIRAGANA, composer_.get()));
EXPECT_EQ("\xE3\x81\x84", // "い"
GetPreedit(composer_.get()));

composer_->Reset();

// b/31444698. Test if "かか" is transliterated to "き"
ASSERT_TRUE(InsertKeyWithMode("\xE3\x81\x8B", // "か"
commands::HIRAGANA,
composer_.get()));
EXPECT_EQ("\xE3\x81\x8B", // "か"
GetPreedit(composer_.get()));
ASSERT_TRUE(InsertKeyWithMode("\xE3\x81\x8B", // "か"
commands::HIRAGANA,
composer_.get()));
EXPECT_EQ("\xE3\x81\x8D", // "き"
GetPreedit(composer_.get()));
}

TEST_F(ComposerTest, CopyFrom) {
// "あ"
table_->AddRule("a", "\xE3\x81\x82", "");
Expand Down
4 changes: 0 additions & 4 deletions src/composer/key_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,6 @@ class KeyParserData {

bool KeyParser::ParseKey(const string &key_string,
KeyEvent *key_event) {
if (Util::GetFormType(key_string) != mozc::Util::HALF_WIDTH) {
LOG(ERROR) << "key should be half-width";
return false;
}
vector<string> keys;
Util::SplitStringUsing(key_string, " ", &keys);
if (keys.empty()) {
Expand Down
4 changes: 3 additions & 1 deletion src/composer/key_parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ TEST(KeyParserTest, KeyCode) {
EXPECT_EQ('A', key_event.key_code());

// "あ" (not half width)
const char32 kHiraganaA = 0x3042;
key_event.Clear();
EXPECT_FALSE(KeyParser::ParseKey("\xE3\x81\x82", &key_event));
EXPECT_TRUE(KeyParser::ParseKey("\xE3\x81\x82", &key_event));
EXPECT_EQ(kHiraganaA, key_event.key_code());
}

TEST(KeyParserTest, ModifierKeys) {
Expand Down
2 changes: 1 addition & 1 deletion src/data/version/mozc_version_template.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

MAJOR=2
MINOR=18
BUILD=2611
BUILD=2612
REVISION=102
# This version represents the version of Mozc IME engine (converter, predictor,
# etc.). This version info is included both in the Mozc server and in the Mozc
Expand Down

0 comments on commit 2315f95

Please sign in to comment.