summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qstring.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-11-04 10:57:10 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-11-19 11:30:23 +0000
commite17629e32dff5a85110a1785a98768cdbe3f091d (patch)
treea9ad8a4df1d6224f2c76fa6d5222a2489c9ef7a2 /src/corelib/tools/qstring.cpp
parent139fd9bd0d0bd2372d7616bbf533f70c18667ecc (diff)
QString::vasprintf: Extract Method parse_field_width
... and reuse the function to parse precision, too. This also allows to more easily simplify it (done in a follow-up commit). Change-Id: I9da27c4b06565f676e15ef9cab7c53b5d464515e Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'src/corelib/tools/qstring.cpp')
-rw-r--r--src/corelib/tools/qstring.cpp33
1 files changed, 15 insertions, 18 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index d36aef8620..e0d2fc3a5e 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -5883,6 +5883,17 @@ static uint parse_flag_characters(const char * &c) Q_DECL_NOTHROW
}
}
+static int parse_field_width(const char * &c)
+{
+ QString width_str;
+ while (*c != '\0' && qIsDigit(*c))
+ width_str.append(QLatin1Char(*c++));
+
+ // can't be negative - started with a digit
+ // contains at least one digit
+ return width_str.toInt();
+}
+
/*!
\fn QString::vasprintf(const char *cformat, va_list ap)
\since 5.5
@@ -5942,15 +5953,8 @@ QString QString::vasprintf(const char *cformat, va_list ap)
// Parse field width
int width = -1; // -1 means unspecified
if (qIsDigit(*c)) {
- QString width_str;
- while (*c != '\0' && qIsDigit(*c))
- width_str.append(QLatin1Char(*c++));
-
- // can't be negative - started with a digit
- // contains at least one digit
- width = width_str.toInt();
- }
- else if (*c == '*') {
+ width = parse_field_width(c);
+ } else if (*c == '*') { // can't parse this in another function, not portably, at least
width = va_arg(ap, int);
if (width < 0)
width = -1; // treat all negative numbers as unspecified
@@ -5967,15 +5971,8 @@ QString QString::vasprintf(const char *cformat, va_list ap)
if (*c == '.') {
++c;
if (qIsDigit(*c)) {
- QString precision_str;
- while (*c != '\0' && qIsDigit(*c))
- precision_str.append(QLatin1Char(*c++));
-
- // can't be negative - started with a digit
- // contains at least one digit
- precision = precision_str.toInt();
- }
- else if (*c == '*') {
+ precision = parse_field_width(c);
+ } else if (*c == '*') { // can't parse this in another function, not portably, at least
precision = va_arg(ap, int);
if (precision < 0)
precision = -1; // treat all negative numbers as unspecified