From b5e10e1507338ecef6ec58585e2334719dd5e407 Mon Sep 17 00:00:00 2001 From: Taku Kudo Date: Thu, 13 Feb 2025 10:55:12 +0000 Subject: [PATCH] Remove composer/internal/converter. This module is internal and only used by mozc_transliterator. Moves the logic to mozc_transliterator to reduce the maintenance cost. PiperOrigin-RevId: 726396597 --- src/composer/composer.gyp | 1 - src/composer/composer_test.gyp | 1 - src/composer/internal/BUILD.bazel | 34 ---------- src/composer/internal/converter.cc | 67 ------------------- src/composer/internal/converter.h | 60 ----------------- src/composer/internal/converter_main.cc | 56 ---------------- src/composer/internal/converter_test.cc | 87 ------------------------- 7 files changed, 306 deletions(-) delete mode 100644 src/composer/internal/converter.cc delete mode 100644 src/composer/internal/converter.h delete mode 100644 src/composer/internal/converter_main.cc delete mode 100644 src/composer/internal/converter_test.cc diff --git a/src/composer/composer.gyp b/src/composer/composer.gyp index d7e576d59..aeda00869 100644 --- a/src/composer/composer.gyp +++ b/src/composer/composer.gyp @@ -42,7 +42,6 @@ 'internal/char_chunk.cc', 'internal/composition.cc', 'internal/composition_input.cc', - 'internal/converter.cc', 'internal/mode_switching_handler.cc', 'internal/special_key.cc', 'internal/transliterators.cc', diff --git a/src/composer/composer_test.gyp b/src/composer/composer_test.gyp index 986225bf7..7db778dbf 100644 --- a/src/composer/composer_test.gyp +++ b/src/composer/composer_test.gyp @@ -37,7 +37,6 @@ 'internal/char_chunk_test.cc', 'internal/composition_input_test.cc', 'internal/composition_test.cc', - 'internal/converter_test.cc', 'internal/mode_switching_handler_test.cc', 'internal/special_key_test.cc', 'internal/transliterators_test.cc', diff --git a/src/composer/internal/BUILD.bazel b/src/composer/internal/BUILD.bazel index a73f2225b..8544df162 100644 --- a/src/composer/internal/BUILD.bazel +++ b/src/composer/internal/BUILD.bazel @@ -192,29 +192,6 @@ mozc_cc_binary( ], ) -mozc_cc_library( - name = "converter", - srcs = ["converter.cc"], - hdrs = ["converter.h"], - visibility = [ - ], # for mozc_transliterator - deps = [ - "//composer:table", - "@com_google_absl//absl/strings", - ], -) - -mozc_cc_test( - name = "converter_test", - size = "small", - srcs = ["converter_test.cc"], - deps = [ - ":converter", - "//composer:table", - "//testing:gunit_main", - ], -) - mozc_cc_library( name = "mode_switching_handler", srcs = ["mode_switching_handler.cc"], @@ -238,17 +215,6 @@ mozc_cc_test( ], ) -mozc_cc_binary( - name = "converter_main", - srcs = ["converter_main.cc"], - deps = [ - ":converter", - "//base:init_mozc", - "//composer:table", - "@com_google_absl//absl/flags:flag", - ], -) - mozc_cc_library( name = "special_key", srcs = ["special_key.cc"], diff --git a/src/composer/internal/converter.cc b/src/composer/internal/converter.cc deleted file mode 100644 index bcca1f698..000000000 --- a/src/composer/internal/converter.cc +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2010-2021, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Converter from a Roman string to a Hiragana string - -#include "composer/internal/converter.h" - -#include -#include - -#include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" -#include "composer/table.h" - -namespace mozc { -namespace composer { - -// ======================================== -// Converter -// ======================================== - -void Converter::Convert(const absl::string_view input, - std::string* output) const { - std::string key(input); - output->clear(); // equivalent to output->assign("") - while (!key.empty()) { - size_t key_length; - bool fixed; - const Entry* entry = table_.LookUpPrefix(key, &key_length, &fixed); - if (entry == nullptr) { - output->append(key, 0, 1); - key.erase(0, 1); - } else { - output->append(entry->result()); - key = absl::StrCat(entry->pending(), key.substr(key_length)); - } - } -} - -} // namespace composer -} // namespace mozc diff --git a/src/composer/internal/converter.h b/src/composer/internal/converter.h deleted file mode 100644 index 49ad4af61..000000000 --- a/src/composer/internal/converter.h +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2010-2021, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Converter from a Roman string to a Hiragana string - -#ifndef MOZC_COMPOSER_INTERNAL_CONVERTER_H_ -#define MOZC_COMPOSER_INTERNAL_CONVERTER_H_ - -#include - -#include "absl/strings/string_view.h" - -namespace mozc { -namespace composer { - -class Table; - -class Converter { - public: - explicit Converter(const Table& table) : table_(table) {} - - Converter(const Converter&) = delete; - Converter& operator=(const Converter&) = delete; - - void Convert(absl::string_view input, std::string* output) const; - - private: - const Table& table_; -}; - -} // namespace composer -} // namespace mozc - -#endif // MOZC_COMPOSER_INTERNAL_CONVERTER_H_ diff --git a/src/composer/internal/converter_main.cc b/src/composer/internal/converter_main.cc deleted file mode 100644 index b08aa8551..000000000 --- a/src/composer/internal/converter_main.cc +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2010-2021, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include // NOLINT -#include -#include - -#include "absl/flags/flag.h" -#include "base/init_mozc.h" -#include "composer/internal/converter.h" -#include "composer/table.h" - -ABSL_FLAG(std::string, table, "system://romanji-hiragana.tsv", - "preedit conversion table file."); - -int main(int argc, char **argv) { - mozc::InitMozc(argv[0], &argc, &argv); - - mozc::composer::Table table; - table.LoadFromFile(absl::GetFlag(FLAGS_table).c_str()); - - mozc::composer::Converter converter(table); - - std::string command; - std::string result; - while (std::getline(std::cin, command)) { - converter.Convert(command, &result); - std::cout << result << std::endl; - } -} diff --git a/src/composer/internal/converter_test.cc b/src/composer/internal/converter_test.cc deleted file mode 100644 index c1d24b112..000000000 --- a/src/composer/internal/converter_test.cc +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2010-2021, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include "composer/internal/converter.h" - -#include -#include - -#include "composer/table.h" -#include "testing/gunit.h" - -namespace mozc { -namespace { - -void InitTable(mozc::composer::Table *table) { - table->AddRule("a", "あ", ""); - table->AddRule("i", "い", ""); - table->AddRule("ka", "か", ""); - table->AddRule("ki", "き", ""); - table->AddRule("ku", "く", ""); - table->AddRule("ke", "け", ""); - table->AddRule("ko", "こ", ""); - table->AddRule("kk", "っ", "k"); - table->AddRule("na", "な", ""); - table->AddRule("ni", "に", ""); - table->AddRule("n", "ん", ""); - table->AddRule("nn", "ん", ""); -} - -TEST(ConverterTest, Converter) { - static const struct TestCase { - const char *input; - const char *expected_output; - } test_cases[] = { - {"a", "あ"}, - {"ka", "か"}, - {"ki", "き"}, - {"ku", "く"}, - {"kk", "っk"}, - {"aka", "あか"}, - {"kakizkka", "かきzっか"}, - {"nankanai?", "なんかない?"}, - {"nannkanain?", "なんかないん?"}, - {"nannkanain", "なんかないん"}, - }; - static const int size = std::size(test_cases); - - mozc::composer::Table table; - InitTable(&table); - mozc::composer::Converter converter(table); - - for (int i = 0; i < size; ++i) { - const TestCase &test = test_cases[i]; - std::string output; - converter.Convert(test.input, &output); - EXPECT_EQ(output, test.expected_output); - } -} - -} // namespace -} // namespace mozc