Fix N_SE-32099 : zero length string may not save to setting.xml
[platform/framework/native/appfw.git] / src / base / FBaseCharacter.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                FBaseCharacter.cpp
20  * @brief               This is the implementation file for Char class.
21  */
22
23 #include <wctype.h>
24 #include <FBaseCharacter.h>
25 #include <FApp_AppInfo.h>
26 #include <FBaseSysLog.h>
27 #include "FBase_CharacterImpl.h"
28
29
30 namespace Tizen { namespace Base
31 {
32
33 Character::Character(wchar_t value)
34         : __val(value)
35         , __pCharacterImpl(null)
36 {
37 }
38
39 Character::Character(const Character& value)
40         : __val(value.__val)
41         , __pCharacterImpl(null)
42 {
43 }
44
45 Character::~Character(void)
46 {
47 }
48
49 Character&
50 Character::operator =(const Character& rhs)
51 {
52         if (&rhs != this)
53         {
54                 __val = rhs.__val;
55         }
56         return *this;
57 }
58
59 int
60 Character::CompareTo(const Character& value) const
61 {
62         return __val - value.__val;
63 }
64
65 bool
66 Character::Equals(const Object& obj) const
67 {
68         const Character* pOther = dynamic_cast <const Character*>(&obj);
69         if (pOther == null)
70         {
71                 return false;
72         }
73
74         return((*this).CompareTo((*pOther).ToMchar()) == 0 ? true : false);
75 }
76
77 int
78 Character::GetHashCode(void) const
79 {
80         return __val;
81 }
82
83 wchar_t
84 Character::ToMchar(void) const
85 {
86         return __val;
87 }
88
89 void
90 Character::ToLower(void)
91 {
92         if (IsUpper(__val))
93         {
94                 __val = towlower(__val);
95         }
96 }
97
98 void
99 Character::ToLowerCase(void)
100 {
101         __val = _CharacterImpl::ToLowerCase(__val);
102 }
103
104 void
105 Character::ToUpper(void)
106 {
107         if (IsLower(__val))
108         {
109                 __val = towupper(__val);
110         }
111 }
112
113 void
114 Character::ToUpperCase(void)
115 {
116         __val = _CharacterImpl::ToUpperCase(__val);
117 }
118
119 String
120 Character::ToString(void) const
121 {
122         return Character::ToString(__val);
123 }
124
125 String
126 Character::ToString(wchar_t value)
127 {
128         return String(value);
129 }
130
131 UnicodeCategory
132 Character::GetUnicodeCategory(wchar_t ch)
133 {
134         return _CharacterImpl::GetUnicodeCategory(ch);
135 }
136
137 wchar_t
138 Character::ToLower(wchar_t ch)
139 {
140         if (IsUpper(ch))
141         {
142                 return towlower(ch);
143         }
144         else
145         {
146                 return ch;
147         }
148 }
149
150 wchar_t
151 Character::ToLowerCase(wchar_t ch)
152 {
153         return _CharacterImpl::ToLowerCase(ch);
154 }
155
156 wchar_t
157 Character::ToUpper(wchar_t ch)
158 {
159         if (IsLower(ch))
160         {
161                 return towupper(ch);
162         }
163         else
164         {
165                 return ch;
166         }
167 }
168
169 wchar_t
170 Character::ToUpperCase(wchar_t ch)
171 {
172         return _CharacterImpl::ToUpperCase(ch);
173 }
174
175 bool
176 Character::IsAlphaNumeric(wchar_t ch)
177 {
178         if (_CharacterImpl::IsLetter(ch))
179         {
180                 return true;
181         }
182
183         if (_CharacterImpl::IsDigit(ch))
184         {
185                 return true;
186         }
187
188         return false;
189 }
190
191 bool
192 Character::IsDigit(wchar_t ch)
193 {
194         if (_CharacterImpl::IsDigit(ch))
195         {
196                 return true;
197         }
198
199         return false;
200 }
201
202 bool
203 Character::IsLetter(wchar_t ch)
204 {
205
206         if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
207         {
208                 return(iswalpha(ch) !=0);
209         }
210         else
211         {
212                 return _CharacterImpl::IsLetter(ch);
213         }
214 }
215
216 bool
217 Character::IsLower(wchar_t ch)
218 {
219         return(iswlower(ch) != 0);
220 }
221
222 bool
223 Character::IsLowerCase(wchar_t ch)
224 {
225         return(Character::ToUpperCase(ch) != ch);
226 }
227
228 bool
229 Character::IsUpper(wchar_t ch)
230 {
231         return(iswupper(ch) != 0);
232 }
233
234 bool
235 Character::IsUpperCase(wchar_t ch)
236 {
237         return(Character::ToLowerCase(ch) != ch);
238 }
239
240 int
241 Character::ToDigit(wchar_t ch, int radix)
242 {
243         return _CharacterImpl::ToDigit(ch, radix);
244 }
245
246
247 wchar_t
248 Character::ForDigit(int digit, int radix)
249 {
250         return _CharacterImpl::ForDigit(digit, radix);
251 }
252
253
254 double
255 Character::GetNumericValue(wchar_t ch)
256 {
257         return _CharacterImpl::GetNumericValue(ch);
258 }
259
260
261 bool
262 Character::IsDefined(wchar_t ch)
263 {
264         return _CharacterImpl::IsDefined(ch);
265 }
266
267
268 bool
269 Character::IsWhitespace(wchar_t ch)
270 {
271         return _CharacterImpl::IsWhitespace(ch);
272 }
273
274 bool
275 Character::IsTitleCase(wchar_t ch)
276 {
277         return _CharacterImpl::IsTitleCase(ch);
278 }
279
280 wchar_t
281 Character::ToTitleCase(wchar_t ch)
282 {
283         return _CharacterImpl::ToTitleCase(ch);
284 }
285
286 bool
287 Character::IsISOControl(wchar_t ch)
288 {
289         return _CharacterImpl::IsISOControl(ch);
290 }
291
292 }} // Tizen::Base