Fix the boiler plate codes
[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
22 #include <wctype.h>
23 #include <FBaseCharacter.h>
24 #include <FApp_AppInfo.h>
25 #include <FBaseSysLog.h>
26 #include "FBase_CharacterImpl.h"
27
28
29 namespace Tizen { namespace Base
30 {
31
32 Character::Character(wchar_t value)
33         : __val(value)
34         , __pCharacterImpl(null)
35 {
36 }
37
38 Character::Character(const Character& value)
39         : __val(value.__val)
40         , __pCharacterImpl(null)
41 {
42 }
43
44 Character::~Character(void)
45 {
46 }
47
48 Character&
49 Character::operator =(const Character& rhs)
50 {
51         if (&rhs != this)
52         {
53                 __val = rhs.__val;
54         }
55         return *this;
56 }
57
58 int
59 Character::CompareTo(const Character& value) const
60 {
61         return __val - value.__val;
62 }
63
64 bool
65 Character::Equals(const Object& obj) const
66 {
67         const Character* pOther = dynamic_cast <const Character*>(&obj);
68         if (pOther == null)
69         {
70                 return false;
71         }
72
73         return((*this).CompareTo((*pOther).ToMchar()) == 0 ? true : false);
74 }
75
76 int
77 Character::GetHashCode(void) const
78 {
79         return __val;
80 }
81
82 wchar_t
83 Character::ToMchar(void) const
84 {
85         return __val;
86 }
87
88 void
89 Character::ToLower(void)
90 {
91         if (IsUpper(__val))
92         {
93                 __val = towlower(__val);
94         }
95 }
96
97 void
98 Character::ToLowerCase(void)
99 {
100         __val = _CharacterImpl::ToLowerCase(__val);
101 }
102
103 void
104 Character::ToUpper(void)
105 {
106         if (IsLower(__val))
107         {
108                 __val = towupper(__val);
109         }
110 }
111
112 void
113 Character::ToUpperCase(void)
114 {
115         __val = _CharacterImpl::ToUpperCase(__val);
116 }
117
118 String
119 Character::ToString(void) const
120 {
121         return Character::ToString(__val);
122 }
123
124 String
125 Character::ToString(wchar_t value)
126 {
127         return String(value);
128 }
129
130 UnicodeCategory
131 Character::GetUnicodeCategory(wchar_t ch)
132 {
133         return _CharacterImpl::GetUnicodeCategory(ch);
134 }
135
136 wchar_t
137 Character::ToLower(wchar_t ch)
138 {
139         if (IsUpper(ch))
140         {
141                 return towlower(ch);
142         }
143         else
144         {
145                 return ch;
146         }
147 }
148
149 wchar_t
150 Character::ToLowerCase(wchar_t ch)
151 {
152         return _CharacterImpl::ToLowerCase(ch);
153 }
154
155 wchar_t
156 Character::ToUpper(wchar_t ch)
157 {
158         if (IsLower(ch))
159         {
160                 return towupper(ch);
161         }
162         else
163         {
164                 return ch;
165         }
166 }
167
168 wchar_t
169 Character::ToUpperCase(wchar_t ch)
170 {
171         return _CharacterImpl::ToUpperCase(ch);
172 }
173
174 bool
175 Character::IsAlphaNumeric(wchar_t ch)
176 {
177         if (_CharacterImpl::IsLetter(ch))
178         {
179                 return true;
180         }
181
182         if (_CharacterImpl::IsDigit(ch))
183         {
184                 return true;
185         }
186
187         return false;
188 }
189
190 bool
191 Character::IsDigit(wchar_t ch)
192 {
193         if (_CharacterImpl::IsDigit(ch))
194         {
195                 return true;
196         }
197
198         return false;
199 }
200
201 bool
202 Character::IsLetter(wchar_t ch)
203 {
204
205         if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
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