1
1
// ASEnhancer.cpp
2
- // Copyright (c) 2018 by Jim Pattee <[email protected] > .
2
+ // Copyright (c) 2023 The Artistic Style Authors .
3
3
// This code is licensed under the MIT License.
4
4
// License.md describes the conditions under which this software may be distributed.
5
5
@@ -19,20 +19,6 @@ namespace astyle {
19
19
// ASEnhancer class
20
20
// -----------------------------------------------------------------------------
21
21
22
- /* *
23
- * ASEnhancer constructor
24
- */
25
- ASEnhancer::ASEnhancer ()
26
- {
27
- }
28
-
29
- /* *
30
- * Destructor of ASEnhancer
31
- */
32
- ASEnhancer::~ASEnhancer ()
33
- {
34
- }
35
-
36
22
/* *
37
23
* initialize the ASEnhancer.
38
24
*
@@ -48,7 +34,7 @@ void ASEnhancer::init(int _fileType,
48
34
bool _preprocBlockIndent,
49
35
bool _preprocDefineIndent,
50
36
bool _emptyLineFill,
51
- vector<const pair<const string, const string>* >* _indentableMacros)
37
+ std:: vector<const std:: pair<const std:: string, const std:: string>* >* _indentableMacros)
52
38
{
53
39
// formatting variables from ASFormatter and ASBeautifier
54
40
ASBase::init (_fileType);
@@ -98,7 +84,7 @@ void ASEnhancer::init(int _fileType,
98
84
*
99
85
* @param line the original formatted line will be updated if necessary.
100
86
*/
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)
102
88
{
103
89
shouldUnindentLine = true ;
104
90
shouldUnindentComment = false ;
@@ -139,7 +125,7 @@ void ASEnhancer::enhance(string& line, bool isInNamespace, bool isInPreprocessor
139
125
if (isInDeclareSection)
140
126
{
141
127
size_t firstText = line.find_first_not_of (" \t " );
142
- if (firstText == string::npos || line[firstText] != ' #' )
128
+ if (firstText == std:: string::npos || line[firstText] != ' #' )
143
129
indentLine (line, 1 );
144
130
}
145
131
@@ -149,7 +135,7 @@ void ASEnhancer::enhance(string& line, bool isInNamespace, bool isInPreprocessor
149
135
|| (namespaceIndent && isInNamespace)))
150
136
{
151
137
size_t firstText = line.find_first_not_of (" \t " );
152
- if (firstText == string::npos || line[firstText] != ' #' )
138
+ if (firstText == std:: string::npos || line[firstText] != ' #' )
153
139
indentLine (line, 1 );
154
140
}
155
141
@@ -164,7 +150,7 @@ void ASEnhancer::enhance(string& line, bool isInNamespace, bool isInPreprocessor
164
150
*
165
151
* @param line a reference to the line that will be converted.
166
152
*/
167
- void ASEnhancer::convertForceTabIndentToSpaces (string& line) const
153
+ void ASEnhancer::convertForceTabIndentToSpaces (std:: string& line) const
168
154
{
169
155
// replace tab indents with spaces
170
156
for (size_t i = 0 ; i < line.length (); i++)
@@ -185,7 +171,7 @@ void ASEnhancer::convertForceTabIndentToSpaces(string& line) const
185
171
*
186
172
* @param line a reference to the line that will be converted.
187
173
*/
188
- void ASEnhancer::convertSpaceIndentToForceTab (string& line) const
174
+ void ASEnhancer::convertSpaceIndentToForceTab (std:: string& line) const
189
175
{
190
176
assert (tabLength > 0 );
191
177
@@ -202,7 +188,7 @@ void ASEnhancer::convertSpaceIndentToForceTab(string& line) const
202
188
* @param caseIndex the line index of the case statement.
203
189
* @return the line index of the colon.
204
190
*/
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
206
192
{
207
193
size_t i = caseIndex;
208
194
bool isInQuote_ = false ;
@@ -216,16 +202,13 @@ size_t ASEnhancer::findCaseColon(const string& line, size_t caseIndex) const
216
202
i++;
217
203
continue ;
218
204
}
219
- else if (line[i] == quoteChar_) // check ending quote
205
+ if (line[i] == quoteChar_) // check ending quote
220
206
{
221
207
isInQuote_ = false ;
222
208
quoteChar_ = ' ' ;
223
209
continue ;
224
210
}
225
- else
226
- {
227
- continue ; // must close quote before continuing
228
- }
211
+ continue ; // must close quote before continuing
229
212
}
230
213
if (line[i] == ' "' // check opening quote
231
214
|| (line[i] == ' \' ' && !isDigitSeparator (line, i)))
@@ -253,7 +236,7 @@ size_t ASEnhancer::findCaseColon(const string& line, size_t caseIndex) const
253
236
* @param indent the number of tabsets to insert.
254
237
* @return the number of characters inserted.
255
238
*/
256
- int ASEnhancer::indentLine (string& line, int indent) const
239
+ int ASEnhancer::indentLine (std:: string& line, int indent) const
257
240
{
258
241
if (line.length () == 0
259
242
&& !emptyLineFill)
@@ -293,23 +276,23 @@ int ASEnhancer::indentLine(string& line, int indent) const
293
276
* @param index the current line index.
294
277
* @return true if a hit.
295
278
*/
296
- bool ASEnhancer::isBeginDeclareSectionSQL (const string& line, size_t index) const
279
+ bool ASEnhancer::isBeginDeclareSectionSQL (const std:: string& line, size_t index) const
297
280
{
298
- string word;
281
+ std:: string word;
299
282
size_t hits = 0 ;
300
283
size_t i;
301
284
for (i = index ; i < line.length (); i++)
302
285
{
303
286
i = line.find_first_not_of (" \t " , i);
304
- if (i == string::npos)
287
+ if (i == std:: string::npos)
305
288
return false ;
306
289
if (line[i] == ' ;' )
307
290
break ;
308
291
if (!isCharPotentialHeader (line, i))
309
292
continue ;
310
293
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 );
313
296
if (word == " EXEC" || word == " SQL" )
314
297
{
315
298
i += word.length () - 1 ;
@@ -342,23 +325,23 @@ bool ASEnhancer::isBeginDeclareSectionSQL(const string& line, size_t index) cons
342
325
* @param index the current line index.
343
326
* @return true if a hit.
344
327
*/
345
- bool ASEnhancer::isEndDeclareSectionSQL (const string& line, size_t index) const
328
+ bool ASEnhancer::isEndDeclareSectionSQL (const std:: string& line, size_t index) const
346
329
{
347
- string word;
330
+ std:: string word;
348
331
size_t hits = 0 ;
349
332
size_t i;
350
333
for (i = index ; i < line.length (); i++)
351
334
{
352
335
i = line.find_first_not_of (" \t " , i);
353
- if (i == string::npos)
336
+ if (i == std:: string::npos)
354
337
return false ;
355
338
if (line[i] == ' ;' )
356
339
break ;
357
340
if (!isCharPotentialHeader (line, i))
358
341
continue ;
359
342
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 );
362
345
if (word == " EXEC" || word == " SQL" )
363
346
{
364
347
i += word.length () - 1 ;
@@ -391,7 +374,7 @@ bool ASEnhancer::isEndDeclareSectionSQL(const string& line, size_t index) const
391
374
* @return false = one-line brace has not been reached.
392
375
* true = one-line brace has been reached.
393
376
*/
394
- bool ASEnhancer::isOneLineBlockReached (const string& line, int startChar) const
377
+ bool ASEnhancer::isOneLineBlockReached (const std:: string& line, int startChar) const
395
378
{
396
379
assert (line[startChar] == ' {' );
397
380
@@ -463,7 +446,7 @@ bool ASEnhancer::isOneLineBlockReached(const string& line, int startChar) const
463
446
* parse characters in the current line to determine if an indent
464
447
* or unindent is needed.
465
448
*/
466
- void ASEnhancer::parseCurrentLine (string& line, bool isInPreprocessor, bool isInSQL)
449
+ void ASEnhancer::parseCurrentLine (std:: string& line, bool isInPreprocessor, bool isInSQL)
467
450
{
468
451
bool isSpecialChar = false ; // is a backslash escape character
469
452
@@ -526,20 +509,20 @@ void ASEnhancer::parseCurrentLine(string& line, bool isInPreprocessor, bool isIn
526
509
shouldUnindentComment = true ;
527
510
break ; // finished with the line
528
511
}
529
- else if (!(isInComment) && line.compare (i, 2 , " /*" ) == 0 )
512
+ if (!(isInComment) && line.compare (i, 2 , " /*" ) == 0 )
530
513
{
531
514
// unindent if not in case braces
532
515
if (sw.switchBraceCount == 1 && sw.unindentCase )
533
516
shouldUnindentComment = true ;
534
517
isInComment = true ;
535
518
size_t commentEnd = line.find (" */" , i);
536
- if (commentEnd == string::npos)
519
+ if (commentEnd == std:: string::npos)
537
520
i = line.length () - 1 ;
538
521
else
539
522
i = commentEnd - 1 ;
540
523
continue ;
541
524
}
542
- else if ((isInComment) && line.compare (i, 2 , " */" ) == 0 )
525
+ if ((isInComment) && line.compare (i, 2 , " */" ) == 0 )
543
526
{
544
527
// unindent if not in case braces
545
528
if (sw.switchBraceCount == 1 && sw.unindentCase )
@@ -548,14 +531,13 @@ void ASEnhancer::parseCurrentLine(string& line, bool isInPreprocessor, bool isIn
548
531
i++;
549
532
continue ;
550
533
}
551
-
552
534
if (isInComment)
553
535
{
554
536
// unindent if not in case braces
555
537
if (sw.switchBraceCount == 1 && sw.unindentCase )
556
538
shouldUnindentComment = true ;
557
539
size_t commentEnd = line.find (" */" , i);
558
- if (commentEnd == string::npos)
540
+ if (commentEnd == std:: string::npos)
559
541
i = line.length () - 1 ;
560
542
else
561
543
i = commentEnd - 1 ;
@@ -573,7 +555,7 @@ void ASEnhancer::parseCurrentLine(string& line, bool isInPreprocessor, bool isIn
573
555
// check for preprocessor within an event table
574
556
if (isInEventTable && line[i] == ' #' && preprocBlockIndent)
575
557
{
576
- string preproc;
558
+ std:: string preproc;
577
559
preproc = line.substr (i + 1 );
578
560
if (preproc.substr (0 , 2 ) == " if" ) // #if, #ifdef, #ifndef)
579
561
eventPreprocDepth += 1 ;
@@ -587,19 +569,16 @@ void ASEnhancer::parseCurrentLine(string& line, bool isInPreprocessor, bool isIn
587
569
588
570
if (isPotentialKeyword)
589
571
{
590
- for (size_t j = 0 ; j < indentableMacros-> size (); j++ )
572
+ for (const auto * indentableMacro : * indentableMacros)
591
573
{
592
574
// 'first' is the beginning macro
593
- if (findKeyword (line, i, indentableMacros-> at (j) ->first ))
575
+ if (findKeyword (line, i, indentableMacro ->first ))
594
576
{
595
577
nextLineIsEventIndent = true ;
596
578
break ;
597
579
}
598
- }
599
- for (size_t j = 0 ; j < indentableMacros->size (); j++)
600
- {
601
580
// 'second' is the ending macro
602
- if (findKeyword (line, i, indentableMacros-> at (j) ->second ))
581
+ if (findKeyword (line, i, indentableMacro ->second ))
603
582
{
604
583
isInEventTable = false ;
605
584
eventPreprocDepth = 0 ;
@@ -640,7 +619,7 @@ void ASEnhancer::parseCurrentLine(string& line, bool isInPreprocessor, bool isIn
640
619
// bypass the entire word
641
620
if (isPotentialKeyword)
642
621
{
643
- string name = getCurrentWord (line, i);
622
+ std:: string name = getCurrentWord (line, i);
644
623
i += name.length () - 1 ;
645
624
}
646
625
continue ;
@@ -658,7 +637,7 @@ void ASEnhancer::parseCurrentLine(string& line, bool isInPreprocessor, bool isIn
658
637
* @param index the current line index.
659
638
* @return the new line index.
660
639
*/
661
- size_t ASEnhancer::processSwitchBlock (string& line, size_t index)
640
+ size_t ASEnhancer::processSwitchBlock (std:: string& line, size_t index)
662
641
{
663
642
size_t i = index ;
664
643
bool isPotentialKeyword = isCharPotentialHeader (line, i);
@@ -733,7 +712,7 @@ size_t ASEnhancer::processSwitchBlock(string& line, size_t index)
733
712
}
734
713
if (isPotentialKeyword)
735
714
{
736
- string name = getCurrentWord (line, i); // bypass the entire name
715
+ std:: string name = getCurrentWord (line, i); // bypass the entire name
737
716
i += name.length () - 1 ;
738
717
}
739
718
return i;
@@ -747,11 +726,11 @@ size_t ASEnhancer::processSwitchBlock(string& line, size_t index)
747
726
* @param unindent the number of tabsets to erase.
748
727
* @return the number of characters erased.
749
728
*/
750
- int ASEnhancer::unindentLine (string& line, int unindent) const
729
+ int ASEnhancer::unindentLine (std:: string& line, int unindent) const
751
730
{
752
731
size_t whitespace = line.find_first_not_of (" \t " );
753
732
754
- if (whitespace == string::npos) // if line is blank
733
+ if (whitespace == std:: string::npos) // if line is blank
755
734
whitespace = line.length (); // must remove padding, if any
756
735
757
736
if (whitespace == 0 )
0 commit comments