Skip to content

Commit

Permalink
Update version 0.2.9
Browse files Browse the repository at this point in the history
Update AStyle to 3.4
  • Loading branch information
ywx committed Dec 20, 2023
1 parent 070c21b commit 93c8679
Show file tree
Hide file tree
Showing 19 changed files with 3,807 additions and 3,240 deletions.
1,811 changes: 995 additions & 816 deletions AStyleLib/ASBeautifier.cpp

Large diffs are not rendered by default.

93 changes: 36 additions & 57 deletions AStyleLib/ASEnhancer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ASEnhancer.cpp
// Copyright (c) 2018 by Jim Pattee <[email protected]>.
// Copyright (c) 2023 The Artistic Style Authors.
// This code is licensed under the MIT License.
// License.md describes the conditions under which this software may be distributed.

Expand All @@ -19,20 +19,6 @@ namespace astyle {
// ASEnhancer class
//-----------------------------------------------------------------------------

/**
* ASEnhancer constructor
*/
ASEnhancer::ASEnhancer()
{
}

/**
* Destructor of ASEnhancer
*/
ASEnhancer::~ASEnhancer()
{
}

/**
* initialize the ASEnhancer.
*
Expand All @@ -48,7 +34,7 @@ void ASEnhancer::init(int _fileType,
bool _preprocBlockIndent,
bool _preprocDefineIndent,
bool _emptyLineFill,
vector<const pair<const string, const string>* >* _indentableMacros)
std::vector<const std::pair<const std::string, const std::string>* >* _indentableMacros)
{
// formatting variables from ASFormatter and ASBeautifier
ASBase::init(_fileType);
Expand Down Expand Up @@ -98,7 +84,7 @@ void ASEnhancer::init(int _fileType,
*
* @param line the original formatted line will be updated if necessary.
*/
void ASEnhancer::enhance(string& line, bool isInNamespace, bool isInPreprocessor, bool isInSQL)
void ASEnhancer::enhance(std::string& line, bool isInNamespace, bool isInPreprocessor, bool isInSQL)
{
shouldUnindentLine = true;
shouldUnindentComment = false;
Expand Down Expand Up @@ -139,7 +125,7 @@ void ASEnhancer::enhance(string& line, bool isInNamespace, bool isInPreprocessor
if (isInDeclareSection)
{
size_t firstText = line.find_first_not_of(" \t");
if (firstText == string::npos || line[firstText] != '#')
if (firstText == std::string::npos || line[firstText] != '#')
indentLine(line, 1);
}

Expand All @@ -149,7 +135,7 @@ void ASEnhancer::enhance(string& line, bool isInNamespace, bool isInPreprocessor
|| (namespaceIndent && isInNamespace)))
{
size_t firstText = line.find_first_not_of(" \t");
if (firstText == string::npos || line[firstText] != '#')
if (firstText == std::string::npos || line[firstText] != '#')
indentLine(line, 1);
}

Expand All @@ -164,7 +150,7 @@ void ASEnhancer::enhance(string& line, bool isInNamespace, bool isInPreprocessor
*
* @param line a reference to the line that will be converted.
*/
void ASEnhancer::convertForceTabIndentToSpaces(string& line) const
void ASEnhancer::convertForceTabIndentToSpaces(std::string& line) const
{
// replace tab indents with spaces
for (size_t i = 0; i < line.length(); i++)
Expand All @@ -185,7 +171,7 @@ void ASEnhancer::convertForceTabIndentToSpaces(string& line) const
*
* @param line a reference to the line that will be converted.
*/
void ASEnhancer::convertSpaceIndentToForceTab(string& line) const
void ASEnhancer::convertSpaceIndentToForceTab(std::string& line) const
{
assert(tabLength > 0);

Expand All @@ -202,7 +188,7 @@ void ASEnhancer::convertSpaceIndentToForceTab(string& line) const
* @param caseIndex the line index of the case statement.
* @return the line index of the colon.
*/
size_t ASEnhancer::findCaseColon(const string& line, size_t caseIndex) const
size_t ASEnhancer::findCaseColon(const std::string& line, size_t caseIndex) const
{
size_t i = caseIndex;
bool isInQuote_ = false;
Expand All @@ -216,16 +202,13 @@ size_t ASEnhancer::findCaseColon(const string& line, size_t caseIndex) const
i++;
continue;
}
else if (line[i] == quoteChar_) // check ending quote
if (line[i] == quoteChar_) // check ending quote
{
isInQuote_ = false;
quoteChar_ = ' ';
continue;
}
else
{
continue; // must close quote before continuing
}
continue; // must close quote before continuing
}
if (line[i] == '"' // check opening quote
|| (line[i] == '\'' && !isDigitSeparator(line, i)))
Expand Down Expand Up @@ -253,7 +236,7 @@ size_t ASEnhancer::findCaseColon(const string& line, size_t caseIndex) const
* @param indent the number of tabsets to insert.
* @return the number of characters inserted.
*/
int ASEnhancer::indentLine(string& line, int indent) const
int ASEnhancer::indentLine(std::string& line, int indent) const
{
if (line.length() == 0
&& !emptyLineFill)
Expand Down Expand Up @@ -293,23 +276,23 @@ int ASEnhancer::indentLine(string& line, int indent) const
* @param index the current line index.
* @return true if a hit.
*/
bool ASEnhancer::isBeginDeclareSectionSQL(const string& line, size_t index) const
bool ASEnhancer::isBeginDeclareSectionSQL(const std::string& line, size_t index) const
{
string word;
std::string word;
size_t hits = 0;
size_t i;
for (i = index; i < line.length(); i++)
{
i = line.find_first_not_of(" \t", i);
if (i == string::npos)
if (i == std::string::npos)
return false;
if (line[i] == ';')
break;
if (!isCharPotentialHeader(line, i))
continue;
word = getCurrentWord(line, i);
for (size_t j = 0; j < word.length(); j++)
word[j] = (char) toupper(word[j]);
for (char& character : word)
character = (char) toupper(character);
if (word == "EXEC" || word == "SQL")
{
i += word.length() - 1;
Expand Down Expand Up @@ -342,23 +325,23 @@ bool ASEnhancer::isBeginDeclareSectionSQL(const string& line, size_t index) cons
* @param index the current line index.
* @return true if a hit.
*/
bool ASEnhancer::isEndDeclareSectionSQL(const string& line, size_t index) const
bool ASEnhancer::isEndDeclareSectionSQL(const std::string& line, size_t index) const
{
string word;
std::string word;
size_t hits = 0;
size_t i;
for (i = index; i < line.length(); i++)
{
i = line.find_first_not_of(" \t", i);
if (i == string::npos)
if (i == std::string::npos)
return false;
if (line[i] == ';')
break;
if (!isCharPotentialHeader(line, i))
continue;
word = getCurrentWord(line, i);
for (size_t j = 0; j < word.length(); j++)
word[j] = (char) toupper(word[j]);
for (char& character : word)
character = (char) toupper(character);
if (word == "EXEC" || word == "SQL")
{
i += word.length() - 1;
Expand Down Expand Up @@ -391,7 +374,7 @@ bool ASEnhancer::isEndDeclareSectionSQL(const string& line, size_t index) const
* @return false = one-line brace has not been reached.
* true = one-line brace has been reached.
*/
bool ASEnhancer::isOneLineBlockReached(const string& line, int startChar) const
bool ASEnhancer::isOneLineBlockReached(const std::string& line, int startChar) const
{
assert(line[startChar] == '{');

Expand Down Expand Up @@ -463,7 +446,7 @@ bool ASEnhancer::isOneLineBlockReached(const string& line, int startChar) const
* parse characters in the current line to determine if an indent
* or unindent is needed.
*/
void ASEnhancer::parseCurrentLine(string& line, bool isInPreprocessor, bool isInSQL)
void ASEnhancer::parseCurrentLine(std::string& line, bool isInPreprocessor, bool isInSQL)
{
bool isSpecialChar = false; // is a backslash escape character

Expand Down Expand Up @@ -526,20 +509,20 @@ void ASEnhancer::parseCurrentLine(string& line, bool isInPreprocessor, bool isIn
shouldUnindentComment = true;
break; // finished with the line
}
else if (!(isInComment) && line.compare(i, 2, "/*") == 0)
if (!(isInComment) && line.compare(i, 2, "/*") == 0)
{
// unindent if not in case braces
if (sw.switchBraceCount == 1 && sw.unindentCase)
shouldUnindentComment = true;
isInComment = true;
size_t commentEnd = line.find("*/", i);
if (commentEnd == string::npos)
if (commentEnd == std::string::npos)
i = line.length() - 1;
else
i = commentEnd - 1;
continue;
}
else if ((isInComment) && line.compare(i, 2, "*/") == 0)
if ((isInComment) && line.compare(i, 2, "*/") == 0)
{
// unindent if not in case braces
if (sw.switchBraceCount == 1 && sw.unindentCase)
Expand All @@ -548,14 +531,13 @@ void ASEnhancer::parseCurrentLine(string& line, bool isInPreprocessor, bool isIn
i++;
continue;
}

if (isInComment)
{
// unindent if not in case braces
if (sw.switchBraceCount == 1 && sw.unindentCase)
shouldUnindentComment = true;
size_t commentEnd = line.find("*/", i);
if (commentEnd == string::npos)
if (commentEnd == std::string::npos)
i = line.length() - 1;
else
i = commentEnd - 1;
Expand All @@ -573,7 +555,7 @@ void ASEnhancer::parseCurrentLine(string& line, bool isInPreprocessor, bool isIn
// check for preprocessor within an event table
if (isInEventTable && line[i] == '#' && preprocBlockIndent)
{
string preproc;
std::string preproc;
preproc = line.substr(i + 1);
if (preproc.substr(0, 2) == "if") // #if, #ifdef, #ifndef)
eventPreprocDepth += 1;
Expand All @@ -587,19 +569,16 @@ void ASEnhancer::parseCurrentLine(string& line, bool isInPreprocessor, bool isIn

if (isPotentialKeyword)
{
for (size_t j = 0; j < indentableMacros->size(); j++)
for (const auto* indentableMacro : *indentableMacros)
{
// 'first' is the beginning macro
if (findKeyword(line, i, indentableMacros->at(j)->first))
if (findKeyword(line, i, indentableMacro->first))
{
nextLineIsEventIndent = true;
break;
}
}
for (size_t j = 0; j < indentableMacros->size(); j++)
{
// 'second' is the ending macro
if (findKeyword(line, i, indentableMacros->at(j)->second))
if (findKeyword(line, i, indentableMacro->second))
{
isInEventTable = false;
eventPreprocDepth = 0;
Expand Down Expand Up @@ -640,7 +619,7 @@ void ASEnhancer::parseCurrentLine(string& line, bool isInPreprocessor, bool isIn
// bypass the entire word
if (isPotentialKeyword)
{
string name = getCurrentWord(line, i);
std::string name = getCurrentWord(line, i);
i += name.length() - 1;
}
continue;
Expand All @@ -658,7 +637,7 @@ void ASEnhancer::parseCurrentLine(string& line, bool isInPreprocessor, bool isIn
* @param index the current line index.
* @return the new line index.
*/
size_t ASEnhancer::processSwitchBlock(string& line, size_t index)
size_t ASEnhancer::processSwitchBlock(std::string& line, size_t index)
{
size_t i = index;
bool isPotentialKeyword = isCharPotentialHeader(line, i);
Expand Down Expand Up @@ -733,7 +712,7 @@ size_t ASEnhancer::processSwitchBlock(string& line, size_t index)
}
if (isPotentialKeyword)
{
string name = getCurrentWord(line, i); // bypass the entire name
std::string name = getCurrentWord(line, i); // bypass the entire name
i += name.length() - 1;
}
return i;
Expand All @@ -747,11 +726,11 @@ size_t ASEnhancer::processSwitchBlock(string& line, size_t index)
* @param unindent the number of tabsets to erase.
* @return the number of characters erased.
*/
int ASEnhancer::unindentLine(string& line, int unindent) const
int ASEnhancer::unindentLine(std::string& line, int unindent) const
{
size_t whitespace = line.find_first_not_of(" \t");

if (whitespace == string::npos) // if line is blank
if (whitespace == std::string::npos) // if line is blank
whitespace = line.length(); // must remove padding, if any

if (whitespace == 0)
Expand Down
Loading

0 comments on commit 93c8679

Please sign in to comment.