Making changes in number classes to maintain compatibility with 2.1 applications
[platform/framework/native/appfw.git] / src / base / FBaseCharacter.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file                FBaseCharacter.cpp
19  * @brief               This is the implementation file for Char class.
20  */
21 #include <cwctype>
22
23 #include <appinfo.h>
24
25 #include <FBaseCharacter.h>
26 #include <FBaseSysLog.h>
27
28 #include "FBase_CharacterImpl.h"
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         if ((appinfo_get_api_version() == APP_INFO_VERSION_2_0) && (appinfo_is_compat() == 1))
206         {
207                 return(iswalpha(ch) != 0);
208         }
209         else
210         {
211                 return _CharacterImpl::IsLetter(ch);
212         }
213 }
214
215 bool
216 Character::IsLower(wchar_t ch)
217 {
218         return(iswlower(ch) != 0);
219 }
220
221 bool
222 Character::IsLowerCase(wchar_t ch)
223 {
224         return(Character::ToUpperCase(ch) != ch);
225 }
226
227 bool
228 Character::IsUpper(wchar_t ch)
229 {
230         return(iswupper(ch) != 0);
231 }
232
233 bool
234 Character::IsUpperCase(wchar_t ch)
235 {
236         return(Character::ToLowerCase(ch) != ch);
237 }
238
239 int
240 Character::ToDigit(wchar_t ch, int radix)
241 {
242         return _CharacterImpl::ToDigit(ch, radix);
243 }
244
245
246 wchar_t
247 Character::ForDigit(int digit, int radix)
248 {
249         return _CharacterImpl::ForDigit(digit, radix);
250 }
251
252
253 double
254 Character::GetNumericValue(wchar_t ch)
255 {
256         return _CharacterImpl::GetNumericValue(ch);
257 }
258
259
260 bool
261 Character::IsDefined(wchar_t ch)
262 {
263         return _CharacterImpl::IsDefined(ch);
264 }
265
266
267 bool
268 Character::IsWhitespace(wchar_t ch)
269 {
270         return _CharacterImpl::IsWhitespace(ch);
271 }
272
273 bool
274 Character::IsTitleCase(wchar_t ch)
275 {
276         return _CharacterImpl::IsTitleCase(ch);
277 }
278
279 wchar_t
280 Character::ToTitleCase(wchar_t ch)
281 {
282         return _CharacterImpl::ToTitleCase(ch);
283 }
284
285 bool
286 Character::IsISOControl(wchar_t ch)
287 {
288         return _CharacterImpl::IsISOControl(ch);
289 }
290
291 }} // Tizen::Base