1 // Copyright 2010-2018, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 #include "composer/internal/composition_input.h"
31
32 #include "base/logging.h"
33
34 namespace mozc {
35 namespace composer {
36
CompositionInput()37 CompositionInput::CompositionInput()
38 : has_conversion_(false),
39 is_new_input_(false),
40 transliterator_(NULL) {}
41
~CompositionInput()42 CompositionInput::~CompositionInput() {}
43
Clear()44 void CompositionInput::Clear() {
45 raw_.clear();
46 conversion_.clear();
47 has_conversion_ = false;
48 is_new_input_ = false;
49 transliterator_ = NULL;
50 }
51
Empty() const52 bool CompositionInput::Empty() const {
53 if (has_conversion()) {
54 return raw().empty() && conversion().empty();
55 } else {
56 return raw().empty();
57 }
58 }
59
CopyFrom(const CompositionInput & input)60 void CompositionInput::CopyFrom(const CompositionInput &input) {
61 raw_ = input.raw();
62 if (input.has_conversion()) {
63 conversion_ = input.conversion();
64 has_conversion_ = true;
65 } else {
66 conversion_.clear();
67 has_conversion_ = false;
68 }
69 is_new_input_ = input.is_new_input();
70 transliterator_ = input.transliterator();
71 }
72
raw() const73 const string &CompositionInput::raw() const {
74 return raw_;
75 }
76
mutable_raw()77 string *CompositionInput::mutable_raw() {
78 return &raw_;
79 }
80
set_raw(const string & raw)81 void CompositionInput::set_raw(const string &raw) {
82 raw_ = raw;
83 }
84
conversion() const85 const string &CompositionInput::conversion() const {
86 if (has_conversion_) {
87 return conversion_;
88 } else {
89 LOG(WARNING) << "conversion is not set.";
90 static const string kEmptyString = "";
91 return kEmptyString;
92 }
93 }
94
mutable_conversion()95 string *CompositionInput::mutable_conversion() {
96 has_conversion_ = true;
97 // If has_conversion_ was false, conversion_ should be empty.
98 return &conversion_;
99 }
100
set_conversion(const string & conversion)101 void CompositionInput::set_conversion(const string &conversion) {
102 conversion_ = conversion;
103 has_conversion_ = true;
104 }
105
has_conversion() const106 bool CompositionInput::has_conversion() const {
107 return has_conversion_;
108 }
109
is_new_input() const110 bool CompositionInput::is_new_input() const {
111 return is_new_input_;
112 }
113
set_is_new_input(bool is_new_input)114 void CompositionInput::set_is_new_input(bool is_new_input) {
115 is_new_input_ = is_new_input;
116 }
117
transliterator() const118 const TransliteratorInterface *CompositionInput::transliterator() const {
119 return transliterator_;
120 }
121
set_transliterator(const TransliteratorInterface * t12r)122 void CompositionInput::set_transliterator(const TransliteratorInterface *t12r) {
123 transliterator_ = t12r;
124 }
125
126 } // namespace composer
127 } // namespace mozc
128