Debian Codegraph @

src/Convert.h

raw symbols SCIP
1 #cxx . . $ `<file>/src/Convert.h`/ifndef CONVERT_H
2 #define CONVERT_Hcxx . . $ `src/Convert.h:2:9`!
3
4 #include <QString>
5 #include <cstdint>
6 #include <optional>
7 #include <limits>
8
9 QStringcxx . . $ QString# hexValuecxx . . $ hexValue(f4fd9db251ca774b).(int value, int width = 0);
10 QStringcxx . . $ QString# escapeXMLcxx . . $ escapeXML(f7f320d754b8fd09).(QStringcxx . . $ QString# str);
11 QStringcxx . . $ QString# unescapeXMLcxx . . $ unescapeXML(f7f320d754b8fd09).(QStringcxx . . $ QString# str);
12
13 // Create optional<T> if boolean b is true.
14 template <typename T>
15 stdcxx . . $ std/::optionalcxx . . $ std/optional#<T> make_ifcxx . . $ make_if(e25f002ff5d2f3ed).(bool b, T value)
16 {
17 return b ? value : stdcxx . . $ std/::optionalcxx . . $ std/optional#<T>();
18 }
19
20 template <typename T>
21 stdcxx . . $ std/::optionalcxx . . $ std/optional#<T> make_positive_optionalcxx . . $ make_positive_optional(42be48c011d89853).(int value)
22 {
23 return make_ifcxx . . $ make_if(e25f002ff5d2f3ed).<T>(value >= 0, T(value));
24 }
25
26 template <typename T>
27 stdcxx . . $ std/::optionalcxx . . $ std/optional#<T> stringToValuecxx . . $ stringToValue(e8c2a6ba39be27fd).(const QStringcxx . . $ QString#& str)
28 {
29 QStringcxx . . $ QString# s = str.trimmedcxx . . $ QString#trimmed(dca2c5857e9adf82).();
30 int base = 10;
31
32 // find base (prefix or postfix)
33 if (s.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).("&"cxx . . $ QString#QString(85c52e162fed56f9).) && s.sizecxx . . $ QString#size(455f465bc33b4cdf).() >= 2) {
34 switch (s[cxx . . $ QString#`operator[]`(57436120916eb52c).1].toUppercxx . . $ QCharRef#toUpper(ae16b0053a7bf832).().toLatin1cxx . . $ QChar#toLatin1(a33b425be6aff8f0).()) {
35 case 'H':
36 base = 16;
37 break;
38 case 'B':
39 base = 2;
40 break;
41 case 'O':
42 base = 8;
43 break;
44 }
45 s =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). s.removecxx . . $ QString#remove(6483560ce2afa901).(0, 2);
46 } else if (s.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).("#"cxx . . $ QString#QString(85c52e162fed56f9).) || s.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).("$"cxx . . $ QString#QString(85c52e162fed56f9).)) {
47 base = 16;
48 s =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). s.removecxx . . $ QString#remove(6483560ce2afa901).(0, 1);
49 } else if (s.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).("0x"cxx . . $ QString#QString(85c52e162fed56f9).)) {
50 base = 16;
51 s =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). s.removecxx . . $ QString#remove(6483560ce2afa901).(0, 2);
52 } else if (s.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).("%"cxx . . $ QString#QString(85c52e162fed56f9).)) {
53 base = 2;
54 s =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). s.removecxx . . $ QString#remove(6483560ce2afa901).(0, 1);
55 } else if (!s.isEmptycxx . . $ QString#isEmpty(50ce9a9e25b4a850).()) {
56 switch (s.rightcxx . . $ QString#right(3f3c3d0e9c0eb37f).(1)[cxx . . $ QString#`operator[]`(57436120916eb52c).0].toUppercxx . . $ QCharRef#toUpper(ae16b0053a7bf832).().toLatin1cxx . . $ QChar#toLatin1(a33b425be6aff8f0).()) {
57 case 'H':
58 case '#':
59 base = 16;
60 break;
61 case 'B':
62 base = 2;
63 break;
64 case 'O':
65 base = 8;
66 break;
67 }
68 if (base != 10) s.chopcxx . . $ QString#chop(d4f767463ce0a6b3).(1);
69 }
70
71 // convert value
72 bool ok;
73 int value = s.toIntcxx . . $ QString#toInt(d7972accae11ee1f).(&ok, base);
74 if (!ok) return {};
75
76 // reject {under|over}flow
77 T max = stdcxx . . $ std/::numeric_limitscxx . . $ std/numeric_limits#<T>::max();
78 T min = stdcxx . . $ std/::numeric_limitscxx . . $ std/numeric_limits#<T>::min();
79 if (value >cxx . . $ `operator>`(4ac7649f87ab4440). max || value <cxx . . $ `operator<`(a4c5a3a75515ddde). min) return {};
80
81 return value;
82 }
83
84 #endif // CONVERT_H