Changeset View
Changeset View
Standalone View
Standalone View
src/countrytoisomap_p.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | This file is part of the KContacts framework. | ||||
3 | Copyright (c) 2018 Volker Krause <vkrause@kde.org> | ||||
4 | | ||||
5 | This library is free software; you can redistribute it and/or | ||||
6 | modify it under the terms of the GNU Library General Public | ||||
7 | License as published by the Free Software Foundation; either | ||||
8 | version 2 of the License, or (at your option) any later version. | ||||
9 | | ||||
10 | This library is distributed in the hope that it will be useful, | ||||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
13 | Library General Public License for more details. | ||||
14 | | ||||
15 | You should have received a copy of the GNU Library General Public License | ||||
16 | along with this library; see the file COPYING.LIB. If not, write to | ||||
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
18 | Boston, MA 02110-1301, USA. | ||||
19 | */ | ||||
20 | | ||||
21 | #ifndef KCONTACTS_COUNTRYTOISOMAP_P_H | ||||
22 | #define KCONTACTS_COUNTRYTOISOMAP_P_H | ||||
23 | | ||||
24 | #include <QString> | ||||
25 | | ||||
26 | namespace KContacts { | ||||
27 | | ||||
28 | /* Pack the string table offset and the country ISO code into 32 bit. | ||||
29 | * The ISO code needs 2x 5bit, leaving 22 bit for the offset, which is plenty | ||||
30 | * considering the string is only about 500k chars long. | ||||
31 | */ | ||||
32 | struct CountryToIsoIndex | ||||
33 | { | ||||
34 | explicit constexpr inline CountryToIsoIndex(int offset, const char isoCode[2]) | ||||
35 | : m_offset(offset) | ||||
36 | , m_c1(isoCode[0] - 'a') | ||||
37 | , m_c2(isoCode[1] - 'a') | ||||
38 | { | ||||
39 | } | ||||
40 | | ||||
41 | inline QString isoCode() const | ||||
42 | { | ||||
43 | char s[2]; | ||||
44 | s[0] = 'a' + m_c1; | ||||
45 | s[1] = 'a' + m_c2; | ||||
46 | return QLatin1String(s, 2); | ||||
47 | } | ||||
48 | | ||||
49 | uint32_t m_offset: 22; | ||||
50 | uint32_t m_c1: 5; | ||||
51 | uint32_t m_c2: 5; | ||||
52 | }; | ||||
53 | | ||||
54 | } | ||||
55 | | ||||
56 | #endif |