Fix N_SE-32099 : zero length string may not save to setting.xml
[platform/framework/native/appfw.git] / src / base / FBaseBoolean.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FBaseBool.cpp
20  * @brief               This is the implementation file for Boolean class.
21  */
22
23 #include <FBaseBoolean.h>
24 #include <FBaseResult.h>
25
26
27 namespace Tizen { namespace Base
28 {
29
30 Boolean::Boolean(bool value)
31         : value(value)
32         , __pBooleanImpl(null)
33 {
34 }
35
36 Boolean::Boolean(const Boolean& value)
37         : value(value.value)
38         , __pBooleanImpl(null)
39 {
40 }
41
42 Boolean::Boolean(const String& value)
43 {
44         const String trueString = L"true";
45         String lowString;
46
47         value.ToLower(lowString);
48
49         if (lowString.Equals(trueString))
50         {
51                 this->value = true;
52         }
53         else
54         {
55                 this->value = false;
56         }
57
58         __pBooleanImpl = null;
59 }
60
61 Boolean::~Boolean(void)
62 {
63 }
64
65 bool
66 Boolean::operator ==(const Boolean& rhs) const
67 {
68         return(value == rhs.value);
69 }
70
71 bool
72 Boolean::operator !=(const Boolean& rhs) const
73 {
74         return(value != rhs.value);
75 }
76
77 Boolean&
78 Boolean::operator =(const Boolean& rhs)
79 {
80         if (&rhs != this)
81         {
82                 value = rhs.value;
83         }
84
85         return(*this);
86 }
87
88 bool
89 Boolean::Equals(const Object& obj) const
90 {
91         const Boolean* pOther = dynamic_cast <const Boolean*>(&obj);
92         if (pOther == null)
93         {
94                 return false;
95         }
96
97         return *this == *pOther;
98 }
99
100 int
101 Boolean::GetHashCode(void) const
102 {
103         return static_cast<int> (value);
104 }
105
106 bool
107 Boolean::Equals(bool value) const
108 {
109         return this->value == value;
110 }
111
112 bool
113 Boolean::ToBool(void) const
114 {
115         return value;
116 }
117
118 bool
119 Boolean::Parse(const String& s)
120 {
121         const String trueString = L"true";
122         if (s.Equals(trueString))
123         {
124                 return true;
125         }
126
127         return false;
128 }
129
130 bool
131 Boolean::Parse(const String& s, bool caseSensitive)
132 {
133         const String trueString = L"true";
134
135         if (caseSensitive)
136         {
137                 if (s.Equals(trueString))
138                 {
139                         return true;
140                 }
141         }
142         else
143         {
144                 int len = s.GetLength();
145                 int trueLen = trueString.GetLength();
146
147                 result r = E_SUCCESS;
148
149                 if (len != trueLen)
150                 {
151                         return false;
152                 }
153
154                 String lowString;
155
156                 r = s.ToLower(lowString);
157                 if (!lowString.Equals(trueString))
158                 {
159                         return false;
160                 }
161
162                 return true;
163         }
164
165         return false;
166 }
167
168 String
169 Boolean::ToString(void) const
170 {
171         return(Boolean::ToString(value));
172 }
173
174 String
175 Boolean::ToString(bool value)
176 {
177         String str;
178
179         if (value == true)
180         {
181                 str = L"true";
182         }
183         else
184         {
185                 str = L"false";
186         }
187
188         return str;
189 }
190
191 const Boolean
192 Boolean::GetTrue(void)
193 {
194         static const Boolean True(true);
195         return True;
196 }
197
198 const Boolean
199 Boolean::GetFalse(void)
200 {
201         static const Boolean False(false);
202         return False;
203 }
204
205 }} // Tizen::Base