File tree 4 files changed +59
-0
lines changed
python/core/auto_generated
4 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -162,6 +162,21 @@ numbers of digits between thousand separators
162
162
.. versionadded:: 2.9
163
163
%End
164
164
165
+ qlonglong qgsPermissiveToLongLong( QString string, bool &ok );
166
+ %Docstring
167
+ Converts a string to an qlonglong in a permissive way, e.g., allowing for incorrect
168
+ numbers of digits between thousand separators
169
+
170
+ :param string: string to convert
171
+ :param ok: will be set to true if conversion was successful
172
+
173
+ :return: string converted to int if possible
174
+
175
+ .. seealso:: :py:func:`permissiveToInt`
176
+
177
+ .. versionadded:: 3.4
178
+ %End
179
+
165
180
bool qgsVariantLessThan( const QVariant &lhs, const QVariant &rhs );
166
181
%Docstring
167
182
Compares two QVariant values and returns whether the first is less than the second.
Original file line number Diff line number Diff line change @@ -108,6 +108,13 @@ int qgsPermissiveToInt( QString string, bool &ok )
108
108
return QLocale ().toInt ( string, &ok );
109
109
}
110
110
111
+ qlonglong qgsPermissiveToLongLong ( QString string, bool &ok )
112
+ {
113
+ // remove any thousands separators
114
+ string.remove ( QLocale ().groupSeparator () );
115
+ return QLocale ().toLongLong ( string, &ok );
116
+ }
117
+
111
118
void *qgsMalloc ( size_t size )
112
119
{
113
120
if ( size == 0 || long ( size ) < 0 )
Original file line number Diff line number Diff line change @@ -409,6 +409,17 @@ CORE_EXPORT double qgsPermissiveToDouble( QString string, bool &ok );
409
409
*/
410
410
CORE_EXPORT int qgsPermissiveToInt ( QString string, bool &ok );
411
411
412
+ /* *
413
+ * Converts a string to an qlonglong in a permissive way, e.g., allowing for incorrect
414
+ * numbers of digits between thousand separators
415
+ * \param string string to convert
416
+ * \param ok will be set to true if conversion was successful
417
+ * \returns string converted to int if possible
418
+ * \see permissiveToInt
419
+ * \since QGIS 3.4
420
+ */
421
+ CORE_EXPORT qlonglong qgsPermissiveToLongLong ( QString string, bool &ok );
422
+
412
423
/* *
413
424
* Compares two QVariant values and returns whether the first is less than the second.
414
425
* Useful for sorting lists of variants, correctly handling sorting of the various
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ class TestQgis : public QObject
38
38
39
39
void permissiveToDouble ();
40
40
void permissiveToInt ();
41
+ void permissiveToLongLong ();
41
42
void doubleToString ();
42
43
void signalBlocker ();
43
44
void qVariantCompare_data ();
@@ -127,6 +128,31 @@ void TestQgis::permissiveToInt()
127
128
QCOMPARE ( result, 1000 );
128
129
}
129
130
131
+ void TestQgis::permissiveToLongLong ()
132
+ {
133
+ // good inputs
134
+ bool ok = false ;
135
+ qlonglong result = qgsPermissiveToLongLong ( QStringLiteral ( " 1000" ), ok );
136
+ QVERIFY ( ok );
137
+ QCOMPARE ( result, 1000 );
138
+ ok = false ;
139
+ result = qgsPermissiveToLongLong ( QStringLiteral ( " 1%01000" ).arg ( QLocale ().groupSeparator () ), ok );
140
+ QVERIFY ( ok );
141
+ QCOMPARE ( result, 1000 );
142
+
143
+ // bad input
144
+ ok = false ;
145
+ ( void ) qgsPermissiveToLongLong ( QStringLiteral ( " a" ), ok );
146
+ QVERIFY ( !ok );
147
+
148
+ // messy input (invalid thousand separator position), should still be converted
149
+ ok = false ;
150
+ result = qgsPermissiveToLongLong ( QStringLiteral ( " 10%0100" ).arg ( QLocale ().groupSeparator () ), ok );
151
+ QVERIFY ( ok );
152
+ QCOMPARE ( result, 1000 );
153
+
154
+ }
155
+
130
156
void TestQgis::doubleToString ()
131
157
{
132
158
QCOMPARE ( qgsDoubleToString ( 5.6783212 , 5 ), QString ( " 5.67832" ) );
You can’t perform that action at this time.
0 commit comments