Skip to content

Commit 93c8679

Browse files
committed
Update version 0.2.9
Update AStyle to 3.4
1 parent 070c21b commit 93c8679

19 files changed

+3807
-3240
lines changed

AStyleLib/ASBeautifier.cpp

Lines changed: 995 additions & 816 deletions
Large diffs are not rendered by default.

AStyleLib/ASEnhancer.cpp

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

@@ -19,20 +19,6 @@ namespace astyle {
1919
// ASEnhancer class
2020
//-----------------------------------------------------------------------------
2121

22-
/**
23-
* ASEnhancer constructor
24-
*/
25-
ASEnhancer::ASEnhancer()
26-
{
27-
}
28-
29-
/**
30-
* Destructor of ASEnhancer
31-
*/
32-
ASEnhancer::~ASEnhancer()
33-
{
34-
}
35-
3622
/**
3723
* initialize the ASEnhancer.
3824
*
@@ -48,7 +34,7 @@ void ASEnhancer::init(int _fileType,
4834
bool _preprocBlockIndent,
4935
bool _preprocDefineIndent,
5036
bool _emptyLineFill,
51-
vector<const pair<const string, const string>* >* _indentableMacros)
37+
std::vector<const std::pair<const std::string, const std::string>* >* _indentableMacros)
5238
{
5339
// formatting variables from ASFormatter and ASBeautifier
5440
ASBase::init(_fileType);
@@ -98,7 +84,7 @@ void ASEnhancer::init(int _fileType,
9884
*
9985
* @param line the original formatted line will be updated if necessary.
10086
*/
101-
void ASEnhancer::enhance(string& line, bool isInNamespace, bool isInPreprocessor, bool isInSQL)
87+
void ASEnhancer::enhance(std::string& line, bool isInNamespace, bool isInPreprocessor, bool isInSQL)
10288
{
10389
shouldUnindentLine = true;
10490
shouldUnindentComment = false;
@@ -139,7 +125,7 @@ void ASEnhancer::enhance(string& line, bool isInNamespace, bool isInPreprocessor
139125
if (isInDeclareSection)
140126
{
141127
size_t firstText = line.find_first_not_of(" \t");
142-
if (firstText == string::npos || line[firstText] != '#')
128+
if (firstText == std::string::npos || line[firstText] != '#')
143129
indentLine(line, 1);
144130
}
145131

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

@@ -164,7 +150,7 @@ void ASEnhancer::enhance(string& line, bool isInNamespace, bool isInPreprocessor
164150
*
165151
* @param line a reference to the line that will be converted.
166152
*/
167-
void ASEnhancer::convertForceTabIndentToSpaces(string& line) const
153+
void ASEnhancer::convertForceTabIndentToSpaces(std::string& line) const
168154
{
169155
// replace tab indents with spaces
170156
for (size_t i = 0; i < line.length(); i++)
@@ -185,7 +171,7 @@ void ASEnhancer::convertForceTabIndentToSpaces(string& line) const
185171
*
186172
* @param line a reference to the line that will be converted.
187173
*/
188-
void ASEnhancer::convertSpaceIndentToForceTab(string& line) const
174+
void ASEnhancer::convertSpaceIndentToForceTab(std::string& line) const
189175
{
190176
assert(tabLength > 0);
191177

@@ -202,7 +188,7 @@ void ASEnhancer::convertSpaceIndentToForceTab(string& line) const
202188
* @param caseIndex the line index of the case statement.
203189
* @return the line index of the colon.
204190
*/
205-
size_t ASEnhancer::findCaseColon(const string& line, size_t caseIndex) const
191+
size_t ASEnhancer::findCaseColon(const std::string& line, size_t caseIndex) const
206192
{
207193
size_t i = caseIndex;
208194
bool isInQuote_ = false;
@@ -216,16 +202,13 @@ size_t ASEnhancer::findCaseColon(const string& line, size_t caseIndex) const
216202
i++;
217203
continue;
218204
}
219-
else if (line[i] == quoteChar_) // check ending quote
205+
if (line[i] == quoteChar_) // check ending quote
220206
{
221207
isInQuote_ = false;
222208
quoteChar_ = ' ';
223209
continue;
224210
}
225-
else
226-
{
227-
continue; // must close quote before continuing
228-
}
211+
continue; // must close quote before continuing
229212
}
230213
if (line[i] == '"' // check opening quote
231214
|| (line[i] == '\'' && !isDigitSeparator(line, i)))
@@ -253,7 +236,7 @@ size_t ASEnhancer::findCaseColon(const string& line, size_t caseIndex) const
253236
* @param indent the number of tabsets to insert.
254237
* @return the number of characters inserted.
255238
*/
256-
int ASEnhancer::indentLine(string& line, int indent) const
239+
int ASEnhancer::indentLine(std::string& line, int indent) const
257240
{
258241
if (line.length() == 0
259242
&& !emptyLineFill)
@@ -293,23 +276,23 @@ int ASEnhancer::indentLine(string& line, int indent) const
293276
* @param index the current line index.
294277
* @return true if a hit.
295278
*/
296-
bool ASEnhancer::isBeginDeclareSectionSQL(const string& line, size_t index) const
279+
bool ASEnhancer::isBeginDeclareSectionSQL(const std::string& line, size_t index) const
297280
{
298-
string word;
281+
std::string word;
299282
size_t hits = 0;
300283
size_t i;
301284
for (i = index; i < line.length(); i++)
302285
{
303286
i = line.find_first_not_of(" \t", i);
304-
if (i == string::npos)
287+
if (i == std::string::npos)
305288
return false;
306289
if (line[i] == ';')
307290
break;
308291
if (!isCharPotentialHeader(line, i))
309292
continue;
310293
word = getCurrentWord(line, i);
311-
for (size_t j = 0; j < word.length(); j++)
312-
word[j] = (char) toupper(word[j]);
294+
for (char& character : word)
295+
character = (char) toupper(character);
313296
if (word == "EXEC" || word == "SQL")
314297
{
315298
i += word.length() - 1;
@@ -342,23 +325,23 @@ bool ASEnhancer::isBeginDeclareSectionSQL(const string& line, size_t index) cons
342325
* @param index the current line index.
343326
* @return true if a hit.
344327
*/
345-
bool ASEnhancer::isEndDeclareSectionSQL(const string& line, size_t index) const
328+
bool ASEnhancer::isEndDeclareSectionSQL(const std::string& line, size_t index) const
346329
{
347-
string word;
330+
std::string word;
348331
size_t hits = 0;
349332
size_t i;
350333
for (i = index; i < line.length(); i++)
351334
{
352335
i = line.find_first_not_of(" \t", i);
353-
if (i == string::npos)
336+
if (i == std::string::npos)
354337
return false;
355338
if (line[i] == ';')
356339
break;
357340
if (!isCharPotentialHeader(line, i))
358341
continue;
359342
word = getCurrentWord(line, i);
360-
for (size_t j = 0; j < word.length(); j++)
361-
word[j] = (char) toupper(word[j]);
343+
for (char& character : word)
344+
character = (char) toupper(character);
362345
if (word == "EXEC" || word == "SQL")
363346
{
364347
i += word.length() - 1;
@@ -391,7 +374,7 @@ bool ASEnhancer::isEndDeclareSectionSQL(const string& line, size_t index) const
391374
* @return false = one-line brace has not been reached.
392375
* true = one-line brace has been reached.
393376
*/
394-
bool ASEnhancer::isOneLineBlockReached(const string& line, int startChar) const
377+
bool ASEnhancer::isOneLineBlockReached(const std::string& line, int startChar) const
395378
{
396379
assert(line[startChar] == '{');
397380

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

@@ -526,20 +509,20 @@ void ASEnhancer::parseCurrentLine(string& line, bool isInPreprocessor, bool isIn
526509
shouldUnindentComment = true;
527510
break; // finished with the line
528511
}
529-
else if (!(isInComment) && line.compare(i, 2, "/*") == 0)
512+
if (!(isInComment) && line.compare(i, 2, "/*") == 0)
530513
{
531514
// unindent if not in case braces
532515
if (sw.switchBraceCount == 1 && sw.unindentCase)
533516
shouldUnindentComment = true;
534517
isInComment = true;
535518
size_t commentEnd = line.find("*/", i);
536-
if (commentEnd == string::npos)
519+
if (commentEnd == std::string::npos)
537520
i = line.length() - 1;
538521
else
539522
i = commentEnd - 1;
540523
continue;
541524
}
542-
else if ((isInComment) && line.compare(i, 2, "*/") == 0)
525+
if ((isInComment) && line.compare(i, 2, "*/") == 0)
543526
{
544527
// unindent if not in case braces
545528
if (sw.switchBraceCount == 1 && sw.unindentCase)
@@ -548,14 +531,13 @@ void ASEnhancer::parseCurrentLine(string& line, bool isInPreprocessor, bool isIn
548531
i++;
549532
continue;
550533
}
551-
552534
if (isInComment)
553535
{
554536
// unindent if not in case braces
555537
if (sw.switchBraceCount == 1 && sw.unindentCase)
556538
shouldUnindentComment = true;
557539
size_t commentEnd = line.find("*/", i);
558-
if (commentEnd == string::npos)
540+
if (commentEnd == std::string::npos)
559541
i = line.length() - 1;
560542
else
561543
i = commentEnd - 1;
@@ -573,7 +555,7 @@ void ASEnhancer::parseCurrentLine(string& line, bool isInPreprocessor, bool isIn
573555
// check for preprocessor within an event table
574556
if (isInEventTable && line[i] == '#' && preprocBlockIndent)
575557
{
576-
string preproc;
558+
std::string preproc;
577559
preproc = line.substr(i + 1);
578560
if (preproc.substr(0, 2) == "if") // #if, #ifdef, #ifndef)
579561
eventPreprocDepth += 1;
@@ -587,19 +569,16 @@ void ASEnhancer::parseCurrentLine(string& line, bool isInPreprocessor, bool isIn
587569

588570
if (isPotentialKeyword)
589571
{
590-
for (size_t j = 0; j < indentableMacros->size(); j++)
572+
for (const auto* indentableMacro : *indentableMacros)
591573
{
592574
// 'first' is the beginning macro
593-
if (findKeyword(line, i, indentableMacros->at(j)->first))
575+
if (findKeyword(line, i, indentableMacro->first))
594576
{
595577
nextLineIsEventIndent = true;
596578
break;
597579
}
598-
}
599-
for (size_t j = 0; j < indentableMacros->size(); j++)
600-
{
601580
// 'second' is the ending macro
602-
if (findKeyword(line, i, indentableMacros->at(j)->second))
581+
if (findKeyword(line, i, indentableMacro->second))
603582
{
604583
isInEventTable = false;
605584
eventPreprocDepth = 0;
@@ -640,7 +619,7 @@ void ASEnhancer::parseCurrentLine(string& line, bool isInPreprocessor, bool isIn
640619
// bypass the entire word
641620
if (isPotentialKeyword)
642621
{
643-
string name = getCurrentWord(line, i);
622+
std::string name = getCurrentWord(line, i);
644623
i += name.length() - 1;
645624
}
646625
continue;
@@ -658,7 +637,7 @@ void ASEnhancer::parseCurrentLine(string& line, bool isInPreprocessor, bool isIn
658637
* @param index the current line index.
659638
* @return the new line index.
660639
*/
661-
size_t ASEnhancer::processSwitchBlock(string& line, size_t index)
640+
size_t ASEnhancer::processSwitchBlock(std::string& line, size_t index)
662641
{
663642
size_t i = index;
664643
bool isPotentialKeyword = isCharPotentialHeader(line, i);
@@ -733,7 +712,7 @@ size_t ASEnhancer::processSwitchBlock(string& line, size_t index)
733712
}
734713
if (isPotentialKeyword)
735714
{
736-
string name = getCurrentWord(line, i); // bypass the entire name
715+
std::string name = getCurrentWord(line, i); // bypass the entire name
737716
i += name.length() - 1;
738717
}
739718
return i;
@@ -747,11 +726,11 @@ size_t ASEnhancer::processSwitchBlock(string& line, size_t index)
747726
* @param unindent the number of tabsets to erase.
748727
* @return the number of characters erased.
749728
*/
750-
int ASEnhancer::unindentLine(string& line, int unindent) const
729+
int ASEnhancer::unindentLine(std::string& line, int unindent) const
751730
{
752731
size_t whitespace = line.find_first_not_of(" \t");
753732

754-
if (whitespace == string::npos) // if line is blank
733+
if (whitespace == std::string::npos) // if line is blank
755734
whitespace = line.length(); // must remove padding, if any
756735

757736
if (whitespace == 0)

0 commit comments

Comments
 (0)