Dedent some switch statement bodies to match coding style
The case labels are meant to line up with the switch statement. Change-Id: I62a45ffca22582d2264ecb3eb5ad7fbfe2aa148b Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
e204de690b
commit
846e532458
@ -2645,17 +2645,17 @@ QString QLocale::toString(double f, char format, int precision) const
|
|||||||
uint flags = isAsciiUpper(format) ? QLocaleData::CapitalEorX : 0;
|
uint flags = isAsciiUpper(format) ? QLocaleData::CapitalEorX : 0;
|
||||||
|
|
||||||
switch (QtMiscUtils::toAsciiLower(format)) {
|
switch (QtMiscUtils::toAsciiLower(format)) {
|
||||||
case 'f':
|
case 'f':
|
||||||
form = QLocaleData::DFDecimal;
|
form = QLocaleData::DFDecimal;
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
form = QLocaleData::DFExponent;
|
form = QLocaleData::DFExponent;
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
form = QLocaleData::DFSignificantDigits;
|
form = QLocaleData::DFSignificantDigits;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(d->m_numberOptions & OmitGroupSeparator))
|
if (!(d->m_numberOptions & OmitGroupSeparator))
|
||||||
@ -3568,76 +3568,76 @@ QString QLocaleData::doubleToString(double d, int precision, DoubleForm form,
|
|||||||
const bool groupDigits = flags & GroupDigits;
|
const bool groupDigits = flags & GroupDigits;
|
||||||
const int minExponentDigits = flags & ZeroPadExponent ? 2 : 1;
|
const int minExponentDigits = flags & ZeroPadExponent ? 2 : 1;
|
||||||
switch (form) {
|
switch (form) {
|
||||||
case DFExponent:
|
case DFExponent:
|
||||||
numStr = exponentForm(std::move(digits), decpt, precision, PMDecimalDigits,
|
numStr = exponentForm(std::move(digits), decpt, precision, PMDecimalDigits,
|
||||||
mustMarkDecimal, minExponentDigits);
|
mustMarkDecimal, minExponentDigits);
|
||||||
break;
|
break;
|
||||||
case DFDecimal:
|
case DFDecimal:
|
||||||
numStr = decimalForm(std::move(digits), decpt, precision, PMDecimalDigits,
|
numStr = decimalForm(std::move(digits), decpt, precision, PMDecimalDigits,
|
||||||
mustMarkDecimal, groupDigits);
|
mustMarkDecimal, groupDigits);
|
||||||
break;
|
break;
|
||||||
case DFSignificantDigits: {
|
case DFSignificantDigits: {
|
||||||
PrecisionMode mode = (flags & AddTrailingZeroes) ?
|
PrecisionMode mode = (flags & AddTrailingZeroes) ?
|
||||||
PMSignificantDigits : PMChopTrailingZeros;
|
PMSignificantDigits : PMChopTrailingZeros;
|
||||||
|
|
||||||
/* POSIX specifies sprintf() to follow fprintf(), whose 'g/G'
|
/* POSIX specifies sprintf() to follow fprintf(), whose 'g/G'
|
||||||
format says; with P = 6 if precision unspecified else 1 if
|
format says; with P = 6 if precision unspecified else 1 if
|
||||||
precision is 0 else precision; when 'e/E' would have exponent
|
precision is 0 else precision; when 'e/E' would have exponent
|
||||||
X, use:
|
X, use:
|
||||||
* 'f/F' if P > X >= -4, with precision P-1-X
|
* 'f/F' if P > X >= -4, with precision P-1-X
|
||||||
* 'e/E' otherwise, with precision P-1
|
* 'e/E' otherwise, with precision P-1
|
||||||
Helpfully, we already have mapped precision < 0 to 6 - except
|
Helpfully, we already have mapped precision < 0 to 6 - except
|
||||||
for F.P.Shortest mode, which is its own story - and those of
|
for F.P.Shortest mode, which is its own story - and those of
|
||||||
our callers with unspecified precision either used 6 or -1
|
our callers with unspecified precision either used 6 or -1
|
||||||
for it.
|
for it.
|
||||||
*/
|
*/
|
||||||
bool useDecimal;
|
bool useDecimal;
|
||||||
if (precision == QLocale::FloatingPointShortest) {
|
if (precision == QLocale::FloatingPointShortest) {
|
||||||
// Find out which representation is shorter.
|
// Find out which representation is shorter.
|
||||||
// Set bias to everything added to exponent form but not
|
// Set bias to everything added to exponent form but not
|
||||||
// decimal, minus the converse.
|
// decimal, minus the converse.
|
||||||
|
|
||||||
// Exponent adds separator, sign and digits:
|
// Exponent adds separator, sign and digits:
|
||||||
int bias = 2 + minExponentDigits;
|
int bias = 2 + minExponentDigits;
|
||||||
// Decimal form may get grouping separators inserted:
|
// Decimal form may get grouping separators inserted:
|
||||||
if (groupDigits && decpt >= m_grouping_top + m_grouping_least)
|
if (groupDigits && decpt >= m_grouping_top + m_grouping_least)
|
||||||
bias -= (decpt - m_grouping_top - m_grouping_least) / m_grouping_higher + 1;
|
bias -= (decpt - m_grouping_top - m_grouping_least) / m_grouping_higher + 1;
|
||||||
// X = decpt - 1 needs two digits if decpt > 10:
|
// X = decpt - 1 needs two digits if decpt > 10:
|
||||||
if (decpt > 10 && minExponentDigits == 1)
|
if (decpt > 10 && minExponentDigits == 1)
|
||||||
++bias;
|
++bias;
|
||||||
// Assume digitCount < 95, so we can ignore the 3-digit
|
// Assume digitCount < 95, so we can ignore the 3-digit
|
||||||
// exponent case (we'll set useDecimal false anyway).
|
// exponent case (we'll set useDecimal false anyway).
|
||||||
|
|
||||||
const qsizetype digitCount = digits.size() / zero.size();
|
const qsizetype digitCount = digits.size() / zero.size();
|
||||||
if (!mustMarkDecimal) {
|
if (!mustMarkDecimal) {
|
||||||
// Decimal separator is skipped if at end; adjust if
|
// Decimal separator is skipped if at end; adjust if
|
||||||
// that happens for only one form:
|
// that happens for only one form:
|
||||||
if (digitCount <= decpt && digitCount > 1)
|
if (digitCount <= decpt && digitCount > 1)
|
||||||
++bias; // decimal but not exponent
|
++bias; // decimal but not exponent
|
||||||
else if (digitCount == 1 && decpt <= 0)
|
else if (digitCount == 1 && decpt <= 0)
|
||||||
--bias; // exponent but not decimal
|
--bias; // exponent but not decimal
|
||||||
}
|
|
||||||
// When 0 < decpt <= digitCount, the forms have equal digit
|
|
||||||
// counts, plus things bias has taken into account;
|
|
||||||
// otherwise decimal form's digit count is right-padded with
|
|
||||||
// zeros to decpt, when decpt is positive, otherwise it's
|
|
||||||
// left-padded with 1 - decpt zeros.
|
|
||||||
useDecimal = (decpt <= 0 ? 1 - decpt <= bias
|
|
||||||
: decpt <= digitCount ? 0 <= bias
|
|
||||||
: decpt <= digitCount + bias);
|
|
||||||
} else {
|
|
||||||
// X == decpt - 1, POSIX's P; -4 <= X < P iff -4 < decpt <= P
|
|
||||||
Q_ASSERT(precision >= 0);
|
|
||||||
useDecimal = decpt > -4 && decpt <= (precision ? precision : 1);
|
|
||||||
}
|
}
|
||||||
|
// When 0 < decpt <= digitCount, the forms have equal digit
|
||||||
numStr = useDecimal
|
// counts, plus things bias has taken into account;
|
||||||
? decimalForm(std::move(digits), decpt, precision, mode,
|
// otherwise decimal form's digit count is right-padded with
|
||||||
mustMarkDecimal, groupDigits)
|
// zeros to decpt, when decpt is positive, otherwise it's
|
||||||
: exponentForm(std::move(digits), decpt, precision, mode,
|
// left-padded with 1 - decpt zeros.
|
||||||
mustMarkDecimal, minExponentDigits);
|
useDecimal = (decpt <= 0 ? 1 - decpt <= bias
|
||||||
break;
|
: decpt <= digitCount ? 0 <= bias
|
||||||
|
: decpt <= digitCount + bias);
|
||||||
|
} else {
|
||||||
|
// X == decpt - 1, POSIX's P; -4 <= X < P iff -4 < decpt <= P
|
||||||
|
Q_ASSERT(precision >= 0);
|
||||||
|
useDecimal = decpt > -4 && decpt <= (precision ? precision : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
numStr = useDecimal
|
||||||
|
? decimalForm(std::move(digits), decpt, precision, mode,
|
||||||
|
mustMarkDecimal, groupDigits)
|
||||||
|
: exponentForm(std::move(digits), decpt, precision, mode,
|
||||||
|
mustMarkDecimal, minExponentDigits);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pad with zeros. LeftAdjusted overrides ZeroPadded.
|
// Pad with zeros. LeftAdjusted overrides ZeroPadded.
|
||||||
@ -4002,47 +4002,47 @@ bool QLocaleData::validateChars(QStringView str, NumberMode numMode, QByteArray
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '.':
|
case '.':
|
||||||
// If an integer has a decimal point, it is Invalid.
|
// If an integer has a decimal point, it is Invalid.
|
||||||
// A double can only have one, at the end of its whole-number part.
|
// A double can only have one, at the end of its whole-number part.
|
||||||
if (numMode == IntegerMode || state != Whole)
|
if (numMode == IntegerMode || state != Whole)
|
||||||
return false;
|
|
||||||
// Even when decDigits is 0, we do allow the decimal point to be
|
|
||||||
// present - just as long as no digits follow it.
|
|
||||||
|
|
||||||
state = Fractional;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '+':
|
|
||||||
case '-':
|
|
||||||
// A sign can only appear at the start or after the e of scientific:
|
|
||||||
if (last != '\0' && !(scientific && last == 'e'))
|
|
||||||
return false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ',':
|
|
||||||
// Grouping is only allowed after a digit in the whole-number portion:
|
|
||||||
if ((number_options & QLocale::RejectGroupSeparator) || state != Whole
|
|
||||||
|| last < '0' || last > '9') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// We could check grouping sizes are correct, but fixup()s are
|
|
||||||
// probably better off correcting any misplacement instead.
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'e':
|
|
||||||
// Only one e is allowed and only in scientific:
|
|
||||||
if (!scientific || state == Exponent)
|
|
||||||
return false;
|
|
||||||
state = Exponent;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
// Nothing else can validly appear in a number.
|
|
||||||
// In fact, numericToCLocale() must have returned 0. If anyone changes
|
|
||||||
// it to return something else, we probably need to handle it here !
|
|
||||||
Q_ASSERT(!c);
|
|
||||||
return false;
|
return false;
|
||||||
|
// Even when decDigits is 0, we do allow the decimal point to be
|
||||||
|
// present - just as long as no digits follow it.
|
||||||
|
|
||||||
|
state = Fractional;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '+':
|
||||||
|
case '-':
|
||||||
|
// A sign can only appear at the start or after the e of scientific:
|
||||||
|
if (last != '\0' && !(scientific && last == 'e'))
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ',':
|
||||||
|
// Grouping is only allowed after a digit in the whole-number portion:
|
||||||
|
if ((number_options & QLocale::RejectGroupSeparator) || state != Whole
|
||||||
|
|| last < '0' || last > '9') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// We could check grouping sizes are correct, but fixup()s are
|
||||||
|
// probably better off correcting any misplacement instead.
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'e':
|
||||||
|
// Only one e is allowed and only in scientific:
|
||||||
|
if (!scientific || state == Exponent)
|
||||||
|
return false;
|
||||||
|
state = Exponent;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Nothing else can validly appear in a number.
|
||||||
|
// In fact, numericToCLocale() must have returned 0. If anyone changes
|
||||||
|
// it to return something else, we probably need to handle it here !
|
||||||
|
Q_ASSERT(!c);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user