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