|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbCore module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 #include "hbnumbergrouping.h" |
|
27 #include "hbngnormalnumber_p.h" |
|
28 |
|
29 /*! |
|
30 @stable |
|
31 @hbcore |
|
32 \class HbNumberGrouping |
|
33 \brief HbNumberGrouping formats numbers according to conventions of a certain country. |
|
34 Eg. for Finland: "123456789.00" => "123 456 789,00". |
|
35 |
|
36 NOTE! |
|
37 - Characters in 'number' parameter needs to be latin numbers even though the type of parameter is QString. |
|
38 - Also '+' and '-' characters are supported. |
|
39 - Decimal separator needs to be a dot '.' always. |
|
40 - Any other characters than above descripted are not allowed. |
|
41 - If grouping fails for some reason then return value is empty QString (NULL). |
|
42 - At the moment currency mark is not added to return value (formatCurrency). |
|
43 - Grouping for phone numbers is not activated yet. |
|
44 |
|
45 Example: |
|
46 |
|
47 \snippet{unittest_hbnumbergrouping/unittest_hbnumbergrouping.cpp,1} |
|
48 |
|
49 */ |
|
50 |
|
51 /*! |
|
52 Static function for creating a (generic) number group. |
|
53 |
|
54 \param number Source number for grouping. |
|
55 \param country Format for number converting. |
|
56 If the country is not given (country = QLocale::AnyCountry) then it will be requested from QLocale::country. |
|
57 \return Modified string. |
|
58 */ |
|
59 QString HbNumberGrouping::formatGeneric( const QString &number, |
|
60 QLocale::Country country ) |
|
61 { |
|
62 if ( number.size() == 0 ) { |
|
63 return QString(); |
|
64 } |
|
65 |
|
66 if ( country == QLocale::AnyCountry) { |
|
67 QLocale locale; |
|
68 country = locale.country(); |
|
69 } |
|
70 |
|
71 return HbNgNormalNumber::normalNumberGrouping(number, country); |
|
72 } |
|
73 |
|
74 /*! |
|
75 Static function for creating a currency group. |
|
76 |
|
77 \param number Source number for grouping. |
|
78 \param country Format for number converting. |
|
79 If the country is not given (country = QLocale::AnyCountry) then it will be requested from QLocale::country. |
|
80 \return Modified string. |
|
81 */ |
|
82 QString HbNumberGrouping::formatCurrency( const QString &number, |
|
83 QLocale::Country country ) |
|
84 { |
|
85 if ( number.size() == 0 ) { |
|
86 return QString(); |
|
87 } |
|
88 |
|
89 if ( country == QLocale::AnyCountry) { |
|
90 QLocale locale; |
|
91 country = locale.country(); |
|
92 } |
|
93 |
|
94 return HbNgNormalNumber::normalNumberGrouping(number, country); |
|
95 } |
|
96 |
|
97 /*! |
|
98 Static function for creating a phone number group. |
|
99 |
|
100 \param number Source number for grouping. |
|
101 \param country Format for number converting. |
|
102 If the country is not given (country = QLocale::AnyCountry) then it will be requested from QLocale::country. |
|
103 \return Modified string. |
|
104 */ |
|
105 QString HbNumberGrouping::formatPhoneNumber( const QString &number, |
|
106 QLocale::Country country ) |
|
107 { |
|
108 if ( number.size() == 0 ) { |
|
109 return QString(); |
|
110 } |
|
111 |
|
112 if ( country == QLocale::AnyCountry) { |
|
113 QLocale locale; |
|
114 country = locale.country(); |
|
115 } |
|
116 |
|
117 return QString(); |
|
118 } |