mirror of
https://github.com/mii443/mozc.git
synced 2025-08-22 16:15:46 +00:00
Moves TransliteratorInterface to transliterator.h as it is purely internal interaface
only used Transliterator. Moves them inside internal namespace so it is not used by outside of this module. PiperOrigin-RevId: 726273567
This commit is contained in:
committed by
Hiroyuki Komatsu
parent
d3c6051c43
commit
0dc00e8cd2
@ -36,12 +36,6 @@ load(
|
||||
|
||||
package(default_visibility = ["//composer:__subpackages__"])
|
||||
|
||||
mozc_cc_library(
|
||||
name = "transliterator_interface",
|
||||
hdrs = ["transliterator_interface.h"],
|
||||
deps = ["@com_google_absl//absl/strings"],
|
||||
)
|
||||
|
||||
mozc_cc_library(
|
||||
name = "char_chunk",
|
||||
srcs = [
|
||||
@ -73,7 +67,6 @@ mozc_cc_library(
|
||||
],
|
||||
hdrs = ["transliterators.h"],
|
||||
deps = [
|
||||
":transliterator_interface",
|
||||
"//base:japanese_util",
|
||||
"//base:singleton",
|
||||
"//base:util",
|
||||
@ -93,7 +86,6 @@ mozc_cc_test(
|
||||
"transliterators_test.cc",
|
||||
],
|
||||
deps = [
|
||||
":transliterator_interface",
|
||||
":transliterators",
|
||||
"//testing:gunit_main",
|
||||
],
|
||||
@ -204,7 +196,8 @@ mozc_cc_library(
|
||||
name = "converter",
|
||||
srcs = ["converter.cc"],
|
||||
hdrs = ["converter.h"],
|
||||
visibility = [], # for mozc_transliterator
|
||||
visibility = [
|
||||
], # for mozc_transliterator
|
||||
deps = [
|
||||
"//composer:table",
|
||||
"@com_google_absl//absl/strings",
|
||||
|
@ -1,76 +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.
|
||||
|
||||
#ifndef MOZC_COMPOSER_INTERNAL_TRANSLITERATOR_INTERFACE_H_
|
||||
#define MOZC_COMPOSER_INTERNAL_TRANSLITERATOR_INTERFACE_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
|
||||
namespace mozc {
|
||||
namespace composer {
|
||||
|
||||
class TransliteratorInterface {
|
||||
public:
|
||||
virtual ~TransliteratorInterface() = default;
|
||||
|
||||
// Return the transliterated string of either raw or converted.
|
||||
// Determination of which argument is used depends on the
|
||||
// implementation.
|
||||
//
|
||||
// Expected usage examples:
|
||||
// - HalfKatakanaTransliterator("a", "あ") => "ア"
|
||||
// - FullAsciiTransliterator("a", "あ") => "a"
|
||||
virtual std::string Transliterate(absl::string_view raw,
|
||||
absl::string_view converted) const = 0;
|
||||
|
||||
// Split raw and converted strings based on the transliteration
|
||||
// rule. If raw or converted could not be deterministically split,
|
||||
// fall back strings are fill and false is returned. The first
|
||||
// argument, position, is in character (rather than byte).
|
||||
//
|
||||
// Expected usage examples:
|
||||
// - HiraganaTransliterator(1, "kk", "っk") => true
|
||||
// (raw_lhs, raw_rhs) => ("k", "k")
|
||||
// (conv_lhs, conv_rhs) => ("っ", "k")
|
||||
// - HalfKatakanaTransliterator(1, "zu", "ず") => false
|
||||
// (raw_lhs, raw_rhs) => ("す", "゛") fall back strings.
|
||||
// (conv_lhs, conv_rhs) => ("す", "゛")
|
||||
virtual bool Split(size_t position, absl::string_view raw,
|
||||
absl::string_view converted, std::string *raw_lhs,
|
||||
std::string *raw_rhs, std::string *converted_lhs,
|
||||
std::string *converted_rhs) const = 0;
|
||||
};
|
||||
|
||||
} // namespace composer
|
||||
} // namespace mozc
|
||||
|
||||
#endif // MOZC_COMPOSER_INTERNAL_TRANSLITERATOR_INTERFACE_H_
|
@ -40,7 +40,6 @@
|
||||
#include "base/strings/assign.h"
|
||||
#include "base/util.h"
|
||||
#include "base/vlog.h"
|
||||
#include "composer/internal/transliterator_interface.h"
|
||||
#include "config/character_form_manager.h"
|
||||
|
||||
namespace mozc {
|
||||
@ -91,7 +90,7 @@ bool SplitPrimaryString(const size_t position, const absl::string_view primary,
|
||||
|
||||
// Singleton class which always uses a converted string rather than a
|
||||
// raw string.
|
||||
class ConversionStringSelector : public TransliteratorInterface {
|
||||
class ConversionStringSelector : public internal::TransliteratorInterface {
|
||||
public:
|
||||
~ConversionStringSelector() override = default;
|
||||
|
||||
@ -116,7 +115,7 @@ class ConversionStringSelector : public TransliteratorInterface {
|
||||
|
||||
// Singleton class which always uses a raw string rather than a
|
||||
// converted string.
|
||||
class RawStringSelector : public TransliteratorInterface {
|
||||
class RawStringSelector : public internal::TransliteratorInterface {
|
||||
public:
|
||||
~RawStringSelector() override = default;
|
||||
|
||||
@ -134,7 +133,7 @@ class RawStringSelector : public TransliteratorInterface {
|
||||
}
|
||||
};
|
||||
|
||||
class HiraganaTransliterator : public TransliteratorInterface {
|
||||
class HiraganaTransliterator : public internal::TransliteratorInterface {
|
||||
public:
|
||||
~HiraganaTransliterator() override = default;
|
||||
|
||||
@ -157,7 +156,7 @@ class HiraganaTransliterator : public TransliteratorInterface {
|
||||
}
|
||||
};
|
||||
|
||||
class FullKatakanaTransliterator : public TransliteratorInterface {
|
||||
class FullKatakanaTransliterator : public internal::TransliteratorInterface {
|
||||
public:
|
||||
~FullKatakanaTransliterator() override = default;
|
||||
|
||||
@ -182,7 +181,7 @@ class FullKatakanaTransliterator : public TransliteratorInterface {
|
||||
}
|
||||
};
|
||||
|
||||
class HalfKatakanaTransliterator : public TransliteratorInterface {
|
||||
class HalfKatakanaTransliterator : public internal::TransliteratorInterface {
|
||||
public:
|
||||
~HalfKatakanaTransliterator() override = default;
|
||||
|
||||
@ -222,7 +221,7 @@ class HalfKatakanaTransliterator : public TransliteratorInterface {
|
||||
}
|
||||
};
|
||||
|
||||
class HalfAsciiTransliterator : public TransliteratorInterface {
|
||||
class HalfAsciiTransliterator : public internal::TransliteratorInterface {
|
||||
public:
|
||||
~HalfAsciiTransliterator() override = default;
|
||||
|
||||
@ -241,7 +240,7 @@ class HalfAsciiTransliterator : public TransliteratorInterface {
|
||||
}
|
||||
};
|
||||
|
||||
class FullAsciiTransliterator : public TransliteratorInterface {
|
||||
class FullAsciiTransliterator : public internal::TransliteratorInterface {
|
||||
public:
|
||||
~FullAsciiTransliterator() override = default;
|
||||
|
||||
@ -263,7 +262,7 @@ class FullAsciiTransliterator : public TransliteratorInterface {
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
const TransliteratorInterface *Transliterators::GetTransliterator(
|
||||
const internal::TransliteratorInterface *Transliterators::GetTransliterator(
|
||||
Transliterator transliterator) {
|
||||
MOZC_VLOG(2) << "Transliterators::GetTransliterator:" << transliterator;
|
||||
DCHECK(transliterator != LOCAL);
|
||||
|
@ -34,10 +34,42 @@
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "composer/internal/transliterator_interface.h"
|
||||
|
||||
namespace mozc {
|
||||
namespace composer {
|
||||
namespace internal {
|
||||
class TransliteratorInterface {
|
||||
public:
|
||||
virtual ~TransliteratorInterface() = default;
|
||||
|
||||
// Return the transliterated string of either raw or converted.
|
||||
// Determination of which argument is used depends on the
|
||||
// implementation.
|
||||
//
|
||||
// Expected usage examples:
|
||||
// - HalfKatakanaTransliterator("a", "あ") => "ア"
|
||||
// - FullAsciiTransliterator("a", "あ") => "a"
|
||||
virtual std::string Transliterate(absl::string_view raw,
|
||||
absl::string_view converted) const = 0;
|
||||
|
||||
// Split raw and converted strings based on the transliteration
|
||||
// rule. If raw or converted could not be deterministically split,
|
||||
// fall back strings are fill and false is returned. The first
|
||||
// argument, position, is in character (rather than byte).
|
||||
//
|
||||
// Expected usage examples:
|
||||
// - HiraganaTransliterator(1, "kk", "っk") => true
|
||||
// (raw_lhs, raw_rhs) => ("k", "k")
|
||||
// (conv_lhs, conv_rhs) => ("っ", "k")
|
||||
// - HalfKatakanaTransliterator(1, "zu", "ず") => false
|
||||
// (raw_lhs, raw_rhs) => ("す", "゛") fall back strings.
|
||||
// (conv_lhs, conv_rhs) => ("す", "゛")
|
||||
virtual bool Split(size_t position, absl::string_view raw,
|
||||
absl::string_view converted, std::string *raw_lhs,
|
||||
std::string *raw_rhs, std::string *converted_lhs,
|
||||
std::string *converted_rhs) const = 0;
|
||||
};
|
||||
} // namespace internal
|
||||
|
||||
// Factory class providing basic TransliteratorInterface instances.
|
||||
class Transliterators {
|
||||
@ -68,7 +100,7 @@ class Transliterators {
|
||||
|
||||
// Return a singleton instance of a TransliteratorInterface.
|
||||
// LOCAL transliterator is not accepted.
|
||||
static const TransliteratorInterface *GetTransliterator(
|
||||
static const internal::TransliteratorInterface *GetTransliterator(
|
||||
Transliterator transliterator);
|
||||
|
||||
static bool SplitRaw(size_t position, absl::string_view raw,
|
||||
|
@ -31,7 +31,6 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "composer/internal/transliterator_interface.h"
|
||||
#include "testing/gunit.h"
|
||||
|
||||
namespace mozc {
|
||||
@ -39,7 +38,7 @@ namespace composer {
|
||||
namespace {
|
||||
|
||||
TEST(TransliteratorsTest, ConversionStringSelector) {
|
||||
const TransliteratorInterface *t12r =
|
||||
const internal::TransliteratorInterface *t12r =
|
||||
Transliterators::GetTransliterator(Transliterators::CONVERSION_STRING);
|
||||
EXPECT_EQ(t12r->Transliterate("zu", "ず"), "ず");
|
||||
EXPECT_EQ(t12r->Transliterate("kk", "っk"), "っk");
|
||||
@ -70,7 +69,7 @@ TEST(TransliteratorsTest, ConversionStringSelector) {
|
||||
}
|
||||
|
||||
TEST(TransliteratorsTest, RawStringSelector) {
|
||||
const TransliteratorInterface *t12r =
|
||||
const internal::TransliteratorInterface *t12r =
|
||||
Transliterators::GetTransliterator(Transliterators::RAW_STRING);
|
||||
EXPECT_EQ(t12r->Transliterate("zu", "ず"), "zu");
|
||||
EXPECT_EQ(t12r->Transliterate("kk", "っk"), "kk");
|
||||
@ -92,7 +91,7 @@ TEST(TransliteratorsTest, RawStringSelector) {
|
||||
}
|
||||
|
||||
TEST(TransliteratorsTest, HiraganaTransliterator) {
|
||||
const TransliteratorInterface *t12r =
|
||||
const internal::TransliteratorInterface *t12r =
|
||||
Transliterators::GetTransliterator(Transliterators::HIRAGANA);
|
||||
EXPECT_EQ(t12r->Transliterate("zu", "ず"), "ず");
|
||||
// Half width "k" is transliterated into full width "k".
|
||||
@ -129,7 +128,7 @@ TEST(TransliteratorsTest, HiraganaTransliterator) {
|
||||
}
|
||||
|
||||
TEST(TransliteratorsTest, FullKatakanaTransliterator) {
|
||||
const TransliteratorInterface *t12r =
|
||||
const internal::TransliteratorInterface *t12r =
|
||||
Transliterators::GetTransliterator(Transliterators::FULL_KATAKANA);
|
||||
EXPECT_EQ(t12r->Transliterate("zu", "ず"), "ズ");
|
||||
// Half width "k" is transliterated into full width "k".
|
||||
@ -157,7 +156,7 @@ TEST(TransliteratorsTest, FullKatakanaTransliterator) {
|
||||
}
|
||||
|
||||
TEST(TransliteratorsTest, HalfKatakanaTransliterator) {
|
||||
const TransliteratorInterface *t12r =
|
||||
const internal::TransliteratorInterface *t12r =
|
||||
Transliterators::GetTransliterator(Transliterators::HALF_KATAKANA);
|
||||
EXPECT_EQ(t12r->Transliterate("zu", "ず"), "ズ");
|
||||
// Half width "k" remains in the current implementation (can be changed).
|
||||
@ -193,7 +192,7 @@ TEST(TransliteratorsTest, HalfKatakanaTransliterator) {
|
||||
}
|
||||
|
||||
TEST(TransliteratorsTest, HalfAsciiTransliterator) {
|
||||
const TransliteratorInterface *t12r =
|
||||
const internal::TransliteratorInterface *t12r =
|
||||
Transliterators::GetTransliterator(Transliterators::HALF_ASCII);
|
||||
EXPECT_EQ(t12r->Transliterate("zu", "ず"), "zu");
|
||||
EXPECT_EQ(t12r->Transliterate("kk", "っk"), "kk");
|
||||
@ -220,7 +219,7 @@ TEST(TransliteratorsTest, HalfAsciiTransliterator) {
|
||||
}
|
||||
|
||||
TEST(TransliteratorsTest, FullAsciiTransliterator) {
|
||||
const TransliteratorInterface *t12r =
|
||||
const internal::TransliteratorInterface *t12r =
|
||||
Transliterators::GetTransliterator(Transliterators::FULL_ASCII);
|
||||
EXPECT_EQ(t12r->Transliterate("zu", "ず"), "zu");
|
||||
EXPECT_EQ(t12r->Transliterate("kk", "っk"), "kk");
|
||||
|
Reference in New Issue
Block a user