forked from qt-creator/qt-creator
CppEditor: better detection of the system a numeric literal is in
Fixes: The literal 1 (or any decimal of length 1) was misdetected as not already a decimal literal which resulted in a quickfix "Convert to decimal". Improves: More consistent handling of 0. Octal is now handled like the other cases. The user is offered to turn 0, 0x0, or 0b0 into 00. Change-Id: I9a559fc328d0b49bfe0e53b933e8b4fee5af27a5 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
committed by
André Hartmann
parent
c9ad2a49b6
commit
6f56feef29
@@ -1495,6 +1495,10 @@ void ConvertNumericLiteral::match(const CppQuickFixInterface &interface, QuickFi
|
|||||||
const int start = file->startOf(literal);
|
const int start = file->startOf(literal);
|
||||||
const char * const str = numeric->chars();
|
const char * const str = numeric->chars();
|
||||||
|
|
||||||
|
const bool isBinary = numberLength > 2 && str[0] == '0' && tolower(str[1]) == 'b';
|
||||||
|
const bool isOctal = numberLength >= 2 && str[0] == '0' && str[1] >= '0' && str[1] <= '7';
|
||||||
|
const bool isDecimal = !(isBinary || isOctal || numeric->isHex());
|
||||||
|
|
||||||
if (!numeric->isHex()) {
|
if (!numeric->isHex()) {
|
||||||
/*
|
/*
|
||||||
Convert integer literal to hex representation.
|
Convert integer literal to hex representation.
|
||||||
@@ -1514,10 +1518,7 @@ void ConvertNumericLiteral::match(const CppQuickFixInterface &interface, QuickFi
|
|||||||
result << op;
|
result << op;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value != 0) {
|
if (!isOctal) {
|
||||||
if (!(numberLength > 1 && str[0] == '0'
|
|
||||||
&& str[1] != 'x' && str[1] != 'X'
|
|
||||||
&& str[1] != 'b' && str[1] != 'B')) {
|
|
||||||
/*
|
/*
|
||||||
Convert integer literal to octal representation.
|
Convert integer literal to octal representation.
|
||||||
Replace
|
Replace
|
||||||
@@ -1534,10 +1535,8 @@ void ConvertNumericLiteral::match(const CppQuickFixInterface &interface, QuickFi
|
|||||||
op->setPriority(priority);
|
op->setPriority(priority);
|
||||||
result << op;
|
result << op;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (value != 0 || numeric->isHex()) {
|
if (!isDecimal) {
|
||||||
if (!(numberLength > 1 && str[0] != '0')) {
|
|
||||||
/*
|
/*
|
||||||
Convert integer literal to decimal representation.
|
Convert integer literal to decimal representation.
|
||||||
Replace
|
Replace
|
||||||
@@ -1554,9 +1553,8 @@ void ConvertNumericLiteral::match(const CppQuickFixInterface &interface, QuickFi
|
|||||||
op->setPriority(priority);
|
op->setPriority(priority);
|
||||||
result << op;
|
result << op;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!(numberLength > 1 && str[0] == '0' && (str[1] == 'b' || str[1] == 'B'))) {
|
if (!isBinary) {
|
||||||
/*
|
/*
|
||||||
Convert integer literal to binary representation.
|
Convert integer literal to binary representation.
|
||||||
Replace
|
Replace
|
||||||
|
|||||||
Reference in New Issue
Block a user