Perfect the patch for astyle
This commit is contained in:
parent
0cc4f09c53
commit
bd52bd9831
1
NEWS.md
1
NEWS.md
|
@ -99,6 +99,7 @@ Red Panda C++ Version 2.27
|
|||
- enhancement: Open ".def" (Module definition file) file in editor when double click it in the project view.
|
||||
- enhancement: When a dll project has .def file, use it when generating the dll file.
|
||||
- fix: "project name".exe.manifest is auto removed when build the project.
|
||||
- fix: "0x3.12p+1" is treadted as a plus expression when reformatting code ( by 绣球135@qq )
|
||||
|
||||
Red Panda C++ Version 2.26
|
||||
- enhancement: Code suggestion for embedded std::vectors.
|
||||
|
|
|
@ -3590,75 +3590,70 @@ bool ASFormatter::isInSwitchStatement() const
|
|||
*
|
||||
* @return whether the current '+' or '-' is in an exponent.
|
||||
*/
|
||||
bool ASFormatter::isInExponent() const {
|
||||
bool ASFormatter::isInExponent() const
|
||||
{
|
||||
assert (currentChar == '+' || currentChar == '-');
|
||||
|
||||
if (charNum >= 2) {
|
||||
char prevPrevFormattedChar = currentLine[charNum - 2];
|
||||
char prevFormattedChar = currentLine[charNum - 1];
|
||||
//XQ135 modify// return ((prevFormattedChar == 'e' || prevFormattedChar == 'E')
|
||||
//XQ135 modify// && (prevPrevFormattedChar == '.' || isDigit(prevPrevFormattedChar)));
|
||||
char qian1 = prevFormattedChar; //XQ135 modify// Start
|
||||
char qian2 = prevPrevFormattedChar; //XQ135 modify//
|
||||
if (charNum < 2)
|
||||
return false;
|
||||
|
||||
bool isexp = false;
|
||||
int i = 2;
|
||||
if (qian1 == 'e' || qian1 == 'E') {
|
||||
while ((charNum - i) >= 0) {
|
||||
qian2 = currentLine[charNum - i];
|
||||
if (qian2 == '.' || isDigit (qian2)) {
|
||||
isexp = true;
|
||||
int i = charNum - 1;
|
||||
char prevChar = currentLine[i];
|
||||
|
||||
if (prevChar == 'e' || prevChar == 'E') {
|
||||
i--;
|
||||
bool hasPoint = false;
|
||||
int numCount = 0;
|
||||
while (i >= 0) {
|
||||
prevChar = currentLine[i];
|
||||
if (prevChar == '.') {
|
||||
if (hasPoint)
|
||||
return false;
|
||||
hasPoint = true;
|
||||
} else if (isDigit(prevChar)) {
|
||||
numCount++;
|
||||
} else {
|
||||
if (! (qian2 == ' ' || qian2 == '&' || qian2 == '|' || qian2 == '='
|
||||
|| qian2 == 7 || qian2 == 10 || qian2 == 13 || qian2 == '~'
|
||||
|| qian2 == '+' || qian2 == '-' || qian2 == '*' || qian2 == '/'
|
||||
|| qian2 == '(' || qian2 == ')' || qian2 == '[' || qian2 == ']'
|
||||
|| qian2 == '{' || qian2 == '}' || qian2 == ',' || qian2 == ':'
|
||||
|| qian2 == ';' || qian2 == '.' || qian2 == '#' || qian2 == '<'
|
||||
|| qian2 == '>' || qian2 == '^' || qian2 == '%' || qian2 == '!' )) {
|
||||
isexp = false;
|
||||
}
|
||||
if (isLetterOrUnderLine(prevChar) || prevChar == '$')
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
i--;
|
||||
}
|
||||
return numCount > 0;
|
||||
}
|
||||
if (isexp) {return true;}
|
||||
|
||||
if (! (qian1 == 'p' || qian1 == 'P')) {return false;}
|
||||
i = 2;
|
||||
while ((charNum - i) >= 0) {
|
||||
qian2 = currentLine[charNum - i];
|
||||
if (qian2 == '.' || isDigit (qian2) || qian2 == 'x' || qian2 == 'X'
|
||||
|| (qian2 >= 'a' && qian2 <= 'f') || (qian2 >= 'A' && qian2 <= 'F')) {
|
||||
if (qian2 == 'x' || qian2 == 'X') {
|
||||
if ((charNum - i - 1) >= 0) {
|
||||
if (currentLine[charNum - i - 1] == '0') {
|
||||
if ((charNum - i - 2) >= 0) {
|
||||
qian2 = currentLine[charNum - i - 2];
|
||||
if (qian2 == ' ' || qian2 == '&' || qian2 == '|' || qian2 == '='
|
||||
|| qian2 == 7 || qian2 == 10 || qian2 == 13 || qian2 == '~'
|
||||
|| qian2 == '+' || qian2 == '-' || qian2 == '*' || qian2 == '/'
|
||||
|| qian2 == '(' || qian2 == ')' || qian2 == '[' || qian2 == ']'
|
||||
|| qian2 == '{' || qian2 == '}' || qian2 == ',' || qian2 == ':'
|
||||
|| qian2 == ';' || qian2 == '.' || qian2 == '#' || qian2 == '<'
|
||||
|| qian2 == '>' || qian2 == '^' || qian2 == '%' || qian2 == '!') {
|
||||
return true;
|
||||
if (prevChar == 'p' || prevChar == 'P') {
|
||||
i--;
|
||||
bool hasPoint = false;
|
||||
bool hasX = false;
|
||||
int numCount = 0;
|
||||
while (i >= 0) {
|
||||
prevChar = currentLine[i];
|
||||
if (isHexDigit(prevChar)) {
|
||||
if (hasX)
|
||||
return false;
|
||||
numCount++ ;
|
||||
} else if (prevChar == '.') {
|
||||
if (hasPoint || hasX)
|
||||
return false;
|
||||
hasPoint = true;
|
||||
} else if ( prevChar == 'x' || prevChar =='X') {
|
||||
if (hasX)
|
||||
return false;
|
||||
i--;
|
||||
if (i<0)
|
||||
return false;
|
||||
if (currentLine[i]!='0')
|
||||
return false;
|
||||
hasX = true;
|
||||
} else {
|
||||
if (isLetterOrUnderLine(prevChar) || prevChar == '$')
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
i++; //XQ135 modify// Floating-point number supporting hexadecimal representation
|
||||
} //XQ135 modify// End 2024.3.24
|
||||
i--; //XQ135 modify// Floating-point number supporting hexadecimal representation
|
||||
}
|
||||
return hasX && numCount > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -764,6 +764,20 @@ bool ASBase::isDigit(char ch) const
|
|||
return (ch >= '0' && ch <= '9');
|
||||
}
|
||||
|
||||
bool ASBase::isHexDigit(char ch) const
|
||||
{
|
||||
return (ch >= '0' && ch <= '9')
|
||||
|| (ch >= 'a' && ch <= 'f')
|
||||
|| (ch >= 'A' && ch <= 'F');
|
||||
}
|
||||
|
||||
bool ASBase::isLetterOrUnderLine(char ch) const
|
||||
{ return (ch >= 'a' && ch <= 'z')
|
||||
|| (ch >= 'A' && ch <= 'Z')
|
||||
|| (ch == '_');
|
||||
|
||||
}
|
||||
|
||||
// check if a specific character is a digit separator
|
||||
bool ASBase::isDigitSeparator(const string& line, int i) const
|
||||
{
|
||||
|
|
|
@ -318,6 +318,8 @@ protected: // functions definitions are at the end of ASResource.cpp
|
|||
const vector<const string*>* possibleOperators) const;
|
||||
string getCurrentWord(const string& line, size_t index) const;
|
||||
bool isDigit(char ch) const;
|
||||
bool isHexDigit(char ch) const;
|
||||
bool isLetterOrUnderLine(char ch) const;
|
||||
bool isLegalNameChar(char ch) const;
|
||||
bool isCharPotentialHeader(const string& line, size_t i) const;
|
||||
bool isCharPotentialOperator(char ch) const;
|
||||
|
|
Loading…
Reference in New Issue