diff --git a/AStyle/src/ASBeautifier.cpp b/AStyle/src/ASBeautifier.cpp index 9f69957..b3f9c7d 100644 --- a/AStyle/src/ASBeautifier.cpp +++ b/AStyle/src/ASBeautifier.cpp @@ -73,13 +73,13 @@ ASBeautifier::ASBeautifier() // initialize ASBeautifier member vectors beautifierFileType = INVALID_TYPE; // reset to an invalid type - headers = new vector; - nonParenHeaders = new vector; - assignmentOperators = new vector; - nonAssignmentOperators = new vector; - preBlockStatements = new vector; - preCommandHeaders = new vector; - indentableHeaders = new vector; + headers = new std::vector; + nonParenHeaders = new std::vector; + assignmentOperators = new std::vector; + nonAssignmentOperators = new std::vector; + preBlockStatements = new std::vector; + preCommandHeaders = new std::vector; + indentableHeaders = new std::vector; } /** @@ -101,36 +101,36 @@ ASBeautifier::ASBeautifier(const ASBeautifier& other) : ASBase(other) // vector '=' operator performs a DEEP copy of all elements in the vector - headerStack = new vector; + headerStack = new std::vector; *headerStack = *other.headerStack; tempStacks = copyTempStacks(other); - parenDepthStack = new vector; + parenDepthStack = new std::vector; *parenDepthStack = *other.parenDepthStack; - blockStatementStack = new vector; + blockStatementStack = new std::vector; *blockStatementStack = *other.blockStatementStack; - parenStatementStack = new vector; + parenStatementStack = new std::vector; *parenStatementStack = *other.parenStatementStack; - braceBlockStateStack = new vector; + braceBlockStateStack = new std::vector; *braceBlockStateStack = *other.braceBlockStateStack; - continuationIndentStack = new vector; + continuationIndentStack = new std::vector; *continuationIndentStack = *other.continuationIndentStack; - continuationIndentStackSizeStack = new vector; + continuationIndentStackSizeStack = new std::vector; *continuationIndentStackSizeStack = *other.continuationIndentStackSizeStack; - parenIndentStack = new vector; + parenIndentStack = new std::vector; *parenIndentStack = *other.parenIndentStack; - preprocIndentStack = new vector >; + preprocIndentStack = new std::vector >; *preprocIndentStack = *other.preprocIndentStack; - // Copy the pointers to vectors. + // Copy the pointers to std::vectors. // This is ok because the original ASBeautifier object // is not deleted until end of job. beautifierFileType = other.beautifierFileType; @@ -234,6 +234,8 @@ ASBeautifier::ASBeautifier(const ASBeautifier& other) : ASBase(other) shouldAlignMethodColon = other.shouldAlignMethodColon; shouldIndentPreprocDefine = other.shouldIndentPreprocDefine; shouldIndentPreprocConditional = other.shouldIndentPreprocConditional; + lambdaIndicator = other.lambdaIndicator; + indentCount = other.indentCount; spaceIndentCount = other.spaceIndentCount; spaceIndentObjCMethodAlignment = other.spaceIndentObjCMethodAlignment; @@ -303,28 +305,28 @@ void ASBeautifier::init(ASSourceIterator* iter) ASBase::init(getFileType()); g_preprocessorCppExternCBrace = 0; - initContainer(waitingBeautifierStack, new vector); - initContainer(activeBeautifierStack, new vector); + initContainer(waitingBeautifierStack, new std::vector); + initContainer(activeBeautifierStack, new std::vector); - initContainer(waitingBeautifierStackLengthStack, new vector); - initContainer(activeBeautifierStackLengthStack, new vector); + initContainer(waitingBeautifierStackLengthStack, new std::vector); + initContainer(activeBeautifierStackLengthStack, new std::vector); - initContainer(headerStack, new vector); + initContainer(headerStack, new std::vector); - initTempStacksContainer(tempStacks, new vector*>); - tempStacks->emplace_back(new vector); + initTempStacksContainer(tempStacks, new std::vector*>); + tempStacks->emplace_back(new std::vector); - initContainer(parenDepthStack, new vector); - initContainer(blockStatementStack, new vector); - initContainer(parenStatementStack, new vector); - initContainer(braceBlockStateStack, new vector); - // do not use emplace_back on vector until supported by macOS + initContainer(parenDepthStack, new std::vector); + initContainer(blockStatementStack, new std::vector); + initContainer(parenStatementStack, new std::vector); + initContainer(braceBlockStateStack, new std::vector); + // do not use emplace_back on std::vector until supported by macOS braceBlockStateStack->push_back(true); - initContainer(continuationIndentStack, new vector); - initContainer(continuationIndentStackSizeStack, new vector); + initContainer(continuationIndentStack, new std::vector); + initContainer(continuationIndentStackSizeStack, new std::vector); continuationIndentStackSizeStack->emplace_back(0); - initContainer(parenIndentStack, new vector); - initContainer(preprocIndentStack, new vector >); + initContainer(parenIndentStack, new std::vector); + initContainer(preprocIndentStack, new std::vector >); previousLastLineHeader = nullptr; currentHeader = nullptr; @@ -361,6 +363,7 @@ void ASBeautifier::init(ASSourceIterator* iter) isInTemplate = false; isInConditional = false; isInTrailingReturnType = false; + lambdaIndicator = false; indentCount = 0; spaceIndentCount = 0; @@ -454,9 +457,9 @@ void ASBeautifier::initVectors() * @return the indented line. * @param originalLine the original unindented line. */ -string ASBeautifier::beautify(const string& originalLine) +std::string ASBeautifier::beautify(const std::string& originalLine) { - string line; + std::string line; bool isInQuoteContinuation = isInVerbatimQuote || haveLineContinuationChar; currentHeader = nullptr; @@ -501,7 +504,7 @@ string ASBeautifier::beautify(const string& originalLine) // trim the end of comment and SQL lines line = originalLine; size_t trimEnd = line.find_last_not_of(" \t"); - if (trimEnd == string::npos) + if (trimEnd == std::string::npos) trimEnd = 0; else trimEnd++; @@ -509,7 +512,7 @@ string ASBeautifier::beautify(const string& originalLine) line.erase(trimEnd); // does a brace open the line size_t firstChar = line.find_first_not_of(" \t"); - if (firstChar != string::npos) + if (firstChar != std::string::npos) { if (line[firstChar] == '{') lineBeginsWithOpenBrace = true; @@ -534,20 +537,20 @@ string ASBeautifier::beautify(const string& originalLine) lineIsLineCommentOnly = true; else if (line.compare(0, 2, "/*") == 0) { - if (line.find("*/", 2) != string::npos) + if (line.find("*/", 2) != std::string::npos) lineIsCommentOnly = true; } } isInRunInComment = false; size_t j = line.find_first_not_of(" \t{"); - if (j != string::npos && line.compare(j, 2, "//") == 0) + if (j != std::string::npos && line.compare(j, 2, "//") == 0) lineOpensWithLineComment = true; - if (j != string::npos && line.compare(j, 2, "/*") == 0) + if (j != std::string::npos && line.compare(j, 2, "/*") == 0) { lineOpensWithComment = true; size_t k = line.find_first_not_of(" \t"); - if (k != string::npos && line.compare(k, 1, "{") == 0) + if (k != std::string::npos && line.compare(k, 1, "{") == 0) isInRunInComment = true; } } @@ -555,7 +558,7 @@ string ASBeautifier::beautify(const string& originalLine) // When indent is OFF the lines must still be processed by ASBeautifier. // Otherwise the lines immediately following may not be indented correctly. if ((lineIsLineCommentOnly || lineIsCommentOnly) - && line.find("*INDENT-OFF*", 0) != string::npos) + && line.find("*INDENT-OFF*", 0) != std::string::npos) isIndentModeOff = true; if (line.length() == 0) @@ -594,7 +597,7 @@ string ASBeautifier::beautify(const string& originalLine) && line.length() > 0 && line[0] != '#') { - string indentedLine; + std::string indentedLine; if (isInClassHeaderTab || isInClassInitializer) { // parsing is turned off in ASFormatter by indent-off @@ -614,11 +617,11 @@ string ASBeautifier::beautify(const string& originalLine) { if (line[0] == '#' && !isInDefine) { - string preproc = extractPreprocessorStatement(line); + std::string preproc = extractPreprocessorStatement(line); processPreprocessor(preproc, line); if (isInIndentablePreprocBlock || isInIndentablePreproc) { - string indentedLine; + std::string indentedLine; if (preproc.length() >= 2 && preproc.substr(0, 2) == "if") // #if, #ifdef, #ifndef { indentedLine = preLineWS(preprocBlockIndent, 0) + line; @@ -642,10 +645,10 @@ string ASBeautifier::beautify(const string& originalLine) } if (shouldIndentPreprocConditional && preproc.length() > 0) { - string indentedLine; + std::string indentedLine; if (preproc.length() >= 2 && preproc.substr(0, 2) == "if") // #if, #ifdef, #ifndef { - pair entry; // indentCount, spaceIndentCount + std::pair entry; // indentCount, spaceIndentCount if (!isInDefine && activeBeautifierStack != nullptr && !activeBeautifierStack->empty()) entry = activeBeautifierStack->back()->computePreprocessorIndent(); else @@ -696,7 +699,7 @@ string ASBeautifier::beautify(const string& originalLine) ASBeautifier* defineBeautifier = activeBeautifierStack->back(); activeBeautifierStack->pop_back(); - string indentedLine = defineBeautifier->beautify(line); + std::string indentedLine = defineBeautifier->beautify(line); delete defineBeautifier; return getIndentedLineReturn(indentedLine, originalLine); } @@ -760,7 +763,7 @@ string ASBeautifier::beautify(const string& originalLine) if (line.length() > 0 && line[0] == '#') { // the 'define' does not have to be attached to the '#' - string preproc = trim(line.substr(1)); + std::string preproc = trim(line.substr(1)); if (preproc.compare(0, 6, "define") == 0) { if (!continuationIndentStack->empty() @@ -787,7 +790,7 @@ string ASBeautifier::beautify(const string& originalLine) // finally, insert indentations into beginning of line - string indentedLine = preLineWS(indentCount, spaceIndentCount) + line; + std::string indentedLine = preLineWS(indentCount, spaceIndentCount) + line; indentedLine = getIndentedLineReturn(indentedLine, originalLine); prevFinalLineSpaceIndentCount = spaceIndentCount; @@ -797,7 +800,7 @@ string ASBeautifier::beautify(const string& originalLine) previousLastLineHeader = lastLineHeader; if ((lineIsLineCommentOnly || lineIsCommentOnly) - && line.find("*INDENT-ON*", 0) != string::npos) + && line.find("*INDENT-ON*", 0) != std::string::npos) isIndentModeOff = false; return indentedLine; @@ -892,7 +895,7 @@ void ASBeautifier::setTabIndentation(int length, bool forceTabs) */ void ASBeautifier::setSpaceIndentation(int length) { - indentString = string(length, ' '); + indentString = std::string(length, ' '); indentLength = length; } @@ -1122,7 +1125,7 @@ int ASBeautifier::getIndentLength() const * * @return the char used for indentation. */ -string ASBeautifier::getIndentString() const +std::string ASBeautifier::getIndentString() const { return indentString; } @@ -1265,14 +1268,14 @@ int ASBeautifier::getTabLength() const return tabLength; } -const string& ASBeautifier::getIndentedLineReturn(const string& newLine, const string& originalLine) const +const std::string& ASBeautifier::getIndentedLineReturn(const std::string& newLine, const std::string& originalLine) const { if (isIndentModeOff) return originalLine; return newLine; } -string ASBeautifier::preLineWS(int lineIndentCount, int lineSpaceIndentCount) const +std::string ASBeautifier::preLineWS(int lineIndentCount, int lineSpaceIndentCount) const { if (shouldForceTabIndentation) { @@ -1291,18 +1294,18 @@ string ASBeautifier::preLineWS(int lineIndentCount, int lineSpaceIndentCount) co } } - string ws; + std::string ws; for (int i = 0; i < lineIndentCount; i++) ws += indentString; while ((lineSpaceIndentCount--) > 0) - ws += string(" "); + ws += std::string(" "); return ws; } /** * register a continuation indent. */ -void ASBeautifier::registerContinuationIndent(const string& line, int i, int spaceIndentCount_, +void ASBeautifier::registerContinuationIndent(const std::string& line, int i, int spaceIndentCount_, int tabIncrementIn, int minIndent, bool updateParenStack) { assert(i >= -1); @@ -1370,7 +1373,7 @@ void ASBeautifier::registerContinuationIndent(const string& line, int i, int spa /** * Register a continuation indent for a class header or a class initializer colon. */ -void ASBeautifier::registerContinuationIndentColon(const string& line, int i, int tabIncrementIn) +void ASBeautifier::registerContinuationIndentColon(const std::string& line, int i, int tabIncrementIn) { assert(line[i] == ':'); assert(isInClassInitializer || isInClassHeaderTab); @@ -1380,7 +1383,7 @@ void ASBeautifier::registerContinuationIndentColon(const string& line, int i, in if (firstChar == (size_t) i) // firstChar is ':' { size_t firstWord = line.find_first_not_of(" \t", firstChar + 1); - if (firstWord != string::npos) + if (firstWord != std::string::npos) { int continuationIndentCount = firstWord + spaceIndentCount + tabIncrementIn; continuationIndentStack->emplace_back(continuationIndentCount); @@ -1394,10 +1397,10 @@ void ASBeautifier::registerContinuationIndentColon(const string& line, int i, in * This may be called for the activeBeautiferStack * instead of the active ASBeautifier object. */ -pair ASBeautifier::computePreprocessorIndent() +std::pair ASBeautifier::computePreprocessorIndent() { computePreliminaryIndentation(); - pair entry(indentCount, spaceIndentCount); + std::pair entry(indentCount, spaceIndentCount); if (!headerStack->empty() && entry.first > 0 && (headerStack->back() == &AS_IF @@ -1412,7 +1415,7 @@ pair ASBeautifier::computePreprocessorIndent() * get distance to the next non-white space, non-comment character in the line. * if no such character exists, return the length remaining to the end of the line. */ -int ASBeautifier::getNextProgramCharDistance(const string& line, int i) const +int ASBeautifier::getNextProgramCharDistance(const std::string& line, int i) const { bool inComment = false; int remainingCharNum = line.length() - i; @@ -1451,15 +1454,15 @@ int ASBeautifier::getNextProgramCharDistance(const string& line, int i) const } /** - * find the index number of a string element in a container of strings + * find the index number of a std::string element in a container of std::strings * * @return the index number of element in the container. -1 if element not found. - * @param container a vector of strings. + * @param container a vector of std::strings. * @param element the element to find . */ -int ASBeautifier::indexOf(const vector& container, const string* element) const +int ASBeautifier::indexOf(const std::vector& container, const std::string* element) const { - vector::const_iterator where; + std::vector::const_iterator where; where = find(container.begin(), container.end(), element); if (where == container.end()) @@ -1485,7 +1488,7 @@ int ASBeautifier::convertTabToSpaces(int i, int tabIncrementIn) const * @return the trimmed line. * @param str the line to trim. */ -string ASBeautifier::trim(const string& str) const +std::string ASBeautifier::trim(const std::string& str) const { int start = 0; int end = str.length() - 1; @@ -1500,7 +1503,7 @@ string ASBeautifier::trim(const string& str) const if (end > -1 && str[end] == '\\') end = str.length() - 1; - string returnStr(str, start, end + 1 - start); + std::string returnStr(str, start, end + 1 - start); return returnStr; } @@ -1510,14 +1513,14 @@ string ASBeautifier::trim(const string& str) const * @return the trimmed line. * @param str the line to trim. */ -string ASBeautifier::rtrim(const string& str) const +std::string ASBeautifier::rtrim(const std::string& str) const { size_t len = str.length(); size_t end = str.find_last_not_of(" \t"); - if (end == string::npos + if (end == std::string::npos || end == len - 1) return str; - string returnStr(str, 0, end + 1); + std::string returnStr(str, 0, end + 1); return returnStr; } @@ -1525,15 +1528,15 @@ string ASBeautifier::rtrim(const string& str) const * Copy tempStacks for the copy constructor. * The value of the vectors must also be copied. */ -vector*>* ASBeautifier::copyTempStacks(const ASBeautifier& other) const +std::vector*>* ASBeautifier::copyTempStacks(const ASBeautifier& other) const { - vector*>* tempStacksNew = new vector*>; - vector*>::iterator iter; + std::vector*>* tempStacksNew = new std::vector*>; + std::vector*>::iterator iter; for (iter = other.tempStacks->begin(); iter != other.tempStacks->end(); ++iter) { - vector* newVec = new vector; + std::vector* newVec = new std::vector; *newVec = **iter; tempStacksNew->emplace_back(newVec); } @@ -1577,11 +1580,11 @@ void ASBeautifier::deleteContainer(T& container) * Therefore the ASBeautifier objects have to be deleted in addition to the * ASBeautifier pointer entries. */ -void ASBeautifier::deleteBeautifierContainer(vector*& container) +void ASBeautifier::deleteBeautifierContainer(std::vector*& container) { if (container != nullptr) { - vector::iterator iter = container->begin(); + std::vector::iterator iter = container->begin(); while (iter < container->end()) { delete *iter; @@ -1595,14 +1598,14 @@ void ASBeautifier::deleteBeautifierContainer(vector*& container) /** * Delete the tempStacks vector object. - * The tempStacks is a vector of pointers to strings allocated with the 'new' operator. - * Therefore the strings have to be deleted in addition to the tempStacks entries. + * The tempStacks is a vector of pointers to std::strings allocated with the 'new' operator. + * Therefore the std::strings have to be deleted in addition to the tempStacks entries. */ -void ASBeautifier::deleteTempStacksContainer(vector*>*& container) +void ASBeautifier::deleteTempStacksContainer(std::vector*>*& container) { if (container != nullptr) { - vector*>::iterator iter = container->begin(); + std::vector*>::iterator iter = container->begin(); while (iter < container->end()) { delete *iter; @@ -1630,11 +1633,11 @@ void ASBeautifier::initContainer(T& container, T value) /** * Initialize the tempStacks vector object. - * The tempStacks is a vector of pointers to strings allocated with the 'new' operator. + * The tempStacks is a vector of pointers to std::strings allocated with the 'new' operator. * Any residual entries are deleted before the vector is initialized. */ -void ASBeautifier::initTempStacksContainer(vector*>*& container, - vector*>* value) +void ASBeautifier::initTempStacksContainer(std::vector*>*& container, + std::vector*>* value) { if (container != nullptr) deleteTempStacksContainer(container); @@ -1648,7 +1651,7 @@ void ASBeautifier::initTempStacksContainer(vector*>*& cont * * @return true if line ends with a comma, otherwise false. */ -bool ASBeautifier::statementEndsWithComma(const string& line, int index) const +bool ASBeautifier::statementEndsWithComma(const std::string& line, int index) const { assert(line[index] == '='); @@ -1718,7 +1721,7 @@ bool ASBeautifier::statementEndsWithComma(const string& line, int index) const size_t lastChar = line.find_last_not_of(" \t", i - 1); - if (lastChar == string::npos || line[lastChar] != ',') + if (lastChar == std::string::npos || line[lastChar] != ',') return false; return true; @@ -1729,16 +1732,16 @@ bool ASBeautifier::statementEndsWithComma(const string& line, int index) const * * @return is before a line-end comment. */ -bool ASBeautifier::isLineEndComment(const string& line, int startPos) const +bool ASBeautifier::isLineEndComment(const std::string& line, int startPos) const { assert(line.compare(startPos, 2, "/*") == 0); // comment must be closed on this line with nothing after it size_t endNum = line.find("*/", startPos + 2); - if (endNum != string::npos) + if (endNum != std::string::npos) { size_t nextChar = line.find_first_not_of(" \t", endNum + 2); - if (nextChar == string::npos) + if (nextChar == std::string::npos) return true; } return false; @@ -1749,7 +1752,7 @@ bool ASBeautifier::isLineEndComment(const string& line, int startPos) const * * @return is the index to the previous word (the in statement indent). */ -int ASBeautifier::getContinuationIndentAssign(const string& line, size_t currPos) const +int ASBeautifier::getContinuationIndentAssign(const std::string& line, size_t currPos) const { assert(line[currPos] == '='); @@ -1758,7 +1761,7 @@ int ASBeautifier::getContinuationIndentAssign(const string& line, size_t currPos // get the last legal word (may be a number) size_t end = line.find_last_not_of(" \t", currPos - 1); - if (end == string::npos || !isLegalNameChar(line[end])) + if (end == std::string::npos || !isLegalNameChar(line[end])) return 0; int start; // start of the previous word @@ -1777,13 +1780,13 @@ int ASBeautifier::getContinuationIndentAssign(const string& line, size_t currPos * * @return is the indent to the second word on the line (the in statement indent). */ -int ASBeautifier::getContinuationIndentComma(const string& line, size_t currPos) const +int ASBeautifier::getContinuationIndentComma(const std::string& line, size_t currPos) const { assert(line[currPos] == ','); // get first word on a line size_t indent = line.find_first_not_of(" \t"); - if (indent == string::npos || !isLegalNameChar(line[indent])) + if (indent == std::string::npos || !isLegalNameChar(line[indent])) return 0; // bypass first word @@ -1798,7 +1801,7 @@ int ASBeautifier::getContinuationIndentComma(const string& line, size_t currPos) // point to second word or assignment operator indent = line.find_first_not_of(" \t", indent); - if (indent == string::npos || indent >= currPos) + if (indent == std::string::npos || indent >= currPos) return 0; return indent; @@ -1808,18 +1811,18 @@ int ASBeautifier::getContinuationIndentComma(const string& line, size_t currPos) * get the next word on a line * the argument 'currPos' must point to the current position. * - * @return is the next word or an empty string if none found. + * @return is the next word or an empty std::string if none found. */ -string ASBeautifier::getNextWord(const string& line, size_t currPos) const +std::string ASBeautifier::getNextWord(const std::string& line, size_t currPos) const { size_t lineLength = line.length(); // get the last legal word (may be a number) if (currPos == lineLength - 1) - return string(); + return std::string(); size_t start = line.find_first_not_of(" \t", currPos + 1); - if (start == string::npos || !isLegalNameChar(line[start])) - return string(); + if (start == std::string::npos || !isLegalNameChar(line[start])) + return std::string(); size_t end; // end of the current word for (end = start + 1; end <= lineLength; end++) @@ -1838,10 +1841,10 @@ string ASBeautifier::getNextWord(const string& line, size_t currPos) const * * @return is true or false. */ -bool ASBeautifier::isIndentedPreprocessor(const string& line, size_t currPos) const +bool ASBeautifier::isIndentedPreprocessor(const std::string& line, size_t currPos) const { assert(line[0] == '#'); - string nextWord = getNextWord(line, currPos); + std::string nextWord = getNextWord(line, currPos); if (nextWord == "region" || nextWord == "endregion") return true; // is it #pragma omp @@ -1849,7 +1852,7 @@ bool ASBeautifier::isIndentedPreprocessor(const string& line, size_t currPos) co { // find pragma size_t start = line.find("pragma"); - if (start == string::npos || !isLegalNameChar(line[start])) + if (start == std::string::npos || !isLegalNameChar(line[start])) return false; // bypass pragma for (; start < line.length(); start++) @@ -1862,7 +1865,7 @@ bool ASBeautifier::isIndentedPreprocessor(const string& line, size_t currPos) co return false; // point to start of second word start = line.find_first_not_of(" \t", start); - if (start == string::npos) + if (start == std::string::npos) return false; // point to end of second word size_t end; @@ -1872,7 +1875,7 @@ bool ASBeautifier::isIndentedPreprocessor(const string& line, size_t currPos) co break; } // check for "pragma omp" - string word = line.substr(start, end - start); + std::string word = line.substr(start, end - start); if (word == "omp" || word == "region" || word == "endregion") return true; } @@ -1884,9 +1887,9 @@ bool ASBeautifier::isIndentedPreprocessor(const string& line, size_t currPos) co * * @return is true or false. */ -bool ASBeautifier::isPreprocessorConditionalCplusplus(const string& line) const +bool ASBeautifier::isPreprocessorConditionalCplusplus(const std::string& line) const { - string preproc = trim(line.substr(1)); + std::string preproc = trim(line.substr(1)); if (preproc.compare(0, 5, "ifdef") == 0 && getNextWord(preproc, 4) == "__cplusplus") return true; if (preproc.compare(0, 2, "if") == 0) @@ -1894,15 +1897,15 @@ bool ASBeautifier::isPreprocessorConditionalCplusplus(const string& line) const // check for " #if defined(__cplusplus)" size_t charNum = 2; charNum = preproc.find_first_not_of(" \t", charNum); - if (charNum != string::npos && preproc.compare(charNum, 7, "defined") == 0) + if (charNum != std::string::npos && preproc.compare(charNum, 7, "defined") == 0) { charNum += 7; charNum = preproc.find_first_not_of(" \t", charNum); - if (charNum != string::npos && preproc.compare(charNum, 1, "(") == 0) + if (charNum != std::string::npos && preproc.compare(charNum, 1, "(") == 0) { ++charNum; charNum = preproc.find_first_not_of(" \t", charNum); - if (charNum != string::npos && preproc.compare(charNum, 11, "__cplusplus") == 0) + if (charNum != std::string::npos && preproc.compare(charNum, 11, "__cplusplus") == 0) return true; } } @@ -1916,16 +1919,16 @@ bool ASBeautifier::isPreprocessorConditionalCplusplus(const string& line) const * * @return is true or false. */ -bool ASBeautifier::isInPreprocessorUnterminatedComment(const string& line) +bool ASBeautifier::isInPreprocessorUnterminatedComment(const std::string& line) { if (!isInPreprocessorComment) { size_t startPos = line.find("/*"); - if (startPos == string::npos) + if (startPos == std::string::npos) return false; } size_t endNum = line.find("*/"); - if (endNum != string::npos) + if (endNum != std::string::npos) { isInPreprocessorComment = false; return false; @@ -1951,7 +1954,7 @@ int ASBeautifier::getBeautifierFileType() const /** * Process preprocessor statements and update the beautifier stacks. */ -void ASBeautifier::processPreprocessor(const string& preproc, const string& line) +void ASBeautifier::processPreprocessor(const std::string& preproc, const std::string& line) { // When finding a multi-lined #define statement, the original beautifier // 1. sets its isInDefineDefinition flag @@ -2267,10 +2270,10 @@ int ASBeautifier::adjustIndentCountForBreakElseIfComments() const { assert(isElseHeaderIndent && !tempStacks->empty()); int indentCountIncrement = 0; - vector* lastTempStack = tempStacks->back(); + std::vector* lastTempStack = tempStacks->back(); if (lastTempStack != nullptr) { - for (const string* const lastTemp : *lastTempStack) + for (const std::string* const lastTemp : *lastTempStack) { if (*lastTemp == AS_ELSE) indentCountIncrement++; @@ -2281,22 +2284,22 @@ int ASBeautifier::adjustIndentCountForBreakElseIfComments() const /** * Extract a preprocessor statement without the #. - * If a error occurs an empty string is returned. + * If a error occurs an empty std::string is returned. */ -string ASBeautifier::extractPreprocessorStatement(const string& line) const +std::string ASBeautifier::extractPreprocessorStatement(const std::string& line) const { - string preproc; + std::string preproc; size_t start = line.find_first_not_of("#/ \t"); - if (start == string::npos) + if (start == std::string::npos) return preproc; size_t end = line.find_first_of("/ \t", start); - if (end == string::npos) + if (end == std::string::npos) end = line.length(); preproc = line.substr(start, end - start); return preproc; } -void ASBeautifier::adjustObjCMethodDefinitionIndentation(const string& line_) +void ASBeautifier::adjustObjCMethodDefinitionIndentation(const std::string& line_) { // register indent for Objective-C continuation line if (line_.length() > 0 @@ -2304,7 +2307,7 @@ void ASBeautifier::adjustObjCMethodDefinitionIndentation(const string& line_) { if (shouldAlignMethodColon && objCColonAlignSubsequent != -1) { - string convertedLine = getIndentedSpaceEquivalent(line_); + std::string convertedLine = getIndentedSpaceEquivalent(line_); colonIndentObjCMethodAlignment = findObjCColonAlignment(convertedLine); int objCColonAlignSubsequentIndent = objCColonAlignSubsequent + indentLength; if (objCColonAlignSubsequentIndent > colonIndentObjCMethodAlignment) @@ -2327,7 +2330,7 @@ void ASBeautifier::adjustObjCMethodDefinitionIndentation(const string& line_) } } -void ASBeautifier::adjustObjCMethodCallIndentation(const string& line_) +void ASBeautifier::adjustObjCMethodCallIndentation(const std::string& line_) { static int keywordIndentObjCMethodAlignment = 0; if (shouldAlignMethodColon && objCColonAlignSubsequent != -1) @@ -2335,7 +2338,7 @@ void ASBeautifier::adjustObjCMethodCallIndentation(const string& line_) if (isInObjCMethodCallFirst) { isInObjCMethodCallFirst = false; - string convertedLine = getIndentedSpaceEquivalent(line_); + std::string convertedLine = getIndentedSpaceEquivalent(line_); bracePosObjCMethodAlignment = convertedLine.find('['); keywordIndentObjCMethodAlignment = getObjCFollowingKeyword(convertedLine, bracePosObjCMethodAlignment); @@ -2372,7 +2375,7 @@ void ASBeautifier::adjustObjCMethodCallIndentation(const string& line_) if (isInObjCMethodCallFirst) { isInObjCMethodCallFirst = false; - string convertedLine = getIndentedSpaceEquivalent(line_); + std::string convertedLine = getIndentedSpaceEquivalent(line_); bracePosObjCMethodAlignment = convertedLine.find('['); keywordIndentObjCMethodAlignment = getObjCFollowingKeyword(convertedLine, bracePosObjCMethodAlignment); @@ -2404,13 +2407,13 @@ void ASBeautifier::clearObjCMethodDefinitionAlignment() * Find the first alignment colon on a line. * Ternary operators (?) are bypassed. */ -int ASBeautifier::findObjCColonAlignment(const string& line) const +int ASBeautifier::findObjCColonAlignment(const std::string& line) const { bool haveTernary = false; for (size_t i = 0; i < line.length(); i++) { i = line.find_first_of(":?", i); - if (i == string::npos) + if (i == std::string::npos) break; if (line[i] == '?') @@ -2434,7 +2437,7 @@ int ASBeautifier::findObjCColonAlignment(const string& line) const * If it cannot be aligned indentLength is returned and a new colon * position is calculated. */ -int ASBeautifier::computeObjCColonAlignment(const string& line, int colonAlignPosition) const +int ASBeautifier::computeObjCColonAlignment(const std::string& line, int colonAlignPosition) const { int colonPosition = findObjCColonAlignment(line); if (colonPosition < 0 || colonPosition > colonAlignPosition) @@ -2448,18 +2451,18 @@ int ASBeautifier::computeObjCColonAlignment(const string& line, int colonAlignPo * Use for now and see what happens. * Most programmers will probably use align-method-colon anyway. */ -int ASBeautifier::getObjCFollowingKeyword(const string& line, int bracePos) const +int ASBeautifier::getObjCFollowingKeyword(const std::string& line, int bracePos) const { assert(line[bracePos] == '['); size_t firstText = line.find_first_not_of(" \t", bracePos + 1); - if (firstText == string::npos) + if (firstText == std::string::npos) return -(indentCount * indentLength - 1); size_t searchBeg = firstText; size_t objectEnd = 0; // end of object text if (line[searchBeg] == '[') { objectEnd = line.find(']', searchBeg + 1); - if (objectEnd == string::npos) + if (objectEnd == std::string::npos) return 0; } else @@ -2467,17 +2470,17 @@ int ASBeautifier::getObjCFollowingKeyword(const string& line, int bracePos) cons if (line[searchBeg] == '(') { searchBeg = line.find(')', searchBeg + 1); - if (searchBeg == string::npos) + if (searchBeg == std::string::npos) return 0; } // bypass the object name objectEnd = line.find_first_of(" \t", searchBeg + 1); - if (objectEnd == string::npos) + if (objectEnd == std::string::npos) return 0; --objectEnd; } size_t keyPos = line.find_first_not_of(" \t", objectEnd + 1); - if (keyPos == string::npos) + if (keyPos == std::string::npos) return 0; return keyPos - firstText; } @@ -2487,11 +2490,11 @@ int ASBeautifier::getObjCFollowingKeyword(const string& line, int bracePos) cons * The indentCount is NOT included * Needed to compute an accurate alignment. */ -string ASBeautifier::getIndentedSpaceEquivalent(const string& line_) const +std::string ASBeautifier::getIndentedSpaceEquivalent(const std::string& line_) const { - string spaceIndent; + std::string spaceIndent; spaceIndent.append(spaceIndentCount, ' '); - string convertedLine = spaceIndent + line_; + std::string convertedLine = spaceIndent + line_; for (size_t i = spaceIndent.length(); i < convertedLine.length(); i++) { if (convertedLine[i] == '\t') @@ -2535,7 +2538,7 @@ bool ASBeautifier::isTopLevel() const /** * Parse the current line to update indentCount and spaceIndentCount. */ -void ASBeautifier::parseCurrentLine(const string& line) +void ASBeautifier::parseCurrentLine(const std::string& line) { bool isInLineComment = false; bool isInOperator = false; @@ -2625,7 +2628,7 @@ void ASBeautifier::parseCurrentLine(const string& line) { if (isCStyle()) { - string delim = ')' + verbatimDelimiter; + std::string delim = ')' + verbatimDelimiter; int delimStart = i - delim.length(); if (delimStart >= 0 && line.substr(delimStart, delim.length()) == delim) { @@ -2736,7 +2739,7 @@ void ASBeautifier::parseCurrentLine(const string& line) continue; } - // if we have reached this far then we are NOT in a comment or string of special character... + // if we have reached this far then we are NOT in a comment or std::string of special character... if (probationHeader != nullptr) { @@ -2817,7 +2820,7 @@ void ASBeautifier::parseCurrentLine(const string& line) { headerStack->pop_back(); isInClassHeader = false; - if (line.find(AS_STRUCT, 0) > i) // if not on this line + if ( !findKeyword(line, i, AS_STRUCT) ) // if not on this line #526 indentCount -= classInitializerIndents; if (indentCount < 0) indentCount = 0; @@ -2834,11 +2837,16 @@ void ASBeautifier::parseCurrentLine(const string& line) { ++squareBracketCount; // #525 Maybe check for opening brace in the line - if (squareBracketCount == 1 && isObjCStyle() && line.find("{", i + 1 ) == string::npos) + if (squareBracketCount == 1 && isObjCStyle() && line.find("{", i + 1 ) == std::string::npos) { isInObjCMethodCall = true; isInObjCMethodCallFirst = true; } + + // #121 + if (!isLegalNameChar(prevNonSpaceCh) && prevNonSpaceCh != ']' && prevNonSpaceCh != ')') { + lambdaIndicator = true; + } } continuationIndentStackSizeStack->emplace_back(continuationIndentStack->size()); @@ -2854,6 +2862,7 @@ void ASBeautifier::parseCurrentLine(const string& line) { if (ch == ']') --squareBracketCount; + if (squareBracketCount <= 0) { squareBracketCount = 0; @@ -2931,7 +2940,7 @@ void ASBeautifier::parseCurrentLine(const string& line) if (!isBlockOpener && currentHeader != nullptr) { - for (const string* const nonParenHeader : *nonParenHeaders) + for (const std::string* const nonParenHeader : *nonParenHeaders) if (currentHeader == nonParenHeader) { isBlockOpener = true; @@ -2939,6 +2948,11 @@ void ASBeautifier::parseCurrentLine(const string& line) } } + // #121 fix indent of lambda bodies + if (isCStyle() && lambdaIndicator ) { + isBlockOpener = false; + } + // do not use emplace_back on vector until supported by macOS braceBlockStateStack->push_back(isBlockOpener); @@ -3031,7 +3045,7 @@ void ASBeautifier::parseCurrentLine(const string& line) foundPreCommandMacro = false; isInExternC = false; - tempStacks->emplace_back(new vector); + tempStacks->emplace_back(new std::vector); headerStack->emplace_back(&AS_OPEN_BRACE); lastLineHeader = &AS_OPEN_BRACE; @@ -3043,7 +3057,7 @@ void ASBeautifier::parseCurrentLine(const string& line) if (isPotentialHeader && squareBracketCount == 0) { - const string* newHeader = findHeader(line, i, headers); + const std::string* newHeader = findHeader(line, i, headers); // java can have a 'default' not in a switch if (newHeader == &AS_DEFAULT @@ -3053,7 +3067,7 @@ void ASBeautifier::parseCurrentLine(const string& line) if (isCStyle() && (newHeader == &AS_FOREVER || newHeader == &AS_FOREACH)) { - if (line.find_first_of("=;", i) != string::npos) + if (line.find_first_of("=;", i) != std::string::npos) newHeader = nullptr; } else if (isSharpStyle() @@ -3073,7 +3087,7 @@ void ASBeautifier::parseCurrentLine(const string& line) isInHeader = true; - vector* lastTempStack = nullptr; + std::vector* lastTempStack = nullptr; if (!tempStacks->empty()) lastTempStack = tempStacks->back(); @@ -3219,17 +3233,17 @@ void ASBeautifier::parseCurrentLine(const string& line) foundPreCommandHeader = true; // Objective-C NSException macros are preCommandHeaders - if (isCStyle() && findKeyword(line, i, AS_NS_DURING)) + if (isObjCStyle() && findKeyword(line, i, AS_NS_DURING)) foundPreCommandMacro = true; - if (isCStyle() && findKeyword(line, i, AS_NS_HANDLER)) + if (isObjCStyle() && findKeyword(line, i, AS_NS_HANDLER)) foundPreCommandMacro = true; //https://sourceforge.net/p/astyle/bugs/550/ //enum can be function return value - if (parenDepth == 0 && findKeyword(line, i, AS_ENUM) && line.find_first_of(AS_OPEN_PAREN, i) == string::npos) + if (parenDepth == 0 && findKeyword(line, i, AS_ENUM) && line.find_first_of(AS_OPEN_PAREN, i) == std::string::npos) isInEnum = true; - if (parenDepth == 0 && (findKeyword(line, i, AS_TYPEDEF_STRUCT) || findKeyword(line, i, AS_STRUCT)) && line.find_first_of(AS_SEMICOLON, i) == string::npos) + if (parenDepth == 0 && (findKeyword(line, i, AS_TYPEDEF_STRUCT) || findKeyword(line, i, AS_STRUCT)) && line.find_first_of(AS_SEMICOLON, i) == std::string::npos) { isInStruct = true; } @@ -3356,14 +3370,14 @@ void ASBeautifier::parseCurrentLine(const string& line) { // is comma at end of line size_t nextChar = line.find_first_not_of(" \t", i + 1); - if (nextChar != string::npos) + if (nextChar != std::string::npos) { if (line.compare(nextChar, 2, "//") == 0 || line.compare(nextChar, 2, "/*") == 0) - nextChar = string::npos; + nextChar = std::string::npos; } // register indent - if (nextChar == string::npos) + if (nextChar == std::string::npos) { // register indent at previous word if (isJavaStyle() && isInClassHeader) @@ -3390,6 +3404,9 @@ void ASBeautifier::parseCurrentLine(const string& line) { if (ch == '}') { + + lambdaIndicator = false; + // first check if this '}' closes a previous block, or a static array... if (braceBlockStateStack->size() > 1) { @@ -3445,7 +3462,7 @@ void ASBeautifier::parseCurrentLine(const string& line) int headerPlace = indexOf(*headerStack, &AS_OPEN_BRACE); if (headerPlace != -1) { - const string* popped = headerStack->back(); + const std::string* popped = headerStack->back(); while (popped != &AS_OPEN_BRACE) { headerStack->pop_back(); @@ -3465,7 +3482,7 @@ void ASBeautifier::parseCurrentLine(const string& line) if (!tempStacks->empty()) { - vector* temp = tempStacks->back(); + std::vector* temp = tempStacks->back(); tempStacks->pop_back(); delete temp; } @@ -3525,7 +3542,7 @@ void ASBeautifier::parseCurrentLine(const string& line) // (otherwise 'struct XXX' statements would be wrongly interpreted...) if (!isInTemplate && !(isCStyle() && parenDepth > 0)) { - const string* newHeader = findHeader(line, i, preBlockStatements); + const std::string* newHeader = findHeader(line, i, preBlockStatements); // CORBA IDL module if (newHeader == &AS_MODULE) { @@ -3572,7 +3589,7 @@ void ASBeautifier::parseCurrentLine(const string& line) continue; } } - const string* foundIndentableHeader = findHeader(line, i, indentableHeaders); + const std::string* foundIndentableHeader = findHeader(line, i, indentableHeaders); if (foundIndentableHeader != nullptr) { @@ -3630,7 +3647,7 @@ void ASBeautifier::parseCurrentLine(const string& line) } // bypass the entire name for all others - string name = getCurrentWord(line, i); + std::string name = getCurrentWord(line, i); i += name.length() - 1; continue; } @@ -3643,11 +3660,11 @@ void ASBeautifier::parseCurrentLine(const string& line) && !isWhiteSpace(line[i + 1]) && isCharPotentialHeader(line, i + 1)) { - string curWord = getCurrentWord(line, i + 1); + std::string curWord = getCurrentWord(line, i + 1); if (curWord == AS_INTERFACE || curWord == AS_AUTORELEASEPOOL) { isInObjCInterface = true; - string name = '@' + curWord; + std::string name = '@' + curWord; i += name.length() - 1; continue; } @@ -3665,7 +3682,7 @@ void ASBeautifier::parseCurrentLine(const string& line) --indentCount; if (modifierIndent) spaceIndentCount += (indentLength / 2); - string name = '@' + curWord; + std::string name = '@' + curWord; i += name.length() - 1; continue; } @@ -3675,7 +3692,7 @@ void ASBeautifier::parseCurrentLine(const string& line) popLastContinuationIndent(); spaceIndentCount = 0; isInObjCMethodDefinition = false; - string name = '@' + curWord; + std::string name = '@' + curWord; i += name.length() - 1; continue; } @@ -3702,8 +3719,8 @@ void ASBeautifier::parseCurrentLine(const string& line) if (isPotentialOperator) { // Check if an operator has been reached. - const string* foundAssignmentOp = findOperator(line, i, assignmentOperators); - const string* foundNonAssignmentOp = findOperator(line, i, nonAssignmentOperators); + const std::string* foundAssignmentOp = findOperator(line, i, assignmentOperators); + const std::string* foundNonAssignmentOp = findOperator(line, i, nonAssignmentOperators); if (foundNonAssignmentOp != nullptr) { diff --git a/AStyle/src/ASEnhancer.cpp b/AStyle/src/ASEnhancer.cpp index da34347..ace7dc8 100644 --- a/AStyle/src/ASEnhancer.cpp +++ b/AStyle/src/ASEnhancer.cpp @@ -34,7 +34,7 @@ void ASEnhancer::init(int _fileType, bool _preprocBlockIndent, bool _preprocDefineIndent, bool _emptyLineFill, - vector* >* _indentableMacros) + std::vector* >* _indentableMacros) { // formatting variables from ASFormatter and ASBeautifier ASBase::init(_fileType); @@ -84,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; @@ -125,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); } @@ -135,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); } @@ -150,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++) @@ -171,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); @@ -188,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; @@ -236,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) @@ -276,15 +276,15 @@ 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; @@ -325,15 +325,15 @@ 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; @@ -374,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] == '{'); @@ -446,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 @@ -516,7 +516,7 @@ void ASEnhancer::parseCurrentLine(string& line, bool isInPreprocessor, bool isIn 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; @@ -537,7 +537,7 @@ void ASEnhancer::parseCurrentLine(string& line, bool isInPreprocessor, bool isIn 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; @@ -555,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; @@ -619,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; @@ -637,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); @@ -712,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; @@ -726,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) diff --git a/AStyle/src/ASFormatter.cpp b/AStyle/src/ASFormatter.cpp index 3a8b848..ab9bb86 100644 --- a/AStyle/src/ASFormatter.cpp +++ b/AStyle/src/ASFormatter.cpp @@ -41,7 +41,7 @@ ASFormatter::ASFormatter() referenceAlignment = REF_SAME_AS_PTR; objCColonPadMode = COLON_PAD_NO_CHANGE; lineEnd = LINEEND_DEFAULT; - maxCodeLength = string::npos; + maxCodeLength = std::string::npos; isInStruct = false; shouldPadCommas = false; shouldPadOperators = false; @@ -85,18 +85,18 @@ ASFormatter::ASFormatter() shouldPadParamType = false; shouldUnPadParamType = false; - // initialize ASFormatter member vectors + // initialize ASFormatter member std::vectors formatterFileType = INVALID_TYPE; // reset to an invalid type - headers = new vector; - nonParenHeaders = new vector; - preDefinitionHeaders = new vector; - preCommandHeaders = new vector; - operators = new vector; - assignmentOperators = new vector; - castOperators = new vector; + headers = new std::vector; + nonParenHeaders = new std::vector; + preDefinitionHeaders = new std::vector; + preCommandHeaders = new std::vector; + operators = new std::vector; + assignmentOperators = new std::vector; + castOperators = new std::vector; - // initialize ASEnhancer member vectors - indentableMacros = new vector* >; + // initialize ASEnhancer member std::vectors + indentableMacros = new std::vector* >; } /** @@ -104,14 +104,14 @@ ASFormatter::ASFormatter() */ ASFormatter::~ASFormatter() { - // delete ASFormatter stack vectors + // delete ASFormatter stack std::vectors deleteContainer(preBraceHeaderStack); deleteContainer(braceTypeStack); deleteContainer(parenStack); deleteContainer(structStack); deleteContainer(questionMarkStack); - // delete ASFormatter member vectors + // delete ASFormatter member std::vectors formatterFileType = INVALID_TYPE; // reset to an invalid type delete headers; delete nonParenHeaders; @@ -121,11 +121,11 @@ ASFormatter::~ASFormatter() delete assignmentOperators; delete castOperators; - // delete ASEnhancer member vectors + // delete ASEnhancer member std::vectors delete indentableMacros; // must be done when the ASFormatter object is deleted (not ASBeautifier) - // delete ASBeautifier member vectors + // delete ASBeautifier member std::vectors ASBeautifier::deleteBeautifierVectors(); delete enhancer; @@ -160,12 +160,12 @@ void ASFormatter::init(ASSourceIterator* si) getEmptyLineFill(), indentableMacros); - initContainer(preBraceHeaderStack, new vector); - initContainer(parenStack, new vector); - initContainer(structStack, new vector); - initContainer(questionMarkStack, new vector); + initContainer(preBraceHeaderStack, new std::vector); + initContainer(parenStack, new std::vector); + initContainer(structStack, new std::vector); + initContainer(questionMarkStack, new std::vector); parenStack->emplace_back(0); // parenStack must contain this default entry - initContainer(braceTypeStack, new vector); + initContainer(braceTypeStack, new std::vector); braceTypeStack->emplace_back(NULL_TYPE); // braceTypeStack must contain this default entry clearFormattedLineSplitPoints(); @@ -183,15 +183,15 @@ void ASFormatter::init(ASSourceIterator* si) charNum = 0; checksumIn = 0; checksumOut = 0; - currentLineFirstBraceNum = string::npos; + currentLineFirstBraceNum = std::string::npos; formattedLineCommentNum = 0; leadingSpaces = 0; - previousReadyFormattedLineLength = string::npos; + previousReadyFormattedLineLength = std::string::npos; preprocBraceTypeStackSize = 0; spacePadNum = 0; - methodAttachCharNum = string::npos; + methodAttachCharNum = std::string::npos; methodAttachLineNum = 0; - methodBreakCharNum = string::npos; + methodBreakCharNum = std::string::npos; methodBreakLineNum = 0; nextLineSpacePadNum = 0; objCColonAlign = 0; @@ -309,7 +309,7 @@ void ASFormatter::init(ASSourceIterator* si) } /** - * build vectors for each programing language + * build std::vectors for each programing language * depending on the file extension. */ void ASFormatter::buildLanguageVectors() @@ -469,9 +469,9 @@ void ASFormatter::fixOptionVariableConflicts() * * @return formatted line. */ -string ASFormatter::nextLine() +std::string ASFormatter::nextLine() { - const string* newHeader = nullptr; + const std::string* newHeader = nullptr; isInVirginLine = isVirgin; isCharImmediatelyPostComment = false; isPreviousCharPostComment = false; @@ -517,7 +517,7 @@ string ASFormatter::nextLine() } if ((lineIsLineCommentOnly || lineIsCommentOnly) - && currentLine.find("*INDENT-ON*", charNum) != string::npos + && currentLine.find("*INDENT-ON*", charNum) != std::string::npos && isFormattingModeOff) { isFormattingModeOff = false; @@ -534,7 +534,7 @@ string ASFormatter::nextLine() continue; } if ((lineIsLineCommentOnly || lineIsCommentOnly) - && currentLine.find("*INDENT-OFF*", charNum) != string::npos) + && currentLine.find("*INDENT-OFF*", charNum) != std::string::npos) { isFormattingModeOff = true; if (isInLineBreak) // is true if not the first line @@ -607,7 +607,7 @@ string ASFormatter::nextLine() isInContinuedPreProc = currentLine[currentLine.size() - 1] == '\\'; /* - string preproc = trim(currentLine.c_str() + charNum + 1); + std::string preproc = trim(currentLine.c_str() + charNum + 1); if (preproc.length() > 0 && isCharPotentialHeader(preproc, 0) && getFileType() != C_TYPE @@ -691,7 +691,7 @@ string ASFormatter::nextLine() && sourceIterator->tellg() > preprocBlockEnd) { // indent the #if preprocessor blocks - string preproc = ASBeautifier::extractPreprocessorStatement(currentLine); + std::string preproc = ASBeautifier::extractPreprocessorStatement(currentLine); if (preproc.length() >= 2 && preproc.substr(0, 2) == "if") // #if, #ifdef, #ifndef { if (isImmediatelyPostPreprocessor) @@ -705,7 +705,7 @@ string ASFormatter::nextLine() && isWhiteSpace(currentLine[charNum + 1])) { size_t nextText = currentLine.find_first_not_of(" \t", charNum + 1); - if (nextText != string::npos) + if (nextText != std::string::npos) currentLine.erase(charNum + 1, nextText - charNum - 1); } if (isIndentablePreprocessorBlck @@ -778,7 +778,7 @@ string ASFormatter::nextLine() if (bracesAdded && !shouldAddOneLineBraces) { size_t firstText = currentLine.find_first_not_of(" \t"); - assert(firstText != string::npos); + assert(firstText != std::string::npos); if ((int) firstText == charNum || shouldBreakOneLineHeaders) breakCurrentOneLineBlock = true; } @@ -794,7 +794,7 @@ string ASFormatter::nextLine() spacePadNum--; else if (shouldBreakOneLineBlocks || (currentLineBeginsWithBrace - && currentLine.find_first_not_of(" \t") != string::npos)) + && currentLine.find_first_not_of(" \t") != std::string::npos)) shouldBreakLineAtNextChar = true; continue; } @@ -807,7 +807,7 @@ string ASFormatter::nextLine() && !isBeforeAnyComment() && (shouldBreakOneLineStatements || !isHeaderInMultiStatementLine)) { - string nextText = peekNextText(currentLine.substr(charNum)); + std::string nextText = peekNextText(currentLine.substr(charNum)); if (nextText.length() > 0 && isCharPotentialHeader(nextText, 0) && ASBase::findHeader(nextText, 0, headers) == &AS_IF) @@ -837,7 +837,7 @@ string ASFormatter::nextLine() } else if (currentHeader == &AS_ELSE) { - string nextText = peekNextText(currentLine.substr(charNum), true); + std::string nextText = peekNextText(currentLine.substr(charNum), true); if (nextText.length() > 0 && ((isCharPotentialHeader(nextText, 0) && ASBase::findHeader(nextText, 0, headers) != &AS_IF) @@ -862,12 +862,12 @@ string ASFormatter::nextLine() if (isBraceType(braceTypeStack->back(), SINGLE_LINE_TYPE)) { size_t blockEnd = currentLine.rfind(AS_CLOSE_BRACE); - assert(blockEnd != string::npos); + assert(blockEnd != std::string::npos); // move ending comments to this formattedLine if (isBeforeAnyLineEndComment(blockEnd)) { size_t commentStart = currentLine.find_first_not_of(" \t", blockEnd + 1); - assert(commentStart != string::npos); + assert(commentStart != std::string::npos); assert((currentLine.compare(commentStart, 2, "//") == 0) || (currentLine.compare(commentStart, 2, "/*") == 0)); formattedLine.append(getIndentLength() - 1, ' '); @@ -891,7 +891,7 @@ string ASFormatter::nextLine() } isInExecSQL = false; shouldReparseCurrentChar = true; - if (formattedLine.find_first_not_of(" \t") != string::npos) + if (formattedLine.find_first_not_of(" \t") != std::string::npos) isInLineBreak = true; if (needHeaderOpeningBrace) { @@ -907,7 +907,7 @@ string ASFormatter::nextLine() passedColon = false; if (parenStack->back() == 0 && !isBeforeAnyComment() - && (formattedLine.find_first_not_of(" \t") != string::npos)) + && (formattedLine.find_first_not_of(" \t") != std::string::npos)) { shouldReparseCurrentChar = true; isInLineBreak = true; @@ -926,7 +926,7 @@ string ASFormatter::nextLine() { if ((size_t) charNum == methodBreakCharNum) isInLineBreak = true; - methodBreakCharNum = string::npos; + methodBreakCharNum = std::string::npos; methodBreakLineNum = 0; } // Check for attach return type @@ -969,14 +969,14 @@ string ASFormatter::nextLine() else formattedLine.append(1, ' '); } - methodAttachCharNum = string::npos; + methodAttachCharNum = std::string::npos; methodAttachLineNum = 0; } // handle parens if (currentChar == '(' || currentChar == '[' || (isInTemplate && currentChar == '<')) { - // do not use emplace_back on vector until supported by macOS + // do not use emplace_back on std::vector until supported by macOS questionMarkStack->push_back(foundQuestionMark); foundQuestionMark = false; parenStack->back()++; @@ -1061,18 +1061,18 @@ string ASFormatter::nextLine() shouldKeepLineUnbroken = false; returnTypeChecked = false; objCColonAlign = 0; - //assert(methodBreakCharNum == string::npos); // comment out + //assert(methodBreakCharNum == std::string::npos); // comment out //assert(methodBreakLineNum == 0); // comment out - methodBreakCharNum = string::npos; + methodBreakCharNum = std::string::npos; methodBreakLineNum = 0; - methodAttachCharNum = string::npos; + methodAttachCharNum = std::string::npos; methodAttachLineNum = 0; isPreviousBraceBlockRelated = !isBraceType(newBraceType, ARRAY_TYPE); braceTypeStack->emplace_back(newBraceType); preBraceHeaderStack->emplace_back(currentHeader); currentHeader = nullptr; - // do not use emplace_back on vector until supported by macOS + // do not use emplace_back on std::vector until supported by macOS structStack->push_back(isInIndentableStruct); if (isBraceType(newBraceType, STRUCT_TYPE) && isCStyle()) isInIndentableStruct = isStructAccessModified(currentLine, charNum); @@ -1251,7 +1251,7 @@ string ASFormatter::nextLine() if (isCStyle() && (newHeader == &AS_FOREVER || newHeader == &AS_FOREACH)) { - if (currentLine.find_first_of("=;", charNum) != string::npos) + if (currentLine.find_first_of("=;", charNum) != std::string::npos) newHeader = nullptr; } if (isJavaStyle() @@ -1286,7 +1286,7 @@ string ASFormatter::nextLine() isAppendPostBlockEmptyLineRequested = false; } - const string* previousHeader = currentHeader; + const std::string* previousHeader = currentHeader; currentHeader = newHeader; needHeaderOpeningBrace = true; @@ -1297,7 +1297,7 @@ string ASFormatter::nextLine() { // if breaking lines, break the line at the header // except for multiple 'case' statements on a line - if (maxCodeLength != string::npos + if (maxCodeLength != std::string::npos && previousHeader != &AS_CASE) isInLineBreak = true; else @@ -1338,7 +1338,7 @@ string ASFormatter::nextLine() { // 'else' must be last thing on the line size_t start = formattedLine.length() >= 6 ? formattedLine.length() - 6 : 0; - if (formattedLine.find(AS_ELSE, start) != string::npos) + if (formattedLine.find(AS_ELSE, start) != std::string::npos) { appendSpacePad(); isInLineBreak = false; @@ -1459,11 +1459,11 @@ string ASFormatter::nextLine() if (currentChar == ';') { squareBracketCount = 0; - //assert(methodBreakCharNum == string::npos); // comment out + //assert(methodBreakCharNum == std::string::npos); // comment out //assert(methodBreakLineNum == 0); // comment out - methodBreakCharNum = string::npos; + methodBreakCharNum = std::string::npos; methodBreakLineNum = 0; - methodAttachCharNum = string::npos; + methodAttachCharNum = std::string::npos; methodAttachLineNum = 0; if (((shouldBreakOneLineStatements @@ -1584,7 +1584,7 @@ string ASFormatter::nextLine() if (findKeyword(currentLine, charNum, AS_ENUM)) { size_t firstNum = currentLine.find_first_of("(){},/"); - if (firstNum == string::npos + if (firstNum == std::string::npos || currentLine[firstNum] == '{' || currentLine[firstNum] == '/') isInEnum = true; @@ -1594,7 +1594,7 @@ string ASFormatter::nextLine() { size_t firstNum = currentLine.find_first_of("(){},/"); - if (firstNum == string::npos + if (firstNum == std::string::npos || currentLine[firstNum] == '{' || currentLine[firstNum] == '/') { @@ -1613,7 +1613,8 @@ string ASFormatter::nextLine() if (isCStyle() && findKeyword(currentLine, charNum, AS_AUTO) && (isBraceType(braceTypeStack->back(), NULL_TYPE) - || isBraceType(braceTypeStack->back(), DEFINITION_TYPE))) + || isBraceType(braceTypeStack->back(), DEFINITION_TYPE)) + && (currentLine.find("(") != std::string::npos)) // #516 auto array initializer with braces should not be blocks foundTrailingReturnType = true; // check for break/attach return type @@ -1680,7 +1681,7 @@ string ASFormatter::nextLine() isSharpDelegate = true; // append the entire name - string name = getCurrentWord(currentLine, charNum); + std::string name = getCurrentWord(currentLine, charNum); // must pad the 'and' and 'or' operators if required if (name == "and" || name == "or") { @@ -1721,7 +1722,7 @@ string ASFormatter::nextLine() && isBraceType(braceTypeStack->back(), NULL_TYPE)) { isInObjCInterface = true; - string name = '@' + AS_INTERFACE; + std::string name = '@' + AS_INTERFACE; appendSequence(name); goForward(name.length() - 1); continue; @@ -1734,7 +1735,7 @@ string ASFormatter::nextLine() && findKeyword(currentLine, charNum + 1, AS_SELECTOR)) { isInObjCSelector = true; - string name = '@' + AS_SELECTOR; + std::string name = '@' + AS_SELECTOR; appendSequence(name); goForward(name.length() - 1); continue; @@ -1834,7 +1835,7 @@ string ASFormatter::nextLine() { const size_t len = formattedLine.length(); size_t lastText = formattedLine.find_last_not_of(' '); - if (lastText != string::npos && lastText < len - 1) + if (lastText != std::string::npos && lastText < len - 1) { formattedLine.resize(lastText + 1); int size_diff = len - (lastText + 1); @@ -1918,7 +1919,7 @@ string ASFormatter::nextLine() // return a beautified (i.e. correctly indented) line. - string beautifiedLine; + std::string beautifiedLine; size_t readyFormattedLineLength = trim(readyFormattedLine).length(); bool isInNamespace = isBraceType(braceTypeStack->back(), NAMESPACE_TYPE); @@ -2503,7 +2504,7 @@ char ASFormatter::peekNextChar() const char ch = ' '; size_t peekNum = currentLine.find_first_not_of(" \t", charNum + 1); - if (peekNum == string::npos) + if (peekNum == std::string::npos) return ch; ch = currentLine[peekNum]; @@ -2521,7 +2522,7 @@ bool ASFormatter::isBeforeComment() const bool foundComment = false; size_t peekNum = currentLine.find_first_not_of(" \t", charNum + 1); - if (peekNum == string::npos) + if (peekNum == std::string::npos) return foundComment; foundComment = (currentLine.compare(peekNum, 2, "/*") == 0); @@ -2539,7 +2540,7 @@ bool ASFormatter::isBeforeAnyComment() const bool foundComment = false; size_t peekNum = currentLine.find_first_not_of(" \t", charNum + 1); - if (peekNum == string::npos) + if (peekNum == std::string::npos) return foundComment; foundComment = (currentLine.compare(peekNum, 2, "/*") == 0 @@ -2559,7 +2560,7 @@ bool ASFormatter::isBeforeAnyLineEndComment(int startPos) const bool foundLineEndComment = false; size_t peekNum = currentLine.find_first_not_of(" \t", startPos + 1); - if (peekNum != string::npos) + if (peekNum != std::string::npos) { if (currentLine.compare(peekNum, 2, "//") == 0) foundLineEndComment = true; @@ -2567,10 +2568,10 @@ bool ASFormatter::isBeforeAnyLineEndComment(int startPos) const { // comment must be closed on this line with nothing after it size_t endNum = currentLine.find("*/", peekNum + 2); - if (endNum != string::npos) + if (endNum != std::string::npos) { size_t nextChar = currentLine.find_first_not_of(" \t", endNum + 2); - if (nextChar == string::npos) + if (nextChar == std::string::npos) foundLineEndComment = true; } } @@ -2588,16 +2589,16 @@ bool ASFormatter::isBeforeMultipleLineEndComments(int startPos) const bool foundMultipleLineEndComment = false; size_t peekNum = currentLine.find_first_not_of(" \t", startPos + 1); - if (peekNum != string::npos) + if (peekNum != std::string::npos) { if (currentLine.compare(peekNum, 2, "/*") == 0) { // comment must be closed on this line with nothing after it size_t endNum = currentLine.find("*/", peekNum + 2); - if (endNum != string::npos) + if (endNum != std::string::npos) { size_t nextChar = currentLine.find_first_not_of(" \t", endNum + 2); - if (nextChar != string::npos + if (nextChar != std::string::npos && currentLine.compare(nextChar, 2, "//") == 0) foundMultipleLineEndComment = true; } @@ -2681,7 +2682,7 @@ bool ASFormatter::getNextLine(bool emptyLineWasDeleted /*false*/) if (currentLine.length() == 0) { isInContinuedPreProc = false; - currentLine = string(" "); // a null is inserted if this is not done + currentLine = std::string(" "); // a null is inserted if this is not done } if (methodBreakLineNum > 0) @@ -2799,7 +2800,7 @@ void ASFormatter::initNewLine() doesLineStartComment = false; currentLineBeginsWithBrace = false; lineIsEmpty = false; - currentLineFirstBraceNum = string::npos; + currentLineFirstBraceNum = std::string::npos; tabIncrementIn = 0; // bypass whitespace at the start of a line @@ -2816,7 +2817,7 @@ void ASFormatter::initNewLine() { doesLineStartComment = true; if ((int) currentLine.length() > charNum + 2 - && currentLine.find("*/", charNum + 2) != string::npos) + && currentLine.find("*/", charNum + 2) != std::string::npos) lineIsCommentOnly = true; } else if (isSequenceReached("//")) @@ -2828,7 +2829,7 @@ void ASFormatter::initNewLine() currentLineBeginsWithBrace = true; currentLineFirstBraceNum = charNum; size_t firstText = currentLine.find_first_not_of(" \t", charNum + 1); - if (firstText != string::npos) + if (firstText != std::string::npos) { if (currentLine.compare(firstText, 2, "//") == 0) lineIsLineCommentOnly = true; @@ -2876,7 +2877,7 @@ void ASFormatter::appendChar(char ch, bool canBreakLine) formattedLine.append(1, ch); isImmediatelyPostCommentOnly = false; - if (maxCodeLength != string::npos) + if (maxCodeLength != std::string::npos) { // These compares reduce the frequency of function calls. if (isOkToSplitFormattedLine()) @@ -2887,14 +2888,14 @@ void ASFormatter::appendChar(char ch, bool canBreakLine) } /** - * Append a string sequence to the current formatted line. + * Append a std::string sequence to the current formatted line. * The formattedLine split points are NOT updated. * But the formattedLine is checked for time to split. * * @param sequence the sequence to append. * @param canBreakLine if true, a registered line-break */ -void ASFormatter::appendSequence(const string& sequence, bool canBreakLine) +void ASFormatter::appendSequence(const std::string& sequence, bool canBreakLine) { if (canBreakLine && isInLineBreak) breakLine(); @@ -2910,12 +2911,12 @@ void ASFormatter::appendSequence(const string& sequence, bool canBreakLine) * @param sequence the sequence to append. * @param canBreakLine if true, a registered line-break */ -void ASFormatter::appendOperator(const string& sequence, bool canBreakLine) +void ASFormatter::appendOperator(const std::string& sequence, bool canBreakLine) { if (canBreakLine && isInLineBreak) breakLine(); formattedLine.append(sequence); - if (maxCodeLength != string::npos) + if (maxCodeLength != std::string::npos) { // These compares reduce the frequency of function calls. if (isOkToSplitFormattedLine()) @@ -2936,7 +2937,7 @@ void ASFormatter::appendSpacePad() { formattedLine.append(1, ' '); spacePadNum++; - if (maxCodeLength != string::npos) + if (maxCodeLength != std::string::npos) { // These compares reduce the frequency of function calls. if (isOkToSplitFormattedLine()) @@ -2958,7 +2959,7 @@ void ASFormatter::appendSpaceAfter() { formattedLine.append(1, ' '); spacePadNum++; - if (maxCodeLength != string::npos) + if (maxCodeLength != std::string::npos) { // These compares reduce the frequency of function calls. if (isOkToSplitFormattedLine()) @@ -2985,7 +2986,7 @@ void ASFormatter::breakLine(bool isSplitLine /*false*/) if (!isSplitLine) { - formattedLineCommentNum = string::npos; + formattedLineCommentNum = std::string::npos; clearFormattedLineSplitPoints(); if (isAppendPostBlockEmptyLineRequested) @@ -3098,7 +3099,7 @@ BraceType ASFormatter::getBraceType() return returnVal; } -bool ASFormatter::isNumericVariable(const string& word) const +bool ASFormatter::isNumericVariable(const std::string& word) const { if (word == "bool" || word == "int" @@ -3169,9 +3170,9 @@ bool ASFormatter::isClassInitializer() const * * @return whether line is empty */ -bool ASFormatter::isEmptyLine(const string& line) const +bool ASFormatter::isEmptyLine(const std::string& line) const { - return line.find_first_not_of(" \t") == string::npos; + return line.find_first_not_of(" \t") == std::string::npos; } /** @@ -3184,10 +3185,10 @@ bool ASFormatter::isExternC() const // charNum should be at 'extern' assert(!isWhiteSpace(currentLine[charNum])); size_t startQuote = currentLine.find_first_of(" \t\"", charNum); - if (startQuote == string::npos) + if (startQuote == std::string::npos) return false; startQuote = currentLine.find_first_not_of(" \t", startQuote); - if (startQuote == string::npos) + if (startQuote == std::string::npos) return false; if (currentLine.compare(startQuote, 3, "\"C\"") != 0) return false; @@ -3214,12 +3215,12 @@ bool ASFormatter::isPointerOrReference() const return false; // get the last legal word (may be a number) - string lastWord = getPreviousWord(currentLine, charNum); + std::string lastWord = getPreviousWord(currentLine, charNum); if (lastWord.empty()) lastWord = " "; // check for preceding or following numeric values - string nextText = peekNextText(currentLine.substr(charNum + 1)); + std::string nextText = peekNextText(currentLine.substr(charNum + 1)); if (nextText.length() == 0) nextText = " "; if (isDigit(lastWord[0]) @@ -3254,7 +3255,7 @@ bool ASFormatter::isPointerOrReference() const return true; if (previousNonWSChar == '>') return true; - string followingText; + std::string followingText; if ((int) currentLine.length() > charNum + 2) followingText = peekNextText(currentLine.substr(charNum + 2)); if (followingText.length() > 0 && followingText[0] == ')') @@ -3293,7 +3294,7 @@ bool ASFormatter::isPointerOrReference() const { // if followed by an assignment it is a pointer or reference // if followed by semicolon it is a pointer or reference in range-based for - const string* followingOperator = getFollowingOperator(); + const std::string* followingOperator = getFollowingOperator(); if (followingOperator != nullptr && followingOperator != &AS_MULT && followingOperator != &AS_BIT_AND) @@ -3324,7 +3325,7 @@ bool ASFormatter::isPointerOrReference() const || nextChar == '+') { size_t nextNum = currentLine.find_first_not_of(" \t", charNum + 1); - if (nextNum != string::npos) + if (nextNum != std::string::npos) { if (currentLine.compare(nextNum, 2, "++") != 0 && currentLine.compare(nextNum, 2, "--") != 0) @@ -3406,7 +3407,7 @@ bool ASFormatter::isDereferenceOrAddressOf() const || parenStack->back() != 0)) return true; - string nextText = peekNextText(currentLine.substr(charNum + 1)); + std::string nextText = peekNextText(currentLine.substr(charNum + 1)); if (nextText.length() > 0) { if (nextText[0] == ')' || nextText[0] == '>' @@ -3423,7 +3424,7 @@ bool ASFormatter::isDereferenceOrAddressOf() const if (!isBraceType(braceTypeStack->back(), COMMAND_TYPE) && parenStack->back() == 0) return false; - string lastWord = getPreviousWord(currentLine, charNum); + std::string lastWord = getPreviousWord(currentLine, charNum); if (lastWord == "else" || lastWord == "delete") return true; if (isPointerOrReferenceVariable(lastWord)) @@ -3488,12 +3489,12 @@ bool ASFormatter::isPointerOrReferenceCentered() const * * @return whether word is a pointer or reference variable. */ -bool ASFormatter::isPointerOrReferenceVariable(const string& word) const +bool ASFormatter::isPointerOrReferenceVariable(const std::string& word) const { assert(currentChar == '*' || currentChar == '&' || currentChar == '^'); bool retval = false; if (word == "char" - || word == "string" + || word == "std::string" || word == "String" || word == "NSString" || word == "int" @@ -3504,13 +3505,13 @@ bool ASFormatter::isPointerOrReferenceVariable(const string& word) const || word == "VOID") retval = true; - // check for C# object type "x is string" + // check for C# object type "x is std::string" if (retval && isSharpStyle()) { // find the word previous to the 'word' parameter - string prevWord; + std::string prevWord; size_t wordStart = currentLine.rfind(word, charNum); - if (wordStart != string::npos) + if (wordStart != std::string::npos) prevWord = getPreviousWord(currentLine, wordStart); if (prevWord == "is") retval = false; @@ -3523,16 +3524,16 @@ bool ASFormatter::isPointerOrReferenceVariable(const string& word) const * * @return true if a pointer *. */ -bool ASFormatter::isPointerToPointer(const string& line, int currPos) const +bool ASFormatter::isPointerToPointer(const std::string& line, int currPos) const { assert(line[currPos] == '*' && peekNextChar() == '*'); if ((int) line.length() > currPos + 1 && line[currPos + 1] == '*') return true; size_t nextText = line.find_first_not_of(" \t", currPos + 1); - if (nextText == string::npos || line[nextText] != '*') + if (nextText == std::string::npos || line[nextText] != '*') return false; size_t nextText2 = line.find_first_not_of(" \t", nextText + 1); - if (nextText == string::npos) + if (nextText == std::string::npos) return false; if (line[nextText2] == ')' || line[nextText2] == '*') return true; @@ -3556,14 +3557,14 @@ bool ASFormatter::isUnaryOperator() const if (!isdigit(peekNextChar())) return false; size_t end = currentLine.rfind(')', charNum); - if (end == string::npos) + if (end == std::string::npos) return false; size_t lastChar = currentLine.find_last_not_of(" \t", end - 1); - if (lastChar == string::npos) + if (lastChar == std::string::npos) return false; if (currentLine[lastChar] == '*') end = lastChar; - string prevWord = getPreviousWord(currentLine, end); + std::string prevWord = getPreviousWord(currentLine, end); if (prevWord.empty()) return false; if (!isNumericVariable(prevWord)) @@ -3650,7 +3651,7 @@ bool ASFormatter::isNonInStatementArrayBrace() const * 2 = one-line block has been reached and is followed by a comma. * 3 = one-line block has been reached and is an empty block. */ -int ASFormatter::isOneLineBlockReached(const string& line, int startChar) const +int ASFormatter::isOneLineBlockReached(const std::string& line, int startChar) const { assert(line[startChar] == '{'); @@ -3718,7 +3719,7 @@ int ASFormatter::isOneLineBlockReached(const string& line, int startChar) const if (parenStack->back() == 0 && prevCh != '}') { size_t peekNum = line.find_first_not_of(" \t", i + 1); - if (peekNum != string::npos && line[peekNum] == ',') + if (peekNum != std::string::npos && line[peekNum] == ',') return 2; } if (!hasText) @@ -3748,7 +3749,7 @@ int ASFormatter::isOneLineBlockReached(const string& line, int startChar) const bool ASFormatter::isNextWordSharpNonParenHeader(int startChar) const { // look ahead to find the next non-comment text - string nextText = peekNextText(currentLine.substr(startChar)); + std::string nextText = peekNextText(currentLine.substr(startChar)); if (nextText.length() == 0) return false; if (nextText[0] == '[') @@ -3772,7 +3773,7 @@ bool ASFormatter::isNextWordSharpNonParenHeader(int startChar) const bool ASFormatter::isNextCharOpeningBrace(int startChar) const { bool retVal = false; - string nextText = peekNextText(currentLine.substr(startChar)); + std::string nextText = peekNextText(currentLine.substr(startChar)); if (nextText.length() > 0 && nextText.compare(0, 1, "{") == 0) retVal = true; @@ -3788,21 +3789,21 @@ bool ASFormatter::isNextCharOpeningBrace(int startChar) const bool ASFormatter::isOperatorPaddingDisabled() const { size_t commentStart = currentLine.find("//", charNum); - if (commentStart == string::npos) + if (commentStart == std::string::npos) { commentStart = currentLine.find("/*", charNum); // comment must end on this line - if (commentStart != string::npos) + if (commentStart != std::string::npos) { size_t commentEnd = currentLine.find("*/", commentStart + 2); - if (commentEnd == string::npos) - commentStart = string::npos; + if (commentEnd == std::string::npos) + commentStart = std::string::npos; } } - if (commentStart == string::npos) + if (commentStart == std::string::npos) return false; size_t noPadStart = currentLine.find("*NOPAD*", commentStart); - if (noPadStart == string::npos) + if (noPadStart == std::string::npos) return false; return true; } @@ -3897,22 +3898,22 @@ bool ASFormatter::isMultiStatementLine() const } /** - * get the next non-whitespace substring on following lines, bypassing all comments. + * get the next non-whitespace substd::string on following lines, bypassing all comments. * * @param firstLine the first line to check - * @return the next non-whitespace substring. + * @return the next non-whitespace substd::string. */ -string ASFormatter::peekNextText(const string& firstLine, +std::string ASFormatter::peekNextText(const std::string& firstLine, bool endOnEmptyLine /*false*/, - const shared_ptr& streamArg /*nullptr*/) const + const std::shared_ptr& streamArg /*nullptr*/) const { assert(sourceIterator->getPeekStart() == 0 || streamArg != nullptr); // Borland may need != 0 bool isFirstLine = true; - string nextLine_ = firstLine; - size_t firstChar = string::npos; - shared_ptr stream = streamArg; + std::string nextLine_ = firstLine; + size_t firstChar = std::string::npos; + std::shared_ptr stream = streamArg; if (stream == nullptr) // Borland may need == 0 - stream = make_shared(sourceIterator); + stream = std::make_shared(sourceIterator); // find the first non-blank text, bypassing all comments. bool isInComment_ = false; @@ -3924,7 +3925,7 @@ string ASFormatter::peekNextText(const string& firstLine, nextLine_ = stream->peekNextLine(); firstChar = nextLine_.find_first_not_of(" \t"); - if (firstChar == string::npos) + if (firstChar == std::string::npos) { if (endOnEmptyLine && !isInComment_) break; @@ -3940,12 +3941,12 @@ string ASFormatter::peekNextText(const string& firstLine, if (isInComment_) { firstChar = nextLine_.find("*/", firstChar); - if (firstChar == string::npos) + if (firstChar == std::string::npos) continue; firstChar += 2; isInComment_ = false; firstChar = nextLine_.find_first_not_of(" \t", firstChar); - if (firstChar == string::npos) + if (firstChar == std::string::npos) continue; } @@ -3956,7 +3957,7 @@ string ASFormatter::peekNextText(const string& firstLine, break; } - if (firstChar == string::npos) + if (firstChar == std::string::npos) nextLine_ = ""; else nextLine_ = nextLine_.substr(firstChar); @@ -3977,11 +3978,11 @@ void ASFormatter::adjustComments() if (isSequenceReached("/*")) { size_t endNum = currentLine.find("*/", charNum + 2); - if (endNum == string::npos) + if (endNum == std::string::npos) return; // following line comments may be a tag from AStyleWx //[[)> size_t nextNum = currentLine.find_first_not_of(" \t", endNum + 2); - if (nextNum != string::npos + if (nextNum != std::string::npos && currentLine.compare(nextNum, 2, "//") != 0) return; } @@ -4002,7 +4003,7 @@ void ASFormatter::adjustComments() { int adjust = spacePadNum; size_t lastText = formattedLine.find_last_not_of(' '); - if (lastText != string::npos + if (lastText != std::string::npos && lastText < len - adjust - 1) formattedLine.resize(len - adjust); else if (len > lastText + 2) @@ -4019,7 +4020,7 @@ void ASFormatter::adjustComments() */ void ASFormatter::appendCharInsideComments() { - if (formattedLineCommentNum == string::npos // does the comment start on the previous line? + if (formattedLineCommentNum == std::string::npos // does the comment start on the previous line? || formattedLineCommentNum == 0) { appendCurrentChar(); // don't attach @@ -4031,7 +4032,7 @@ void ASFormatter::appendCharInsideComments() // find the previous non space char size_t end = formattedLineCommentNum; size_t beg = formattedLine.find_last_not_of(" \t", end - 1); - if (beg == string::npos) + if (beg == std::string::npos) { appendCurrentChar(); // don't attach return; @@ -4059,7 +4060,7 @@ void ASFormatter::appendCharInsideComments() * * @param newOperator the operator to be padded */ -void ASFormatter::padOperators(const string* newOperator) +void ASFormatter::padOperators(const std::string* newOperator) { assert(shouldPadOperators); assert(newOperator != nullptr); @@ -4114,7 +4115,7 @@ void ASFormatter::padOperators(const string* newOperator) && !(newOperator == &AS_COLON && (!foundQuestionMark && !isInEnum) && currentHeader != &AS_FOR) && !(newOperator == &AS_QUESTION && isSharpStyle() // check for C# nullable type (e.g. int?) - && currentLine.find(':', charNum + 1) == string::npos) + && currentLine.find(':', charNum + 1) == std::string::npos) ) { appendSpacePad(); @@ -4166,7 +4167,7 @@ void ASFormatter::formatPointerOrReference() { ptrLength = 2; size_t nextChar = currentLine.find_first_not_of(" \t", charNum + 2); - if (nextChar == string::npos) + if (nextChar == std::string::npos) peekedChar = ' '; else peekedChar = currentLine[nextChar]; @@ -4224,7 +4225,7 @@ void ASFormatter::formatPointerOrReferenceToType() // do this before bumping charNum bool isOldPRCentered = isPointerOrReferenceCentered(); - string sequenceToInsert(1, currentChar); + std::string sequenceToInsert(1, currentChar); // get the sequence if (currentChar == peekNextChar()) { @@ -4240,7 +4241,7 @@ void ASFormatter::formatPointerOrReferenceToType() } } // append the sequence - string charSave; + std::string charSave; size_t prevCh = formattedLine.find_last_not_of(" \t"); if (prevCh < formattedLine.length()) { @@ -4271,7 +4272,7 @@ void ASFormatter::formatPointerOrReferenceToType() spacePadNum--; } // update the formattedLine split point - if (maxCodeLength != string::npos && formattedLine.length() > 0) + if (maxCodeLength != std::string::npos && formattedLine.length() > 0) { size_t index = formattedLine.length() - 1; if (isWhiteSpace(formattedLine[index])) @@ -4292,11 +4293,11 @@ void ASFormatter::formatPointerOrReferenceToMiddle() // compute current whitespace before size_t wsBefore = currentLine.find_last_not_of(" \t", charNum - 1); - if (wsBefore == string::npos) + if (wsBefore == std::string::npos) wsBefore = 0; else wsBefore = charNum - wsBefore - 1; - string sequenceToInsert(1, currentChar); + std::string sequenceToInsert(1, currentChar); if (currentChar == peekNextChar()) { for (size_t i = charNum + 1; currentLine.length() > i; i++) @@ -4333,7 +4334,7 @@ void ASFormatter::formatPointerOrReferenceToMiddle() bool isAfterScopeResolution = previousNonWSChar == ':'; size_t charNumSave = charNum; // if this is the last thing on the line - if (currentLine.find_first_not_of(" \t", charNum + 1) == string::npos) + if (currentLine.find_first_not_of(" \t", charNum + 1) == std::string::npos) { if (wsBefore == 0 && !isAfterScopeResolution) formattedLine.append(1, ' '); @@ -4353,7 +4354,7 @@ void ASFormatter::formatPointerOrReferenceToMiddle() } // find space padding after size_t wsAfter = currentLine.find_first_not_of(" \t", charNumSave + 1); - if (wsAfter == string::npos || isBeforeAnyComment()) + if (wsAfter == std::string::npos || isBeforeAnyComment()) wsAfter = 0; else wsAfter = wsAfter - charNumSave - 1; @@ -4394,10 +4395,10 @@ void ASFormatter::formatPointerOrReferenceToMiddle() spacePadNum += wsAfter; } // update the formattedLine split point after the pointer - if (maxCodeLength != string::npos && formattedLine.length() > 0) + if (maxCodeLength != std::string::npos && formattedLine.length() > 0) { size_t index = formattedLine.find_last_not_of(" \t"); - if (index != string::npos && (index < formattedLine.length() - 1)) + if (index != std::string::npos && (index < formattedLine.length() - 1)) { index++; updateFormattedLineSplitPointsPointerOrReference(index); @@ -4418,9 +4419,9 @@ void ASFormatter::formatPointerOrReferenceToName() bool isOldPRCentered = isPointerOrReferenceCentered(); size_t startNum = formattedLine.find_last_not_of(" \t"); - if (startNum == string::npos) + if (startNum == std::string::npos) startNum = 0; - string sequenceToInsert(1, currentChar); + std::string sequenceToInsert(1, currentChar); if (currentChar == peekNextChar()) { for (size_t i = charNum + 1; currentLine.length() > i; i++) @@ -4460,7 +4461,7 @@ void ASFormatter::formatPointerOrReferenceToName() { // empty parens don't count size_t start = currentLine.find_first_not_of("( \t", i); - if (start != string::npos && currentLine[start] != ')') + if (start != std::string::npos && currentLine[start] != ')') break; } goForward(1); @@ -4474,7 +4475,7 @@ void ASFormatter::formatPointerOrReferenceToName() if (isAfterScopeResolution) { size_t lastText = formattedLine.find_last_not_of(" \t"); - if (lastText != string::npos && lastText + 1 < formattedLine.length()) + if (lastText != std::string::npos && lastText + 1 < formattedLine.length()) formattedLine.erase(lastText + 1); } // if no space before * then add one @@ -4513,10 +4514,10 @@ void ASFormatter::formatPointerOrReferenceToName() } } // update the formattedLine split point - if (maxCodeLength != string::npos) + if (maxCodeLength != std::string::npos) { size_t index = formattedLine.find_last_of(" \t"); - if (index != string::npos + if (index != std::string::npos && index < formattedLine.length() - 1 && (formattedLine[index + 1] == '*' || formattedLine[index + 1] == '&' @@ -4545,7 +4546,7 @@ void ASFormatter::formatPointerOrReferenceCast() int itemAlignment = (currentChar == '*' || currentChar == '^') ? pa : ((ra == REF_SAME_AS_PTR) ? pa : ra); - string sequenceToInsert(1, currentChar); + std::string sequenceToInsert(1, currentChar); if (isSequenceReached("**") || isSequenceReached("&&")) { goForward(1); @@ -4559,7 +4560,7 @@ void ASFormatter::formatPointerOrReferenceCast() // remove preceding whitespace char prevCh = ' '; size_t prevNum = formattedLine.find_last_not_of(" \t"); - if (prevNum != string::npos) + if (prevNum != std::string::npos) { prevCh = formattedLine[prevNum]; if (itemAlignment == PTR_ALIGN_TYPE && currentChar == '*' && prevCh == '*') @@ -4587,7 +4588,7 @@ void ASFormatter::formatPointerOrReferenceCast() { appendSpacePad(); // in this case appendSpacePad may or may not update the split point - if (maxCodeLength != string::npos && formattedLine.length() > 0) + if (maxCodeLength != std::string::npos && formattedLine.length() > 0) updateFormattedLineSplitPointsPointerOrReference(formattedLine.length() - 1); appendSequence(sequenceToInsert, false); } @@ -4620,7 +4621,7 @@ void ASFormatter::padParens() char lastChar = ' '; bool prevIsParenHeader = false; size_t i = formattedLine.find_last_not_of(" \t"); - if (i != string::npos) + if (i != std::string::npos) { // if last char is a brace the previous whitespace is an indent if (formattedLine[i] == '{') @@ -4632,8 +4633,8 @@ void ASFormatter::padParens() spacesOutsideToDelete -= i; lastChar = formattedLine[i]; // if previous word is a header, it will be a paren header - string prevWord = getPreviousWord(formattedLine, formattedLine.length()); - const string* prevWordH = nullptr; + std::string prevWord = getPreviousWord(formattedLine, formattedLine.length()); + const std::string* prevWordH = nullptr; if (shouldPadHeader && prevWord.length() > 0 && isCharPotentialHeader(prevWord, 0)) @@ -4702,7 +4703,7 @@ void ASFormatter::padParens() if (shouldUnPadParens) { size_t j = currentLine.find_first_not_of(" \t", charNum + 1); - if (j != string::npos) + if (j != std::string::npos) spacesInsideToDelete = j - charNum - 1; if (shouldPadParensInside) spacesInsideToDelete--; @@ -4731,7 +4732,7 @@ void ASFormatter::padParens() { spacesInsideToDelete = formattedLine.length(); size_t i = formattedLine.find_last_not_of(" \t"); - if (i != string::npos) + if (i != std::string::npos) spacesInsideToDelete = formattedLine.length() - 1 - i; if (shouldPadParensInside) spacesInsideToDelete--; @@ -4755,7 +4756,7 @@ void ASFormatter::padParens() { //spacesOutsideToDelete = 0; //size_t j = currentLine.find_first_not_of(" \t", charNum + 1); - //if (j != string::npos) + //if (j != std::string::npos) // spacesOutsideToDelete = j - charNum - 1; //if (shouldPadParensOutside) // spacesOutsideToDelete--; @@ -4792,10 +4793,10 @@ void ASFormatter::padObjCMethodPrefix() assert(shouldPadMethodPrefix || shouldUnPadMethodPrefix); size_t prefix = formattedLine.find_first_of("+-"); - if (prefix == string::npos) + if (prefix == std::string::npos) return; size_t firstChar = formattedLine.find_first_not_of(" \t", prefix + 1); - if (firstChar == string::npos) + if (firstChar == std::string::npos) firstChar = formattedLine.length(); int spaces = firstChar - prefix - 1; @@ -4835,7 +4836,7 @@ void ASFormatter::padObjCReturnType() assert(shouldPadReturnType || shouldUnPadReturnType); size_t nextText = currentLine.find_first_not_of(" \t", charNum + 1); - if (nextText == string::npos) + if (nextText == std::string::npos) return; int spaces = nextText - charNum - 1; @@ -4889,9 +4890,9 @@ void ASFormatter::padObjCParamType() { // open paren has already been attached to formattedLine by padParen size_t paramOpen = formattedLine.rfind('('); - assert(paramOpen != string::npos); + assert(paramOpen != std::string::npos); size_t prevText = formattedLine.find_last_not_of(" \t", paramOpen - 1); - if (prevText == string::npos) + if (prevText == std::string::npos) return; int spaces = paramOpen - prevText - 1; @@ -4926,7 +4927,7 @@ void ASFormatter::padObjCParamType() else if (currentChar == ')') { size_t nextText = currentLine.find_first_not_of(" \t", charNum + 1); - if (nextText == string::npos) + if (nextText == std::string::npos) return; int spaces = nextText - charNum - 1; @@ -5176,7 +5177,7 @@ void ASFormatter::formatClosingBrace(BraceType braceType) if (currentHeader == &AS_CASE || currentHeader == &AS_DEFAULT) { // do not yet insert a line if "break" statement is outside the braces - string nextText = peekNextText(currentLine.substr(charNum + 1)); + std::string nextText = peekNextText(currentLine.substr(charNum + 1)); if (nextText.length() > 0 && nextText.substr(0, 5) != "break") isAppendPostBlockEmptyLineRequested = true; @@ -5375,7 +5376,7 @@ void ASFormatter::formatArrayBraces(BraceType braceType, bool isOpeningArrayBrac // must check if the block is still a single line because of anonymous statements if (!isBraceType(braceType, INIT_TYPE) && (!isBraceType(braceType, SINGLE_LINE_TYPE) - || formattedLine.find('{') == string::npos)) + || formattedLine.find('{') == std::string::npos)) breakLine(); appendCurrentChar(); } @@ -5403,11 +5404,11 @@ void ASFormatter::formatRunIn() // make sure the line begins with a brace size_t lastText = formattedLine.find_last_not_of(" \t"); - if (lastText == string::npos || formattedLine[lastText] != '{') + if (lastText == std::string::npos || formattedLine[lastText] != '{') return; // false; // make sure the brace is broken - if (formattedLine.find_first_not_of(" \t{") != string::npos) + if (formattedLine.find_first_not_of(" \t{") != std::string::npos) return; // false; if (isBraceType(braceTypeStack->back(), NAMESPACE_TYPE)) @@ -5455,7 +5456,7 @@ void ASFormatter::formatRunIn() isInLineBreak = false; // remove for extra whitespace if (formattedLine.length() > lastText + 1 - && formattedLine.find_first_not_of(" \t", lastText + 1) == string::npos) + && formattedLine.find_first_not_of(" \t", lastText + 1) == std::string::npos) formattedLine.erase(lastText + 1); if (extraHalfIndent) @@ -5467,7 +5468,7 @@ void ASFormatter::formatRunIn() else if (getForceTabIndentation() && getIndentLength() != getTabLength()) { // insert the space indents - string indent; + std::string indent; int indentLength_ = getIndentLength(); int tabLength_ = getTabLength(); indent.append(indentLength_, ' '); @@ -5513,16 +5514,16 @@ void ASFormatter::formatArrayRunIn() assert(isBraceType(braceTypeStack->back(), ARRAY_TYPE)); // make sure the brace is broken - if (formattedLine.find_first_not_of(" \t{") != string::npos) + if (formattedLine.find_first_not_of(" \t{") != std::string::npos) return; size_t lastText = formattedLine.find_last_not_of(" \t"); - if (lastText == string::npos || formattedLine[lastText] != '{') + if (lastText == std::string::npos || formattedLine[lastText] != '{') return; // check for extra whitespace if (formattedLine.length() > lastText + 1 - && formattedLine.find_first_not_of(" \t", lastText + 1) == string::npos) + && formattedLine.find_first_not_of(" \t", lastText + 1) == std::string::npos) formattedLine.erase(lastText + 1); if (getIndentString() == "\t") @@ -5541,10 +5542,10 @@ void ASFormatter::formatArrayRunIn() } /** - * delete a braceTypeStack vector object + * delete a braceTypeStack std::vector object * BraceTypeStack did not work with the DeleteContainer template */ -void ASFormatter::deleteContainer(vector*& container) +void ASFormatter::deleteContainer(std::vector*& container) { if (container != nullptr) { @@ -5555,9 +5556,9 @@ void ASFormatter::deleteContainer(vector*& container) } /** - * delete a vector object - * T is the type of vector - * used for all vectors except braceTypeStack + * delete a std::vector object + * T is the type of std::vector + * used for all std::vectors except braceTypeStack */ template void ASFormatter::deleteContainer(T& container) @@ -5571,10 +5572,10 @@ void ASFormatter::deleteContainer(T& container) } /** - * initialize a braceType vector object + * initialize a braceType std::vector object * braceType did not work with the DeleteContainer template */ -void ASFormatter::initContainer(vector*& container, vector* value) +void ASFormatter::initContainer(std::vector*& container, std::vector* value) { if (container != nullptr) deleteContainer(container); @@ -5582,15 +5583,15 @@ void ASFormatter::initContainer(vector*& container, vector } /** - * initialize a vector object - * T is the type of vector - * used for all vectors except braceTypeStack + * initialize a std::vector object + * T is the type of std::vector + * used for all std::vectors except braceTypeStack */ template void ASFormatter::initContainer(T& container, T value) { // since the ASFormatter object is never deleted, - // the existing vectors must be deleted before creating new ones + // the existing std::vectors must be deleted before creating new ones if (container != nullptr) deleteContainer(container); container = value; @@ -5642,7 +5643,7 @@ bool ASFormatter::isOkToBreakBlock(BraceType braceType) const /** * check if a sharp header is a paren or non-paren header */ -bool ASFormatter::isSharpStyleWithParen(const string* header) const +bool ASFormatter::isSharpStyleWithParen(const std::string* header) const { return (isSharpStyle() && peekNextChar() == '(' && (header == &AS_CATCH @@ -5654,7 +5655,7 @@ bool ASFormatter::isSharpStyleWithParen(const string* header) const * firstLine must contain the start of the comment. * return value is a pointer to the header or nullptr. */ -const string* ASFormatter::checkForHeaderFollowingComment(const string& firstLine) const +const std::string* ASFormatter::checkForHeaderFollowingComment(const std::string& firstLine) const { assert(isInComment || isInLineComment); assert(shouldBreakElseIfs || shouldBreakBlocks || isInSwitchStatement()); @@ -5662,7 +5663,7 @@ const string* ASFormatter::checkForHeaderFollowingComment(const string& firstLin bool endOnEmptyLine = (currentHeader == nullptr); if (isInSwitchStatement()) endOnEmptyLine = false; - string nextText = peekNextText(firstLine, endOnEmptyLine); + std::string nextText = peekNextText(firstLine, endOnEmptyLine); if (nextText.length() == 0 || !isCharPotentialHeader(nextText, 0)) return nullptr; @@ -5682,7 +5683,7 @@ void ASFormatter::processPreprocessor() assert(currentChar == '#'); const size_t preproc = currentLine.find_first_not_of(" \t", charNum + 1); - if (preproc == string::npos) + if (preproc == std::string::npos) return; if (currentLine.compare(preproc, 2, "if") == 0) @@ -5716,22 +5717,22 @@ bool ASFormatter::commentAndHeaderFollows() assert(shouldDeleteEmptyLines && shouldBreakBlocks); // is the next line a comment - auto stream = make_shared(sourceIterator); + auto stream = std::make_shared(sourceIterator); if (!stream->hasMoreLines()) return false; - string nextLine_ = stream->peekNextLine(); + std::string nextLine_ = stream->peekNextLine(); size_t firstChar = nextLine_.find_first_not_of(" \t"); - if (firstChar == string::npos + if (firstChar == std::string::npos || !(nextLine_.compare(firstChar, 2, "//") == 0 || nextLine_.compare(firstChar, 2, "/*") == 0)) return false; // find the next non-comment text, and reset - string nextText = peekNextText(nextLine_, false, stream); + std::string nextText = peekNextText(nextLine_, false, stream); if (nextText.length() == 0 || !isCharPotentialHeader(nextText, 0)) return false; - const string* newHeader = ASBase::findHeader(nextText, 0, headers); + const std::string* newHeader = ASBase::findHeader(nextText, 0, headers); if (newHeader == nullptr) return false; @@ -5897,7 +5898,7 @@ void ASFormatter::formatCommentOpener() // Check for a following header. // For speed do not check multiple comment lines more than once. // For speed do not check shouldBreakBlocks if previous line is empty, a comment, or a '{'. - const string* followingHeader = nullptr; + const std::string* followingHeader = nullptr; if ((doesLineStartComment && !isImmediatelyPostCommentOnly && isBraceType(braceTypeStack->back(), COMMAND_TYPE)) @@ -5991,7 +5992,7 @@ void ASFormatter::formatCommentCloser() appendSequence(AS_CLOSE_COMMENT); goForward(1); if (doesLineStartComment - && (currentLine.find_first_not_of(" \t", charNum + 1) == string::npos)) + && (currentLine.find_first_not_of(" \t", charNum + 1) == std::string::npos)) lineEndsInCommentOnly = true; if (peekNextChar() == '}' && previousCommandChar != ';' @@ -6054,7 +6055,7 @@ void ASFormatter::formatLineCommentOpener() // Check for a following header. // For speed do not check multiple comment lines more than once. // For speed do not check shouldBreakBlocks if previous line is empty, a comment, or a '{'. - const string* followingHeader = nullptr; + const std::string* followingHeader = nullptr; if ((lineIsLineCommentOnly && !isImmediatelyPostCommentOnly && isBraceType(braceTypeStack->back(), COMMAND_TYPE)) @@ -6192,7 +6193,7 @@ void ASFormatter::formatQuoteBody() { if (isCStyle()) { - string delim = ')' + verbatimDelimiter; + std::string delim = ')' + verbatimDelimiter; int delimStart = charNum - delim.length(); if (delimStart > 0 && currentLine.substr(delimStart, delim.length()) == delim) { @@ -6217,7 +6218,7 @@ void ASFormatter::formatQuoteBody() } else if (quoteChar == currentChar) { - ////do not quit if we have CS string with interpolation + ////do not quit if we have CS std::string with interpolation isInQuote = false; } @@ -6321,7 +6322,7 @@ int ASFormatter::getNextLineCommentAdjustment() if (charNum < 1) // "else" is in column 1 return 0; size_t lastBrace = currentLine.rfind('}', charNum - 1); - if (lastBrace != string::npos) + if (lastBrace != std::string::npos) return (lastBrace - charNum); // return a negative number return 0; } @@ -6345,7 +6346,7 @@ int ASFormatter::getCurrentLineCommentAdjustment() if (charNum < 1) return 2; size_t lastBrace = currentLine.rfind('}', charNum - 1); - if (lastBrace == string::npos) + if (lastBrace == std::string::npos) return 2; return 0; } @@ -6354,17 +6355,17 @@ int ASFormatter::getCurrentLineCommentAdjustment() * get the previous word on a line * the argument 'currPos' must point to the current position. * - * @return is the previous word or an empty string if none found. + * @return is the previous word or an empty std::string if none found. */ -string ASFormatter::getPreviousWord(const string& line, int currPos) const +std::string ASFormatter::getPreviousWord(const std::string& line, int currPos) const { // get the last legal word (may be a number) if (currPos == 0) - return string(); + return std::string(); size_t end = line.find_last_not_of(" \t", currPos - 1); - if (end == string::npos || !isLegalNameChar(line[end])) - return string(); + if (end == std::string::npos || !isLegalNameChar(line[end])) + return std::string(); int start; // start of the previous word for (start = end; start > -1; start--) @@ -6410,7 +6411,7 @@ void ASFormatter::isLineBreakBeforeClosingHeader() appendSpacePad(); // is closing brace broken? size_t i = currentLine.find_first_not_of(" \t"); - if (i != string::npos && currentLine[i] == '}') + if (i != std::string::npos && currentLine[i] == '}') isInLineBreak = false; if (shouldBreakBlocks) @@ -6444,7 +6445,7 @@ void ASFormatter::appendClosingHeader() bool previousLineIsEmpty = isEmptyLine(formattedLine); int previousLineIsOneLineBlock = 0; size_t firstBrace = findNextChar(formattedLine, '{'); - if (firstBrace != string::npos) + if (firstBrace != std::string::npos) previousLineIsOneLineBlock = isOneLineBlockReached(formattedLine, firstBrace); if (!previousLineIsEmpty && previousLineIsOneLineBlock == 0) @@ -6491,7 +6492,7 @@ bool ASFormatter::addBracesToStatement() size_t nextSemiColon = charNum; if (currentChar != ';') nextSemiColon = findNextChar(currentLine, ';', charNum + 1); - if (nextSemiColon == string::npos) + if (nextSemiColon == std::string::npos) return false; // add closing brace before changing the line length @@ -6536,7 +6537,7 @@ bool ASFormatter::removeBracesFromStatement() return false; bool isFirstLine = true; - string nextLine_; + std::string nextLine_; // leave nextLine_ empty if end of line comment follows if (!isBeforeAnyLineEndComment(charNum) || currentLineBeginsWithBrace) nextLine_ = currentLine.substr(charNum + 1); @@ -6555,7 +6556,7 @@ bool ASFormatter::removeBracesFromStatement() } nextChar = nextLine_.find_first_not_of(" \t", nextChar); - if (nextChar != string::npos) + if (nextChar != std::string::npos) break; } if (!stream.hasMoreLines()) @@ -6572,7 +6573,7 @@ bool ASFormatter::removeBracesFromStatement() size_t nextSemiColon = nextChar; if (nextLine_[nextChar] != ';') nextSemiColon = findNextChar(nextLine_, ';', nextChar + 1); - if (nextSemiColon == string::npos) + if (nextSemiColon == std::string::npos) return false; // find the closing brace @@ -6588,7 +6589,7 @@ bool ASFormatter::removeBracesFromStatement() nextChar = 0; } nextChar = nextLine_.find_first_not_of(" \t", nextChar); - if (nextChar != string::npos) + if (nextChar != std::string::npos) break; } if (nextLine_.length() == 0 || nextLine_[nextChar] != '}') @@ -6606,24 +6607,24 @@ bool ASFormatter::removeBracesFromStatement() * @param line the line to be searched. * @param searchChar the char to find. * @param searchStart the start position on the line (default is 0). - * @return the position on the line or string::npos if not found. + * @return the position on the line or std::string::npos if not found. */ -size_t ASFormatter::findNextChar(const string& line, char searchChar, int searchStart /*0*/) const +size_t ASFormatter::findNextChar(const std::string& line, char searchChar, int searchStart /*0*/) const { // find the next searchChar size_t i; for (i = searchStart; i < line.length(); i++) { if (line.compare(i, 2, "//") == 0) - return string::npos; + return std::string::npos; if (line.compare(i, 2, "/*") == 0) { size_t endComment = line.find("*/", i + 2); - if (endComment == string::npos) - return string::npos; + if (endComment == std::string::npos) + return std::string::npos; i = endComment + 2; if (i >= line.length()) - return string::npos; + return std::string::npos; } if (line[i] == '"' || (line[i] == '\'' && !isDigitSeparator(line, i))) @@ -6632,8 +6633,8 @@ size_t ASFormatter::findNextChar(const string& line, char searchChar, int search while (i < line.length()) { size_t endQuote = line.find(quote, i + 1); - if (endQuote == string::npos) - return string::npos; + if (endQuote == std::string::npos) + return std::string::npos; i = endQuote; if (line[endQuote - 1] != '\\') // check for '\"' break; @@ -6648,10 +6649,10 @@ size_t ASFormatter::findNextChar(const string& line, char searchChar, int search // for now don't process C# 'delegate' braces // do this last in case the search char is a '{' if (line[i] == '{') - return string::npos; + return std::string::npos; } if (i >= line.length()) // didn't find searchChar - return string::npos; + return std::string::npos; return i; } @@ -6659,7 +6660,7 @@ size_t ASFormatter::findNextChar(const string& line, char searchChar, int search /** * Find split point for break/attach return type. */ -void ASFormatter::findReturnTypeSplitPoint(const string& firstLine) +void ASFormatter::findReturnTypeSplitPoint(const std::string& firstLine) { assert((isBraceType(braceTypeStack->back(), NULL_TYPE) || isBraceType(braceTypeStack->back(), DEFINITION_TYPE))); @@ -6678,8 +6679,8 @@ void ASFormatter::findReturnTypeSplitPoint(const string& firstLine) size_t squareCount = 0; size_t angleCount = 0; size_t breakLineNum = 0; - size_t breakCharNum = string::npos; - string line = firstLine; + size_t breakCharNum = std::string::npos; + std::string line = firstLine; // Process the lines until a ';' or '{'. ASPeekStream stream(sourceIterator); @@ -6696,7 +6697,7 @@ void ASFormatter::findReturnTypeSplitPoint(const string& firstLine) ++breakLineNum; } size_t firstCharNum = line.find_first_not_of(" \t"); - if (firstCharNum == string::npos) + if (firstCharNum == std::string::npos) continue; if (line[firstCharNum] == '#') { @@ -6771,9 +6772,9 @@ void ASFormatter::findReturnTypeSplitPoint(const string& firstLine) if (!angleCount) { size_t nextCharNum = line.find_first_not_of(" \t*&", i + 1); - if (nextCharNum == string::npos) + if (nextCharNum == std::string::npos) { - breakCharNum = string::npos; + breakCharNum = std::string::npos; continue; } if (line[nextCharNum] != ':') // scope operator @@ -6800,20 +6801,20 @@ void ASFormatter::findReturnTypeSplitPoint(const string& firstLine) if (isWhiteSpace(line[i]) || line[i] == '*' || line[i] == '&') { size_t nextNum = line.find_first_not_of(" \t", i + 1); - if (nextNum == string::npos) - breakCharNum = string::npos; + if (nextNum == std::string::npos) + breakCharNum = std::string::npos; else { if (line.length() > nextNum + 1 && line[nextNum] == ':' && line[nextNum + 1] == ':') i = --nextNum; else if (line[nextNum] != '(') - breakCharNum = string::npos; + breakCharNum = std::string::npos; } continue; } if ((isLegalNameChar(line[i]) || line[i] == '~') - && breakCharNum == string::npos) + && breakCharNum == std::string::npos) { breakCharNum = i; if (isLegalNameChar(line[i]) @@ -6825,11 +6826,11 @@ void ASFormatter::findReturnTypeSplitPoint(const string& firstLine) // find the operator, may be parens size_t parenNum = line.find_first_not_of(" \t", i + AS_OPERATOR.length()); - if (parenNum == string::npos) + if (parenNum == std::string::npos) return; // find paren after the operator parenNum = line.find('(', parenNum + 1); - if (parenNum == string::npos) + if (parenNum == std::string::npos) return; i = --parenNum; } @@ -6840,7 +6841,7 @@ void ASFormatter::findReturnTypeSplitPoint(const string& firstLine) && line[i + 1] == ':') { size_t nextCharNum = line.find_first_not_of(" \t:", i + 1); - if (nextCharNum == string::npos) + if (nextCharNum == std::string::npos) return; if (isLegalNameChar(line[nextCharNum]) @@ -6853,11 +6854,11 @@ void ASFormatter::findReturnTypeSplitPoint(const string& firstLine) // find the operator, may be parens size_t parenNum = line.find_first_not_of(" \t", i + AS_OPERATOR.length()); - if (parenNum == string::npos) + if (parenNum == std::string::npos) return; // find paren after the operator parenNum = line.find('(', parenNum + 1); - if (parenNum == string::npos) + if (parenNum == std::string::npos) return; i = --parenNum; } @@ -6901,7 +6902,7 @@ void ASFormatter::findReturnTypeSplitPoint(const string& firstLine) if (shouldAttachReturnType && foundSplitPoint && isAlreadyBroken) { //https://sourceforge.net/p/astyle/bugs/545/ - if ((maxCodeLength != string::npos && previousReadyFormattedLineLength < maxCodeLength) || maxCodeLength == string::npos) + if ((maxCodeLength != std::string::npos && previousReadyFormattedLineLength < maxCodeLength) || maxCodeLength == std::string::npos) { methodAttachCharNum = breakCharNum; methodAttachLineNum = breakLineNum; @@ -6927,7 +6928,7 @@ void ASFormatter::findReturnTypeSplitPoint(const string& firstLine) return; } // end of for loop if (!foundSplitPoint) - breakCharNum = string::npos; + breakCharNum = std::string::npos; } // end of while loop } @@ -6938,14 +6939,14 @@ void ASFormatter::findReturnTypeSplitPoint(const string& firstLine) * @param index the current line index. * @return true if the struct has access modifiers. */ -bool ASFormatter::isStructAccessModified(const string& firstLine, size_t index) const +bool ASFormatter::isStructAccessModified(const std::string& firstLine, size_t index) const { assert(firstLine[index] == '{'); assert(isCStyle()); bool isFirstLine = true; size_t braceCount = 1; - string nextLine_ = firstLine.substr(index + 1); + std::string nextLine_ = firstLine.substr(index + 1); ASPeekStream stream(sourceIterator); // find the first non-blank text, bypassing all comments and quotes. @@ -7013,7 +7014,7 @@ bool ASFormatter::isStructAccessModified(const string& firstLine, size_t index) || findKeyword(nextLine_, i, AS_PRIVATE) || findKeyword(nextLine_, i, AS_PROTECTED)) return true; - string name = getCurrentWord(nextLine_, i); + std::string name = getCurrentWord(nextLine_, i); i += name.length() - 1; } } // end of for loop @@ -7029,7 +7030,7 @@ bool ASFormatter::isStructAccessModified(const string& firstLine, size_t index) * @param index the current line index. * @return true if the block is indentable. */ -bool ASFormatter::isIndentablePreprocessorBlock(const string& firstLine, size_t index) +bool ASFormatter::isIndentablePreprocessorBlock(const std::string& firstLine, size_t index) { assert(firstLine[index] == '#'); @@ -7042,8 +7043,8 @@ bool ASFormatter::isIndentablePreprocessorBlock(const string& firstLine, size_t bool isPotentialHeaderGuard2 = false; // define is within the first preproc int numBlockIndents = 0; int lineParenCount = 0; - string nextLine_ = firstLine.substr(index); - auto stream = make_shared(sourceIterator); + std::string nextLine_ = firstLine.substr(index); + auto stream = std::make_shared(sourceIterator); // find end of the block, bypassing all comments and quotes. bool isInComment_ = false; @@ -7098,7 +7099,7 @@ bool ASFormatter::isIndentablePreprocessorBlock(const string& firstLine, size_t // handle preprocessor statement if (nextLine_[i] == '#') { - string preproc = ASBeautifier::extractPreprocessorStatement(nextLine_); + std::string preproc = ASBeautifier::extractPreprocessorStatement(nextLine_); if (preproc.length() >= 2 && preproc.substr(0, 2) == "if") // #if, #ifdef, #ifndef { numBlockIndents += 1; @@ -7165,7 +7166,7 @@ bool ASFormatter::isIndentablePreprocessorBlock(const string& firstLine, size_t isInIndentableBlock = false; // find next executable instruction // this WILL RESET the get pointer - string nextText = peekNextText("", false, stream); + std::string nextText = peekNextText("", false, stream); // bypass header include guards if (isFirstPreprocConditional) { @@ -7183,7 +7184,7 @@ bool ASFormatter::isIndentablePreprocessorBlock(const string& firstLine, size_t return isInIndentableBlock; } -bool ASFormatter::isNDefPreprocStatement(const string& nextLine_, const string& preproc) const +bool ASFormatter::isNDefPreprocStatement(const std::string& nextLine_, const std::string& preproc) const { if (preproc == "ifndef") return true; @@ -7191,10 +7192,10 @@ bool ASFormatter::isNDefPreprocStatement(const string& nextLine_, const string& if (preproc == "if") { size_t i = nextLine_.find('!'); - if (i == string::npos) + if (i == std::string::npos) return false; i = nextLine_.find_first_not_of(" \t", ++i); - if (i != string::npos && nextLine_.compare(i, 7, "defined") == 0) + if (i != std::string::npos && nextLine_.compare(i, 7, "defined") == 0) return true; } return false; @@ -7207,11 +7208,11 @@ bool ASFormatter::isNDefPreprocStatement(const string& nextLine_, const string& * @param index the current line index. * @return true if the statement is EXEC SQL. */ -bool ASFormatter::isExecSQL(const string& line, size_t index) const +bool ASFormatter::isExecSQL(const std::string& line, size_t index) const { if (line[index] != 'e' && line[index] != 'E') // quick check to reject most return false; - string word; + std::string word; if (isCharPotentialHeader(line, index)) word = getCurrentWord(line, index); for (char& character : word) @@ -7220,7 +7221,7 @@ bool ASFormatter::isExecSQL(const string& line, size_t index) const return false; size_t index2 = index + word.length(); index2 = line.find_first_not_of(" \t", index2); - if (index2 == string::npos) + if (index2 == std::string::npos) return false; word.erase(); if (isCharPotentialHeader(line, index2)) @@ -7266,7 +7267,7 @@ void ASFormatter::trimContinuationLine() else { // build a new line with the equivalent leading chars - string newLine; + std::string newLine; int leadingChars = 0; if ((int) leadingSpaces > tabIncrementIn) leadingChars = leadingSpaces - tabIncrementIn; @@ -7275,7 +7276,7 @@ void ASFormatter::trimContinuationLine() currentLine = newLine; charNum = leadingChars; if (currentLine.length() == 0) - currentLine = string(" "); // a null is inserted if this is not done + currentLine = std::string(" "); // a null is inserted if this is not done } if (i >= len) charNum = 0; @@ -7287,7 +7288,7 @@ void ASFormatter::trimContinuationLine() * * @return true if the header is a closing header. */ -bool ASFormatter::isClosingHeader(const string* header) const +bool ASFormatter::isClosingHeader(const std::string* header) const { return (header == &AS_ELSE || header == &AS_CATCH @@ -7303,16 +7304,16 @@ bool ASFormatter::isImmediatelyPostCast() const { assert(previousNonWSChar == ')' && currentChar == '*'); // find preceding closing paren on currentLine or readyFormattedLine - string line; // currentLine or readyFormattedLine + std::string line; // currentLine or readyFormattedLine size_t paren = currentLine.rfind(')', charNum); - if (paren != string::npos) + if (paren != std::string::npos) line = currentLine; // if not on currentLine it must be on the previous line else { line = readyFormattedLine; paren = line.rfind(')'); - if (paren == string::npos) + if (paren == std::string::npos) return false; } if (paren == 0) @@ -7320,7 +7321,7 @@ bool ASFormatter::isImmediatelyPostCast() const // find character preceding the closing paren size_t lastChar = line.find_last_not_of(" \t", paren - 1); - if (lastChar == string::npos) + if (lastChar == std::string::npos) return false; // check for pointer cast if (line[lastChar] == '*') @@ -7338,7 +7339,7 @@ void ASFormatter::checkIfTemplateOpener() // find first char after the '<' operators size_t firstChar = currentLine.find_first_not_of("< \t", charNum); - if (firstChar == string::npos + if (firstChar == std::string::npos || currentLine[firstChar] == '=') { // this is not a template -> leave... @@ -7350,7 +7351,7 @@ void ASFormatter::checkIfTemplateOpener() int parenDepth_ = 0; int maxTemplateDepth = 0; templateDepth = 0; - string nextLine_ = currentLine.substr(charNum); + std::string nextLine_ = currentLine.substr(charNum); ASPeekStream stream(sourceIterator); // find the angle braces, bypassing all comments and quotes. @@ -7456,8 +7457,8 @@ void ASFormatter::checkIfTemplateOpener() || currentChar_ == '^' // C++/CLI managed pointer, e.g. A || currentChar_ == ':' // ::, e.g. std::string || currentChar_ == '=' // assign e.g. default parameter - || currentChar_ == '[' // [] e.g. string[] - || currentChar_ == ']' // [] e.g. string[] + || currentChar_ == '[' // [] e.g. std::string[] + || currentChar_ == ']' // [] e.g. std::string[] || currentChar_ == '(' // (...) e.g. function definition || currentChar_ == ')' // (...) e.g. function definition || (isJavaStyle() && currentChar_ == '?') // Java wildcard @@ -7472,7 +7473,7 @@ void ASFormatter::checkIfTemplateOpener() templateDepth = 0; return; } - string name = getCurrentWord(nextLine_, i); + std::string name = getCurrentWord(nextLine_, i); i += name.length() - 1; } // end for loop } // end while loop @@ -7480,7 +7481,7 @@ void ASFormatter::checkIfTemplateOpener() void ASFormatter::updateFormattedLineSplitPoints(char appendedChar) { - assert(maxCodeLength != string::npos); + assert(maxCodeLength != std::string::npos); assert(formattedLine.length() > 0); if (!isOkToSplitFormattedLine()) @@ -7582,9 +7583,9 @@ void ASFormatter::updateFormattedLineSplitPoints(char appendedChar) } } -void ASFormatter::updateFormattedLineSplitPointsOperator(const string& sequence) +void ASFormatter::updateFormattedLineSplitPointsOperator(const std::string& sequence) { - assert(maxCodeLength != string::npos); + assert(maxCodeLength != std::string::npos); assert(formattedLine.length() > 0); if (!isOkToSplitFormattedLine()) @@ -7681,7 +7682,7 @@ void ASFormatter::updateFormattedLineSplitPointsOperator(const string& sequence) */ void ASFormatter::updateFormattedLineSplitPointsPointerOrReference(size_t index) { - assert(maxCodeLength != string::npos); + assert(maxCodeLength != std::string::npos); assert(formattedLine.length() > 0); assert(index < formattedLine.length()); @@ -7699,7 +7700,7 @@ void ASFormatter::updateFormattedLineSplitPointsPointerOrReference(size_t index) bool ASFormatter::isOkToSplitFormattedLine() { - assert(maxCodeLength != string::npos); + assert(maxCodeLength != std::string::npos); // Is it OK to split the line? if (shouldKeepLineUnbroken || isInLineComment @@ -7739,12 +7740,12 @@ void ASFormatter::testForTimeToSplitFormattedLine() size_t splitPoint = findFormattedLineSplitPoint(); if (splitPoint > 0 && splitPoint < formattedLine.length()) { - string splitLine = formattedLine.substr(splitPoint); + std::string splitLine = formattedLine.substr(splitPoint); formattedLine = formattedLine.substr(0, splitPoint); breakLine(true); formattedLine = splitLine; // if break-blocks is requested and this is a one-line statement - string nextWord = ASBeautifier::getNextWord(currentLine, charNum - 1); + std::string nextWord = ASBeautifier::getNextWord(currentLine, charNum - 1); if (isAppendPostBlockEmptyLineRequested && (nextWord == "break" || nextWord == "continue")) { @@ -7786,7 +7787,7 @@ void ASFormatter::testForTimeToSplitFormattedLine() } // don't allow an empty formatted line size_t firstText = formattedLine.find_first_not_of(" \t"); - if (firstText == string::npos && formattedLine.length() > 0) + if (firstText == std::string::npos && formattedLine.length() > 0) { formattedLine.erase(); clearFormattedLineSplitPoints(); @@ -7804,10 +7805,10 @@ void ASFormatter::testForTimeToSplitFormattedLine() maxWhiteSpace = (maxWhiteSpace > firstText) ? (maxWhiteSpace - firstText) : 0; } // reset formattedLineCommentNum - if (formattedLineCommentNum != string::npos) + if (formattedLineCommentNum != std::string::npos) { formattedLineCommentNum = formattedLine.find("//"); - if (formattedLineCommentNum == string::npos) + if (formattedLineCommentNum == std::string::npos) formattedLineCommentNum = formattedLine.find("/*"); } } @@ -7816,7 +7817,7 @@ void ASFormatter::testForTimeToSplitFormattedLine() size_t ASFormatter::findFormattedLineSplitPoint() const { - assert(maxCodeLength != string::npos); + assert(maxCodeLength != std::string::npos); // determine where to split size_t minCodeLength = 10; size_t splitPoint = 0; @@ -7839,7 +7840,7 @@ size_t ASFormatter::findFormattedLineSplitPoint() const // replace split point with first available break point if (splitPoint < minCodeLength) { - splitPoint = string::npos; + splitPoint = std::string::npos; if (maxSemiPending > 0 && maxSemiPending < splitPoint) splitPoint = maxSemiPending; if (maxAndOrPending > 0 && maxAndOrPending < splitPoint) @@ -7850,7 +7851,7 @@ size_t ASFormatter::findFormattedLineSplitPoint() const splitPoint = maxParenPending; if (maxWhiteSpacePending > 0 && maxWhiteSpacePending < splitPoint) splitPoint = maxWhiteSpacePending; - if (splitPoint == string::npos) + if (splitPoint == std::string::npos) splitPoint = 0; } // if remaining line after split is too long @@ -7895,7 +7896,7 @@ void ASFormatter::clearFormattedLineSplitPoints() bool ASFormatter::pointerSymbolFollows() const { size_t peekNum = currentLine.find_first_not_of(" \t", charNum + 1); - if (peekNum == string::npos || currentLine.compare(peekNum, 2, "->") != 0) + if (peekNum == std::string::npos || currentLine.compare(peekNum, 2, "->") != 0) return false; return true; } @@ -7904,7 +7905,7 @@ bool ASFormatter::pointerSymbolFollows() const * Compute the input checksum. * This is called as an assert so it for is debug config only */ -bool ASFormatter::computeChecksumIn(const string& currentLine_) +bool ASFormatter::computeChecksumIn(const std::string& currentLine_) { for (const char& character : currentLine_) if (!isWhiteSpace(character)) @@ -7936,7 +7937,7 @@ size_t ASFormatter::getChecksumIn() const * Compute the output checksum. * This is called as an assert so it is for debug config only */ -bool ASFormatter::computeChecksumOut(const string& beautifiedLine) +bool ASFormatter::computeChecksumOut(const std::string& beautifiedLine) { for (const char& character : beautifiedLine) if (!isWhiteSpace(character)) @@ -7979,11 +7980,11 @@ int ASFormatter::getFormatterFileType() const // Check if an operator follows the next word. // The next word must be a legal name. -const string* ASFormatter::getFollowingOperator() const +const std::string* ASFormatter::getFollowingOperator() const { // find next word size_t nextNum = currentLine.find_first_not_of(" \t", charNum + 1); - if (nextNum == string::npos) + if (nextNum == std::string::npos) return nullptr; if (!isLegalNameChar(currentLine[nextNum])) @@ -8003,7 +8004,7 @@ const string* ASFormatter::getFollowingOperator() const || currentLine[nextNum] == '/') // comment return nullptr; - const string* newOperator = ASBase::findOperator(currentLine, nextNum, operators); + const std::string* newOperator = ASBase::findOperator(currentLine, nextNum, operators); return newOperator; } @@ -8015,7 +8016,7 @@ bool ASFormatter::isArrayOperator() const // find next word size_t nextNum = currentLine.find_first_not_of(" \t", charNum + 1); - if (nextNum == string::npos) + if (nextNum == std::string::npos) return false; if (!isLegalNameChar(currentLine[nextNum])) @@ -8086,7 +8087,7 @@ int ASFormatter::findObjCColonAlignment() const int sqBracketCount = 0; int colonAdjust = 0; int colonAlign = 0; - string nextLine_ = currentLine; + std::string nextLine_ = currentLine; ASPeekStream stream(sourceIterator); // peek next line @@ -8233,7 +8234,7 @@ void ASFormatter::padObjCMethodColon() { // remove spaces after size_t nextText = currentLine.find_first_not_of(" \t", charNum + 1); - if (nextText == string::npos) + if (nextText == std::string::npos) nextText = currentLine.length(); int spaces = nextText - charNum - 1; if (spaces > 0) @@ -8247,7 +8248,7 @@ void ASFormatter::padObjCMethodColon() { // pad space after size_t nextText = currentLine.find_first_not_of(" \t", charNum + 1); - if (nextText == string::npos) + if (nextText == std::string::npos) nextText = currentLine.length(); int spaces = nextText - charNum - 1; if (spaces == 0) @@ -8297,7 +8298,7 @@ void ASFormatter::stripCommentPrefix() int followingTextIndent = followingText - commentOpener; if (followingTextIndent < indentLen) { - string stringToInsert(indentLen - followingTextIndent, ' '); + std::string stringToInsert(indentLen - followingTextIndent, ' '); formattedLine.insert(followingText, stringToInsert); } return; @@ -8326,7 +8327,7 @@ void ASFormatter::stripCommentPrefix() int indentLen = getIndentLength(); adjustChecksumIn(-'*'); // second char must be at least one indent - if (formattedLine.substr(0, secondChar).find('\t') != string::npos) + if (formattedLine.substr(0, secondChar).find('\t') != std::string::npos) { formattedLine.erase(firstChar, 1); } @@ -8337,7 +8338,7 @@ void ASFormatter::stripCommentPrefix() spacesToInsert = secondChar; else spacesToInsert = indentLen; - formattedLine = string(spacesToInsert, ' ') + formattedLine.substr(secondChar); + formattedLine = std::string(spacesToInsert, ' ') + formattedLine.substr(secondChar); } // remove a trailing '*' int lastChar = formattedLine.find_last_not_of(" \t"); @@ -8352,12 +8353,12 @@ void ASFormatter::stripCommentPrefix() { // first char not a '*' // first char must be at least one indent - if (formattedLine.substr(0, firstChar).find('\t') == string::npos) + if (formattedLine.substr(0, firstChar).find('\t') == std::string::npos) { int indentLen = getIndentLength(); if (firstChar < indentLen) { - string stringToInsert(indentLen, ' '); + std::string stringToInsert(indentLen, ' '); formattedLine = stringToInsert + formattedLine.substr(firstChar); } } diff --git a/AStyle/src/ASLocalizer.cpp b/AStyle/src/ASLocalizer.cpp index e73786b..5e39d16 100644 --- a/AStyle/src/ASLocalizer.cpp +++ b/AStyle/src/ASLocalizer.cpp @@ -183,7 +183,7 @@ void ASLocalizer::setLanguageFromLCID(size_t lcid) #endif // _WIN32 -string ASLocalizer::getLanguageID() const +std::string ASLocalizer::getLanguageID() const // Returns the language ID in m_langID. { return m_langID; @@ -217,13 +217,13 @@ void ASLocalizer::setLanguageFromName(const char* langID) // de_DE.iso88591@euro { // the constants describing the format of lang_LANG locale string - string langStr = langID; + std::string langStr = langID; m_langID = langStr.substr(0, 2); // need the sublang for chinese if (m_langID == "zh" && langStr[2] == '_') { - string subLang = langStr.substr(3, 2); + std::string subLang = langStr.substr(3, 2); if (subLang == "CN" || subLang == "SG") m_subLangID = "CHS"; else @@ -236,7 +236,7 @@ const char* ASLocalizer::settext(const char* textIn) const // Call the settext class and return the value. { assert(m_translationClass); - const string stringIn = textIn; + const std::string stringIn = textIn; return m_translationClass->translate(stringIn).c_str(); } @@ -311,22 +311,22 @@ Translation::Translation() m_translationVector.reserve(translationElements); } -void Translation::addPair(const string& english, const wstring& translated) +void Translation::addPair(const std::string& english, const std::wstring& translated) // Add a string pair to the translation vector. { - pair entry(english, translated); + std::pair entry(english, translated); m_translationVector.emplace_back(entry); assert(m_translationVector.size() <= translationElements); } -string Translation::convertToMultiByte(const wstring& wideStr) const +std::string Translation::convertToMultiByte(const std::wstring& wideStr) const // Convert wchar_t to a multibyte string using the currently assigned locale. // Return an empty string if an error occurs. { static bool msgDisplayed = false; // get length of the output excluding the nullptr and validate the parameters size_t mbLen = wcstombs(nullptr, wideStr.c_str(), 0); - if (mbLen == string::npos) + if (mbLen == std::string::npos) { if (!msgDisplayed) { @@ -336,7 +336,7 @@ string Translation::convertToMultiByte(const wstring& wideStr) const return ""; } // convert the characters - char* mbStr = new (nothrow) char[mbLen + 1]; + char* mbStr = new (std::nothrow) char[mbLen + 1]; if (mbStr == nullptr) { if (!msgDisplayed) @@ -348,16 +348,16 @@ string Translation::convertToMultiByte(const wstring& wideStr) const } wcstombs(mbStr, wideStr.c_str(), mbLen + 1); // return the string - string mbTranslation = mbStr; + std::string mbTranslation = mbStr; delete[] mbStr; return mbTranslation; } -string Translation::getTranslationString(size_t i) const +std::string Translation::getTranslationString(size_t i) const // Return the translation ascii value. Used for testing. { if (i >= m_translationVector.size()) - return string(); + return std::string(); return m_translationVector[i].first; } @@ -367,10 +367,10 @@ size_t Translation::getTranslationVectorSize() const return m_translationVector.size(); } -bool Translation::getWideTranslation(const string& stringIn, wstring& wideOut) const +bool Translation::getWideTranslation(const std::string& stringIn, std::wstring& wideOut) const // Get the wide translation string. Used for testing. { - for (const pair& translation : m_translationVector) + for (const std::pair& translation : m_translationVector) { if (translation.first == stringIn) { @@ -383,13 +383,13 @@ bool Translation::getWideTranslation(const string& stringIn, wstring& wideOut) c return false; } -string& Translation::translate(const string& stringIn) const +std::string& Translation::translate(const std::string& stringIn) const // Translate a string. // Return a mutable string so the method can have a "const" designation. // This allows "settext" to be called from a "const" method. { m_mbTranslation.clear(); - for (const pair& translation : m_translationVector) + for (const std::pair& translation : m_translationVector) { if (translation.first == stringIn) { diff --git a/AStyle/src/ASLocalizer.h b/AStyle/src/ASLocalizer.h index 3de9d6a..08ac360 100644 --- a/AStyle/src/ASLocalizer.h +++ b/AStyle/src/ASLocalizer.h @@ -19,8 +19,6 @@ namespace astyle { -using namespace std; - #ifndef ASTYLE_LIB //----------------------------------------------------------------------------- @@ -35,7 +33,7 @@ class ASLocalizer public: // functions ASLocalizer(); virtual ~ASLocalizer(); - string getLanguageID() const; + std::string getLanguageID() const; const Translation* getTranslationClass() const; #ifdef _WIN32 void setLanguageFromLCID(size_t lcid); @@ -48,8 +46,8 @@ class ASLocalizer private: // variables Translation* m_translationClass;// pointer to a polymorphic Translation class - string m_langID; // language identifier from the locale - string m_subLangID; // sub language identifier, if needed + std::string m_langID; // language identifier from the locale + std::string m_subLangID; // sub language identifier, if needed #ifdef _WIN32 size_t m_lcid; // LCID of the user locale (Windows only) size_t m_codepage; // active codepage, 65001 = utf-8 @@ -63,36 +61,36 @@ class ASLocalizer class Translation // This base class is inherited by the language translation classes. // Polymorphism is used to call the correct language translator. -// This class contains the translation vector and settext translation method. -// The language vector is built by the language sub classes. +// This class contains the translation std::vector and settext translation method. +// The language std::vector is built by the language sub classes. // NOTE: This class must have virtual methods for typeid() to work. // typeid() is used by AStyleTestI18n_Localizer.cpp. { public: Translation(); virtual ~Translation() = default; - string convertToMultiByte(const wstring& wideStr) const; - string getTranslationString(size_t i) const; + std::string convertToMultiByte(const std::wstring& wideStr) const; + std::string getTranslationString(size_t i) const; size_t getTranslationVectorSize() const; - bool getWideTranslation(const string& stringIn, wstring& wideOut) const; - string& translate(const string& stringIn) const; + bool getWideTranslation(const std::string& stringIn, std::wstring& wideOut) const; + std::string& translate(const std::string& stringIn) const; protected: - void addPair(const string& english, const wstring& translated); + void addPair(const std::string& english, const std::wstring& translated); // variables - vector > m_translationVector; + std::vector > m_translationVector; private: // the number of translation pairs added a constructor static const size_t translationElements = 30; // need static for vs2013 - // the translated string - mutable string m_mbTranslation; + // the translated std::string + mutable std::string m_mbTranslation; }; //---------------------------------------------------------------------------- // Translation classes // One class for each language. -// These classes have only a constructor which builds the language vector. +// These classes have only a constructor which builds the language std::vector. //---------------------------------------------------------------------------- class Bulgarian : public Translation diff --git a/AStyle/src/ASResource.cpp b/AStyle/src/ASResource.cpp index 23288ea..1020703 100644 --- a/AStyle/src/ASResource.cpp +++ b/AStyle/src/ASResource.cpp @@ -16,159 +16,159 @@ namespace astyle { // -const string ASResource::_AS_EXCEPT = string("__except"); -const string ASResource::_AS_FINALLY = string("__finally"); -const string ASResource::_AS_TRY = string("__try"); -const string ASResource::AS_ADD = string("add"); -const string ASResource::AS_AUTO = string("auto"); -const string ASResource::AS_AUTORELEASEPOOL = string("autoreleasepool"); -const string ASResource::AS_CASE = string("case"); -const string ASResource::AS_CATCH = string("catch"); -const string ASResource::AS_CLASS = string("class"); -const string ASResource::AS_CONST = string("const"); -const string ASResource::AS_CONST_CAST = string("const_cast"); -const string ASResource::AS_DEFAULT = string("default"); -const string ASResource::AS_DELEGATE = string("delegate"); -const string ASResource::AS_DELETE = string("delete"); -const string ASResource::AS_DO = string("do"); -const string ASResource::AS_DYNAMIC_CAST = string("dynamic_cast"); -const string ASResource::AS_ELSE = string("else"); -const string ASResource::AS_END = string("end"); -const string ASResource::AS_ENUM = string("enum"); -const string ASResource::AS_EXTERN = string("extern"); -const string ASResource::AS_FINAL = string("final"); -const string ASResource::AS_FINALLY = string("finally"); -const string ASResource::AS_FIXED = string("fixed"); -const string ASResource::AS_FOR = string("for"); -const string ASResource::AS_FOREACH = string("foreach"); -const string ASResource::AS_FOREVER = string("forever"); -const string ASResource::AS_GET = string("get"); -const string ASResource::AS_IF = string("if"); -const string ASResource::AS_INTERFACE = string("interface"); -const string ASResource::AS_INTERRUPT = string("interrupt"); -const string ASResource::AS_LET = string("let"); -const string ASResource::AS_LOCK = string("lock"); -const string ASResource::AS_MODULE = string("module"); // CORBA IDL module definition -const string ASResource::AS_NAMESPACE = string("namespace"); -const string ASResource::AS_NEW = string("new"); -const string ASResource::AS_NOEXCEPT = string("noexcept"); -const string ASResource::AS_NS_DURING = string("NS_DURING"); -const string ASResource::AS_NS_HANDLER = string("NS_HANDLER"); -const string ASResource::AS_OPERATOR = string("operator"); -const string ASResource::AS_OVERRIDE = string("override"); -const string ASResource::AS_PRIVATE = string("private"); -const string ASResource::AS_PROTECTED = string("protected"); -const string ASResource::AS_PUBLIC = string("public"); -const string ASResource::AS_QFOREACH = string("Q_FOREACH"); -const string ASResource::AS_QFOREVER = string("Q_FOREVER"); -const string ASResource::AS_REINTERPRET_CAST = string("reinterpret_cast"); -const string ASResource::AS_REMOVE = string("remove"); -const string ASResource::AS_SEALED = string("sealed"); -const string ASResource::AS_SELECTOR = string("selector"); -const string ASResource::AS_SET = string("set"); -const string ASResource::AS_STATIC = string("static"); -const string ASResource::AS_STATIC_CAST = string("static_cast"); -const string ASResource::AS_STRUCT = string("struct"); -const string ASResource::AS_TYPEDEF_STRUCT = string("typedef struct"); -const string ASResource::AS_SWITCH = string("switch"); -const string ASResource::AS_SYNCHRONIZED = string("synchronized"); -const string ASResource::AS_TEMPLATE = string("template"); -const string ASResource::AS_THROW = string("throw"); -const string ASResource::AS_THROWS = string("throws"); -const string ASResource::AS_TRY = string("try"); -const string ASResource::AS_UNCHECKED = string("unchecked"); -const string ASResource::AS_UNION = string("union"); -const string ASResource::AS_UNSAFE = string("unsafe"); -const string ASResource::AS_USING = string("using"); -const string ASResource::AS_VOLATILE = string("volatile"); -const string ASResource::AS_WHERE = string("where"); -const string ASResource::AS_WHILE = string("while"); - -const string ASResource::AS_ASM = string("asm"); -const string ASResource::AS__ASM__ = string("__asm__"); -const string ASResource::AS_MS_ASM = string("_asm"); -const string ASResource::AS_MS__ASM = string("__asm"); - -const string ASResource::AS_BAR_DEFINE = string("#define"); -const string ASResource::AS_BAR_INCLUDE = string("#include"); -const string ASResource::AS_BAR_IF = string("#if"); -const string ASResource::AS_BAR_EL = string("#el"); -const string ASResource::AS_BAR_ENDIF = string("#endif"); - -const string ASResource::AS_OPEN_PAREN = string("("); -const string ASResource::AS_CLOSE_PAREN = string(")"); -const string ASResource::AS_OPEN_BRACE = string("{"); -const string ASResource::AS_CLOSE_BRACE = string("}"); -const string ASResource::AS_OPEN_LINE_COMMENT = string("//"); -const string ASResource::AS_OPEN_COMMENT = string("/*"); -const string ASResource::AS_CLOSE_COMMENT = string("*/"); - -const string ASResource::AS_ASSIGN = string("="); -const string ASResource::AS_PLUS_ASSIGN = string("+="); -const string ASResource::AS_MINUS_ASSIGN = string("-="); -const string ASResource::AS_MULT_ASSIGN = string("*="); -const string ASResource::AS_DIV_ASSIGN = string("/="); -const string ASResource::AS_MOD_ASSIGN = string("%="); -const string ASResource::AS_OR_ASSIGN = string("|="); -const string ASResource::AS_AND_ASSIGN = string("&="); -const string ASResource::AS_XOR_ASSIGN = string("^="); -const string ASResource::AS_GR_GR_ASSIGN = string(">>="); -const string ASResource::AS_LS_LS_ASSIGN = string("<<="); -const string ASResource::AS_GR_GR_GR_ASSIGN = string(">>>="); -const string ASResource::AS_LS_LS_LS_ASSIGN = string("<<<="); -const string ASResource::AS_GCC_MIN_ASSIGN = string("?"); - -const string ASResource::AS_RETURN = string("return"); -const string ASResource::AS_CIN = string("cin"); -const string ASResource::AS_COUT = string("cout"); -const string ASResource::AS_CERR = string("cerr"); - -const string ASResource::AS_EQUAL = string("=="); -const string ASResource::AS_PLUS_PLUS = string("++"); -const string ASResource::AS_MINUS_MINUS = string("--"); -const string ASResource::AS_NOT_EQUAL = string("!="); -const string ASResource::AS_GR_EQUAL = string(">="); -const string ASResource::AS_GR_GR = string(">>"); -const string ASResource::AS_GR_GR_GR = string(">>>"); -const string ASResource::AS_LS_EQUAL = string("<="); -const string ASResource::AS_LS_LS = string("<<"); -const string ASResource::AS_LS_LS_LS = string("<<<"); -const string ASResource::AS_QUESTION_QUESTION = string("??"); -const string ASResource::AS_LAMBDA = string("=>"); // C# lambda expression arrow -const string ASResource::AS_ARROW = string("->"); -const string ASResource::AS_AND = string("&&"); -const string ASResource::AS_OR = string("||"); -const string ASResource::AS_SCOPE_RESOLUTION = string("::"); -const string ASResource::AS_SPACESHIP = string("<=>"); -const string ASResource::AS_EQUAL_JS = string("==="); - -const string ASResource::AS_PLUS = string("+"); -const string ASResource::AS_MINUS = string("-"); -const string ASResource::AS_MULT = string("*"); -const string ASResource::AS_DIV = string("/"); -const string ASResource::AS_MOD = string("%"); -const string ASResource::AS_GR = string(">"); -const string ASResource::AS_LS = string("<"); -const string ASResource::AS_NOT = string("!"); -const string ASResource::AS_BIT_OR = string("|"); -const string ASResource::AS_BIT_AND = string("&"); -const string ASResource::AS_BIT_NOT = string("~"); -const string ASResource::AS_BIT_XOR = string("^"); -const string ASResource::AS_QUESTION = string("?"); -const string ASResource::AS_COLON = string(":"); -const string ASResource::AS_COMMA = string(","); -const string ASResource::AS_SEMICOLON = string(";"); +const std::string ASResource::_AS_EXCEPT = std::string("__except"); +const std::string ASResource::_AS_FINALLY = std::string("__finally"); +const std::string ASResource::_AS_TRY = std::string("__try"); +const std::string ASResource::AS_ADD = std::string("add"); +const std::string ASResource::AS_AUTO = std::string("auto"); +const std::string ASResource::AS_AUTORELEASEPOOL = std::string("autoreleasepool"); +const std::string ASResource::AS_CASE = std::string("case"); +const std::string ASResource::AS_CATCH = std::string("catch"); +const std::string ASResource::AS_CLASS = std::string("class"); +const std::string ASResource::AS_CONST = std::string("const"); +const std::string ASResource::AS_CONST_CAST = std::string("const_cast"); +const std::string ASResource::AS_DEFAULT = std::string("default"); +const std::string ASResource::AS_DELEGATE = std::string("delegate"); +const std::string ASResource::AS_DELETE = std::string("delete"); +const std::string ASResource::AS_DO = std::string("do"); +const std::string ASResource::AS_DYNAMIC_CAST = std::string("dynamic_cast"); +const std::string ASResource::AS_ELSE = std::string("else"); +const std::string ASResource::AS_END = std::string("end"); +const std::string ASResource::AS_ENUM = std::string("enum"); +const std::string ASResource::AS_EXTERN = std::string("extern"); +const std::string ASResource::AS_FINAL = std::string("final"); +const std::string ASResource::AS_FINALLY = std::string("finally"); +const std::string ASResource::AS_FIXED = std::string("fixed"); +const std::string ASResource::AS_FOR = std::string("for"); +const std::string ASResource::AS_FOREACH = std::string("foreach"); +const std::string ASResource::AS_FOREVER = std::string("forever"); +const std::string ASResource::AS_GET = std::string("get"); +const std::string ASResource::AS_IF = std::string("if"); +const std::string ASResource::AS_INTERFACE = std::string("interface"); +const std::string ASResource::AS_INTERRUPT = std::string("interrupt"); +const std::string ASResource::AS_LET = std::string("let"); +const std::string ASResource::AS_LOCK = std::string("lock"); +const std::string ASResource::AS_MODULE = std::string("module"); // CORBA IDL module definition +const std::string ASResource::AS_NAMESPACE = std::string("namespace"); +const std::string ASResource::AS_NEW = std::string("new"); +const std::string ASResource::AS_NOEXCEPT = std::string("noexcept"); +const std::string ASResource::AS_NS_DURING = std::string("NS_DURING"); +const std::string ASResource::AS_NS_HANDLER = std::string("NS_HANDLER"); +const std::string ASResource::AS_OPERATOR = std::string("operator"); +const std::string ASResource::AS_OVERRIDE = std::string("override"); +const std::string ASResource::AS_PRIVATE = std::string("private"); +const std::string ASResource::AS_PROTECTED = std::string("protected"); +const std::string ASResource::AS_PUBLIC = std::string("public"); +const std::string ASResource::AS_QFOREACH = std::string("Q_FOREACH"); +const std::string ASResource::AS_QFOREVER = std::string("Q_FOREVER"); +const std::string ASResource::AS_REINTERPRET_CAST = std::string("reinterpret_cast"); +const std::string ASResource::AS_REMOVE = std::string("remove"); +const std::string ASResource::AS_SEALED = std::string("sealed"); +const std::string ASResource::AS_SELECTOR = std::string("selector"); +const std::string ASResource::AS_SET = std::string("set"); +const std::string ASResource::AS_STATIC = std::string("static"); +const std::string ASResource::AS_STATIC_CAST = std::string("static_cast"); +const std::string ASResource::AS_STRUCT = std::string("struct"); +const std::string ASResource::AS_TYPEDEF_STRUCT = std::string("typedef struct"); +const std::string ASResource::AS_SWITCH = std::string("switch"); +const std::string ASResource::AS_SYNCHRONIZED = std::string("synchronized"); +const std::string ASResource::AS_TEMPLATE = std::string("template"); +const std::string ASResource::AS_THROW = std::string("throw"); +const std::string ASResource::AS_THROWS = std::string("throws"); +const std::string ASResource::AS_TRY = std::string("try"); +const std::string ASResource::AS_UNCHECKED = std::string("unchecked"); +const std::string ASResource::AS_UNION = std::string("union"); +const std::string ASResource::AS_UNSAFE = std::string("unsafe"); +const std::string ASResource::AS_USING = std::string("using"); +const std::string ASResource::AS_VOLATILE = std::string("volatile"); +const std::string ASResource::AS_WHERE = std::string("where"); +const std::string ASResource::AS_WHILE = std::string("while"); + +const std::string ASResource::AS_ASM = std::string("asm"); +const std::string ASResource::AS__ASM__ = std::string("__asm__"); +const std::string ASResource::AS_MS_ASM = std::string("_asm"); +const std::string ASResource::AS_MS__ASM = std::string("__asm"); + +const std::string ASResource::AS_BAR_DEFINE = std::string("#define"); +const std::string ASResource::AS_BAR_INCLUDE = std::string("#include"); +const std::string ASResource::AS_BAR_IF = std::string("#if"); +const std::string ASResource::AS_BAR_EL = std::string("#el"); +const std::string ASResource::AS_BAR_ENDIF = std::string("#endif"); + +const std::string ASResource::AS_OPEN_PAREN = std::string("("); +const std::string ASResource::AS_CLOSE_PAREN = std::string(")"); +const std::string ASResource::AS_OPEN_BRACE = std::string("{"); +const std::string ASResource::AS_CLOSE_BRACE = std::string("}"); +const std::string ASResource::AS_OPEN_LINE_COMMENT = std::string("//"); +const std::string ASResource::AS_OPEN_COMMENT = std::string("/*"); +const std::string ASResource::AS_CLOSE_COMMENT = std::string("*/"); + +const std::string ASResource::AS_ASSIGN = std::string("="); +const std::string ASResource::AS_PLUS_ASSIGN = std::string("+="); +const std::string ASResource::AS_MINUS_ASSIGN = std::string("-="); +const std::string ASResource::AS_MULT_ASSIGN = std::string("*="); +const std::string ASResource::AS_DIV_ASSIGN = std::string("/="); +const std::string ASResource::AS_MOD_ASSIGN = std::string("%="); +const std::string ASResource::AS_OR_ASSIGN = std::string("|="); +const std::string ASResource::AS_AND_ASSIGN = std::string("&="); +const std::string ASResource::AS_XOR_ASSIGN = std::string("^="); +const std::string ASResource::AS_GR_GR_ASSIGN = std::string(">>="); +const std::string ASResource::AS_LS_LS_ASSIGN = std::string("<<="); +const std::string ASResource::AS_GR_GR_GR_ASSIGN = std::string(">>>="); +const std::string ASResource::AS_LS_LS_LS_ASSIGN = std::string("<<<="); +const std::string ASResource::AS_GCC_MIN_ASSIGN = std::string("?"); + +const std::string ASResource::AS_RETURN = std::string("return"); +const std::string ASResource::AS_CIN = std::string("cin"); +const std::string ASResource::AS_COUT = std::string("cout"); +const std::string ASResource::AS_CERR = std::string("cerr"); + +const std::string ASResource::AS_EQUAL = std::string("=="); +const std::string ASResource::AS_PLUS_PLUS = std::string("++"); +const std::string ASResource::AS_MINUS_MINUS = std::string("--"); +const std::string ASResource::AS_NOT_EQUAL = std::string("!="); +const std::string ASResource::AS_GR_EQUAL = std::string(">="); +const std::string ASResource::AS_GR_GR = std::string(">>"); +const std::string ASResource::AS_GR_GR_GR = std::string(">>>"); +const std::string ASResource::AS_LS_EQUAL = std::string("<="); +const std::string ASResource::AS_LS_LS = std::string("<<"); +const std::string ASResource::AS_LS_LS_LS = std::string("<<<"); +const std::string ASResource::AS_QUESTION_QUESTION = std::string("??"); +const std::string ASResource::AS_LAMBDA = std::string("=>"); // C# lambda expression arrow +const std::string ASResource::AS_ARROW = std::string("->"); +const std::string ASResource::AS_AND = std::string("&&"); +const std::string ASResource::AS_OR = std::string("||"); +const std::string ASResource::AS_SCOPE_RESOLUTION = std::string("::"); +const std::string ASResource::AS_SPACESHIP = std::string("<=>"); +const std::string ASResource::AS_EQUAL_JS = std::string("==="); + +const std::string ASResource::AS_PLUS = std::string("+"); +const std::string ASResource::AS_MINUS = std::string("-"); +const std::string ASResource::AS_MULT = std::string("*"); +const std::string ASResource::AS_DIV = std::string("/"); +const std::string ASResource::AS_MOD = std::string("%"); +const std::string ASResource::AS_GR = std::string(">"); +const std::string ASResource::AS_LS = std::string("<"); +const std::string ASResource::AS_NOT = std::string("!"); +const std::string ASResource::AS_BIT_OR = std::string("|"); +const std::string ASResource::AS_BIT_AND = std::string("&"); +const std::string ASResource::AS_BIT_NOT = std::string("~"); +const std::string ASResource::AS_BIT_XOR = std::string("^"); +const std::string ASResource::AS_QUESTION = std::string("?"); +const std::string ASResource::AS_COLON = std::string(":"); +const std::string ASResource::AS_COMMA = std::string(","); +const std::string ASResource::AS_SEMICOLON = std::string(";"); /** * Sort comparison function. * Compares the length of the value of pointers in the vectors. - * The LONGEST strings will be first in the vector. + * The LONGEST std::strings will be first in the vector. * - * @param a and b, the string pointers to be compared. + * @param a and b, the std::string pointers to be compared. */ -bool sortOnLength(const string* a, const string* b) +bool sortOnLength(const std::string* a, const std::string* b) { return (*a).length() > (*b).length(); } @@ -177,9 +177,9 @@ bool sortOnLength(const string* a, const string* b) * Sort comparison function. * Compares the value of pointers in the vectors. * - * @param a and b, the string pointers to be compared. + * @param a and b, the std::string pointers to be compared. */ -bool sortOnName(const string* a, const string* b) +bool sortOnName(const std::string* a, const std::string* b) { return *a < *b; } @@ -190,7 +190,7 @@ bool sortOnName(const string* a, const string* b) * * @param assignmentOperators a reference to the vector to be built. */ -void ASResource::buildAssignmentOperators(vector* assignmentOperators) +void ASResource::buildAssignmentOperators(std::vector* assignmentOperators) { const size_t elements = 15; assignmentOperators->reserve(elements); @@ -223,7 +223,7 @@ void ASResource::buildAssignmentOperators(vector* assignmentOpera * * @param castOperators a reference to the vector to be built. */ -void ASResource::buildCastOperators(vector* castOperators) +void ASResource::buildCastOperators(std::vector* castOperators) { const size_t elements = 5; castOperators->reserve(elements); @@ -243,7 +243,7 @@ void ASResource::buildCastOperators(vector* castOperators) * * @param headers a reference to the vector to be built. */ -void ASResource::buildHeaders(vector* headers, int fileType, bool beautifier) +void ASResource::buildHeaders(std::vector* headers, int fileType, bool beautifier) { const size_t elements = 25; headers->reserve(elements); @@ -310,7 +310,7 @@ void ASResource::buildHeaders(vector* headers, int fileType, bool * * @param indentableHeaders a reference to the vector to be built. */ -void ASResource::buildIndentableHeaders(vector* indentableHeaders) +void ASResource::buildIndentableHeaders(std::vector* indentableHeaders) { indentableHeaders->emplace_back(&AS_RETURN); @@ -323,13 +323,13 @@ void ASResource::buildIndentableHeaders(vector* indentableHeaders * * @param indentableMacros a reference to the vector to be built. */ -void ASResource::buildIndentableMacros(vector* >* indentableMacros) +void ASResource::buildIndentableMacros(std::vector* >* indentableMacros) { const size_t elements = 10; indentableMacros->reserve(elements); // the pairs must be retained in memory because of pair pointers - using macro_pair = pair; + using macro_pair = std::pair; static const macro_pair macros[] = { // wxWidgets @@ -354,7 +354,7 @@ void ASResource::buildIndentableMacros(vector* nonAssignmentOperators) +void ASResource::buildNonAssignmentOperators(std::vector* nonAssignmentOperators) { const size_t elements = 15; nonAssignmentOperators->reserve(elements); @@ -383,9 +383,9 @@ void ASResource::buildNonAssignmentOperators(vector* nonAssignmen * Used by BOTH ASFormatter.cpp and ASBeautifier.cpp. * NOTE: Non-paren headers should also be included in the headers vector. * - * @param nonParenHeaders a reference to the vector to be built. + * @param nonParenHeaders a reference to the std::vector to be built. */ -void ASResource::buildNonParenHeaders(vector* nonParenHeaders, int fileType, bool beautifier) +void ASResource::buildNonParenHeaders(std::vector* nonParenHeaders, int fileType, bool beautifier) { const size_t elements = 20; nonParenHeaders->reserve(elements); @@ -440,7 +440,7 @@ void ASResource::buildNonParenHeaders(vector* nonParenHeaders, in * * @param operators a reference to the vector to be built. */ -void ASResource::buildOperators(vector* operators, int fileType) +void ASResource::buildOperators(std::vector* operators, int fileType) { const size_t elements = 50; operators->reserve(elements); @@ -509,7 +509,7 @@ void ASResource::buildOperators(vector* operators, int fileType) * * @param preBlockStatements a reference to the vector to be built. */ -void ASResource::buildPreBlockStatements(vector* preBlockStatements, int fileType) +void ASResource::buildPreBlockStatements(std::vector* preBlockStatements, int fileType) { const size_t elements = 10; preBlockStatements->reserve(elements); @@ -549,7 +549,7 @@ void ASResource::buildPreBlockStatements(vector* preBlockStatemen * the closing paren and the opening brace. * e.g. in "void foo() const {}", "const" is a preCommandHeader. */ -void ASResource::buildPreCommandHeaders(vector* preCommandHeaders, int fileType) +void ASResource::buildPreCommandHeaders(std::vector* preCommandHeaders, int fileType) { const size_t elements = 10; preCommandHeaders->reserve(elements); @@ -592,7 +592,7 @@ void ASResource::buildPreCommandHeaders(vector* preCommandHeaders * * @param preDefinitionHeaders a reference to the vector to be built. */ -void ASResource::buildPreDefinitionHeaders(vector* preDefinitionHeaders, int fileType) +void ASResource::buildPreDefinitionHeaders(std::vector* preDefinitionHeaders, int fileType) { const size_t elements = 10; preDefinitionHeaders->reserve(elements); @@ -626,15 +626,15 @@ void ASResource::buildPreDefinitionHeaders(vector* preDefinitionH * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ // check if a specific line position contains a header. -const string* ASBase::findHeader(const string& line, int i, - const vector* possibleHeaders) const +const std::string* ASBase::findHeader(const std::string& line, int i, + const std::vector* possibleHeaders) const { assert(isCharPotentialHeader(line, i)); // check the word size_t maxHeaders = possibleHeaders->size(); for (size_t p = 0; p < maxHeaders; p++) { - const string* header = (*possibleHeaders)[p]; + const std::string* header = (*possibleHeaders)[p]; const size_t wordEnd = i + header->length(); if (wordEnd > line.length()) continue; @@ -666,8 +666,9 @@ const string* ASBase::findHeader(const string& line, int i, } // check if a specific line position contains a keyword. -bool ASBase::findKeyword(const string& line, int i, const string& keyword) const +bool ASBase::findKeyword(const std::string& line, int i, const std::string& keyword) const { + //std::cerr << "findKeyword "<< i << " "<< line << " -< "<< keyword << "\n"; assert(isCharPotentialHeader(line, i)); // check the word const size_t keywordLength = keyword.length(); @@ -677,20 +678,25 @@ bool ASBase::findKeyword(const string& line, int i, const string& keyword) const if (line.compare(i, keywordLength, keyword) != 0) return false; // check that this is not part of a longer word - if (wordEnd == line.length()) + if (wordEnd == line.length()) { + //std::cerr << "findKeyword t1 \n"; return true; + } + if (isLegalNameChar(line[wordEnd])) return false; // is not a keyword if part of a definition const char peekChar = peekNextChar(line, (int) wordEnd - 1); if (peekChar == ',' || peekChar == ')') return false; + + //std::cerr << "findKeyword t2 \n"; return true; } // check if a specific line position contains an operator. -const string* ASBase::findOperator(const string& line, int i, - const vector* possibleOperators) const +const std::string* ASBase::findOperator(const std::string& line, int i, + const std::vector* possibleOperators) const { assert(isCharPotentialOperator(line[i])); // find the operator in the vector @@ -710,7 +716,7 @@ const string* ASBase::findOperator(const string& line, int i, // get the current word on a line // index must point to the beginning of the word -string ASBase::getCurrentWord(const string& line, size_t index) const +std::string ASBase::getCurrentWord(const std::string& line, size_t index) const { assert(isCharPotentialHeader(line, index)); size_t lineLength = line.length(); @@ -737,7 +743,7 @@ bool ASBase::isLegalNameChar(char ch) const } // check if a specific character can be part of a header -bool ASBase::isCharPotentialHeader(const string& line, size_t i) const +bool ASBase::isCharPotentialHeader(const std::string& line, size_t i) const { assert(!isWhiteSpace(line[i])); char prevCh = ' '; @@ -773,7 +779,7 @@ bool ASBase::isDigit(char ch) const } // check if a specific character is a digit separator -bool ASBase::isDigitSeparator(const string& line, int i) const +bool ASBase::isDigitSeparator(const std::string& line, int i) const { assert(line[i] == '\''); // casting to (unsigned char) eliminates negative characters @@ -786,11 +792,11 @@ bool ASBase::isDigitSeparator(const string& line, int i) const } // peek at the next unread character. -char ASBase::peekNextChar(const string& line, int i) const +char ASBase::peekNextChar(const std::string& line, int i) const { char ch = ' '; size_t peekNum = line.find_first_not_of(" \t", i + 1); - if (peekNum == string::npos) + if (peekNum == std::string::npos) return ch; ch = line[peekNum]; return ch; diff --git a/AStyle/src/astyle.h b/AStyle/src/astyle.h index d661b65..a572244 100644 --- a/AStyle/src/astyle.h +++ b/AStyle/src/astyle.h @@ -57,8 +57,6 @@ //----------------------------------------------------------------------------- namespace astyle { -// -using namespace std; //---------------------------------------------------------------------------- // definitions @@ -188,13 +186,13 @@ class ASSourceIterator public: ASSourceIterator() = default; virtual ~ASSourceIterator() = default; - virtual streamoff getPeekStart() const = 0; + virtual std::streamoff getPeekStart() const = 0; virtual int getStreamLength() const = 0; virtual bool hasMoreLines() const = 0; - virtual string nextLine(bool emptyLineWasDeleted) = 0; - virtual string peekNextLine() = 0; + virtual std::string nextLine(bool emptyLineWasDeleted) = 0; + virtual std::string peekNextLine() = 0; virtual void peekReset() = 0; - virtual streamoff tellg() = 0; + virtual std::streamoff tellg() = 0; }; //----------------------------------------------------------------------------- @@ -220,7 +218,7 @@ class ASPeekStream bool hasMoreLines() const { return sourceIterator->hasMoreLines(); } - string peekNextLine() + std::string peekNextLine() { needReset = true; return sourceIterator->peekNextLine(); } }; @@ -232,61 +230,61 @@ class ASPeekStream class ASResource { public: - void buildAssignmentOperators(vector* assignmentOperators); - void buildCastOperators(vector* castOperators); - void buildHeaders(vector* headers, int fileType, bool beautifier = false); - void buildIndentableMacros(vector* >* indentableMacros); - void buildIndentableHeaders(vector* indentableHeaders); - void buildNonAssignmentOperators(vector* nonAssignmentOperators); - void buildNonParenHeaders(vector* nonParenHeaders, int fileType, bool beautifier = false); - void buildOperators(vector* operators, int fileType); - void buildPreBlockStatements(vector* preBlockStatements, int fileType); - void buildPreCommandHeaders(vector* preCommandHeaders, int fileType); - void buildPreDefinitionHeaders(vector* preDefinitionHeaders, int fileType); + void buildAssignmentOperators(std::vector* assignmentOperators); + void buildCastOperators(std::vector* castOperators); + void buildHeaders(std::vector* headers, int fileType, bool beautifier = false); + void buildIndentableMacros(std::vector* >* indentableMacros); + void buildIndentableHeaders(std::vector* indentableHeaders); + void buildNonAssignmentOperators(std::vector* nonAssignmentOperators); + void buildNonParenHeaders(std::vector* nonParenHeaders, int fileType, bool beautifier = false); + void buildOperators(std::vector* operators, int fileType); + void buildPreBlockStatements(std::vector* preBlockStatements, int fileType); + void buildPreCommandHeaders(std::vector* preCommandHeaders, int fileType); + void buildPreDefinitionHeaders(std::vector* preDefinitionHeaders, int fileType); public: - static const string AS_IF, AS_ELSE; - static const string AS_DO, AS_WHILE; - static const string AS_FOR; - static const string AS_SWITCH, AS_CASE, AS_DEFAULT; - static const string AS_TRY, AS_CATCH, AS_THROW, AS_THROWS, AS_FINALLY, AS_USING; - static const string _AS_TRY, _AS_FINALLY, _AS_EXCEPT; - static const string AS_PUBLIC, AS_PROTECTED, AS_PRIVATE; - static const string AS_CLASS, AS_STRUCT, AS_TYPEDEF_STRUCT, AS_UNION, AS_INTERFACE, AS_NAMESPACE; - static const string AS_MODULE; - static const string AS_END; - static const string AS_SELECTOR; - static const string AS_EXTERN, AS_ENUM; - static const string AS_FINAL, AS_OVERRIDE; - static const string AS_STATIC, AS_CONST, AS_SEALED, AS_VOLATILE, AS_NEW, AS_DELETE; - static const string AS_NOEXCEPT, AS_INTERRUPT, AS_AUTORELEASEPOOL; - static const string AS_WHERE, AS_LET, AS_SYNCHRONIZED; - static const string AS_OPERATOR, AS_TEMPLATE; - static const string AS_OPEN_PAREN, AS_CLOSE_PAREN; - static const string AS_OPEN_BRACE, AS_CLOSE_BRACE; - static const string AS_OPEN_LINE_COMMENT, AS_OPEN_COMMENT, AS_CLOSE_COMMENT; - static const string AS_BAR_DEFINE, AS_BAR_INCLUDE, AS_BAR_IF, AS_BAR_EL, AS_BAR_ENDIF; - static const string AS_AUTO, AS_RETURN; - static const string AS_CIN, AS_COUT, AS_CERR; - static const string AS_ASSIGN, AS_PLUS_ASSIGN, AS_MINUS_ASSIGN, AS_MULT_ASSIGN; - static const string AS_DIV_ASSIGN, AS_MOD_ASSIGN, AS_XOR_ASSIGN, AS_OR_ASSIGN, AS_AND_ASSIGN; - static const string AS_GR_GR_ASSIGN, AS_LS_LS_ASSIGN, AS_GR_GR_GR_ASSIGN, AS_LS_LS_LS_ASSIGN; - static const string AS_GCC_MIN_ASSIGN, AS_GCC_MAX_ASSIGN, AS_SPACESHIP, AS_EQUAL_JS; - static const string AS_EQUAL, AS_PLUS_PLUS, AS_MINUS_MINUS, AS_NOT_EQUAL, AS_GR_EQUAL; - static const string AS_LS_EQUAL, AS_LS_LS_LS, AS_LS_LS, AS_GR_GR_GR, AS_GR_GR; - static const string AS_QUESTION_QUESTION, AS_LAMBDA; - static const string AS_ARROW, AS_AND, AS_OR; - static const string AS_SCOPE_RESOLUTION; - static const string AS_PLUS, AS_MINUS, AS_MULT, AS_DIV, AS_MOD, AS_GR, AS_LS; - static const string AS_NOT, AS_BIT_XOR, AS_BIT_OR, AS_BIT_AND, AS_BIT_NOT; - static const string AS_QUESTION, AS_COLON, AS_SEMICOLON, AS_COMMA; - static const string AS_ASM, AS__ASM__, AS_MS_ASM, AS_MS__ASM; - static const string AS_QFOREACH, AS_QFOREVER, AS_FOREVER; - static const string AS_FOREACH, AS_LOCK, AS_UNSAFE, AS_FIXED; - static const string AS_GET, AS_SET, AS_ADD, AS_REMOVE; - static const string AS_DELEGATE, AS_UNCHECKED; - static const string AS_CONST_CAST, AS_DYNAMIC_CAST, AS_REINTERPRET_CAST, AS_STATIC_CAST; - static const string AS_NS_DURING, AS_NS_HANDLER; + static const std::string AS_IF, AS_ELSE; + static const std::string AS_DO, AS_WHILE; + static const std::string AS_FOR; + static const std::string AS_SWITCH, AS_CASE, AS_DEFAULT; + static const std::string AS_TRY, AS_CATCH, AS_THROW, AS_THROWS, AS_FINALLY, AS_USING; + static const std::string _AS_TRY, _AS_FINALLY, _AS_EXCEPT; + static const std::string AS_PUBLIC, AS_PROTECTED, AS_PRIVATE; + static const std::string AS_CLASS, AS_STRUCT, AS_TYPEDEF_STRUCT, AS_UNION, AS_INTERFACE, AS_NAMESPACE; + static const std::string AS_MODULE; + static const std::string AS_END; + static const std::string AS_SELECTOR; + static const std::string AS_EXTERN, AS_ENUM; + static const std::string AS_FINAL, AS_OVERRIDE; + static const std::string AS_STATIC, AS_CONST, AS_SEALED, AS_VOLATILE, AS_NEW, AS_DELETE; + static const std::string AS_NOEXCEPT, AS_INTERRUPT, AS_AUTORELEASEPOOL; + static const std::string AS_WHERE, AS_LET, AS_SYNCHRONIZED; + static const std::string AS_OPERATOR, AS_TEMPLATE; + static const std::string AS_OPEN_PAREN, AS_CLOSE_PAREN; + static const std::string AS_OPEN_BRACE, AS_CLOSE_BRACE; + static const std::string AS_OPEN_LINE_COMMENT, AS_OPEN_COMMENT, AS_CLOSE_COMMENT; + static const std::string AS_BAR_DEFINE, AS_BAR_INCLUDE, AS_BAR_IF, AS_BAR_EL, AS_BAR_ENDIF; + static const std::string AS_AUTO, AS_RETURN; + static const std::string AS_CIN, AS_COUT, AS_CERR; + static const std::string AS_ASSIGN, AS_PLUS_ASSIGN, AS_MINUS_ASSIGN, AS_MULT_ASSIGN; + static const std::string AS_DIV_ASSIGN, AS_MOD_ASSIGN, AS_XOR_ASSIGN, AS_OR_ASSIGN, AS_AND_ASSIGN; + static const std::string AS_GR_GR_ASSIGN, AS_LS_LS_ASSIGN, AS_GR_GR_GR_ASSIGN, AS_LS_LS_LS_ASSIGN; + static const std::string AS_GCC_MIN_ASSIGN, AS_GCC_MAX_ASSIGN, AS_SPACESHIP, AS_EQUAL_JS; + static const std::string AS_EQUAL, AS_PLUS_PLUS, AS_MINUS_MINUS, AS_NOT_EQUAL, AS_GR_EQUAL; + static const std::string AS_LS_EQUAL, AS_LS_LS_LS, AS_LS_LS, AS_GR_GR_GR, AS_GR_GR; + static const std::string AS_QUESTION_QUESTION, AS_LAMBDA; + static const std::string AS_ARROW, AS_AND, AS_OR; + static const std::string AS_SCOPE_RESOLUTION; + static const std::string AS_PLUS, AS_MINUS, AS_MULT, AS_DIV, AS_MOD, AS_GR, AS_LS; + static const std::string AS_NOT, AS_BIT_XOR, AS_BIT_OR, AS_BIT_AND, AS_BIT_NOT; + static const std::string AS_QUESTION, AS_COLON, AS_SEMICOLON, AS_COMMA; + static const std::string AS_ASM, AS__ASM__, AS_MS_ASM, AS_MS__ASM; + static const std::string AS_QFOREACH, AS_QFOREVER, AS_FOREVER; + static const std::string AS_FOREACH, AS_LOCK, AS_UNSAFE, AS_FIXED; + static const std::string AS_GET, AS_SET, AS_ADD, AS_REMOVE; + static const std::string AS_DELEGATE, AS_UNCHECKED; + static const std::string AS_CONST_CAST, AS_DYNAMIC_CAST, AS_REINTERPRET_CAST, AS_STATIC_CAST; + static const std::string AS_NS_DURING, AS_NS_HANDLER; }; // Class ASResource //----------------------------------------------------------------------------- @@ -314,18 +312,18 @@ class ASBase : protected ASResource bool isWhiteSpace(char ch) const { return (ch == ' ' || ch == '\t'); } protected: // functions definitions are at the end of ASResource.cpp - const string* findHeader(const string& line, int i, - const vector* possibleHeaders) const; - bool findKeyword(const string& line, int i, const string& keyword) const; - const string* findOperator(const string& line, int i, - const vector* possibleOperators) const; - string getCurrentWord(const string& line, size_t index) const; + const std::string* findHeader(const std::string& line, int i, + const std::vector* possibleHeaders) const; + bool findKeyword(const std::string& line, int i, const std::string& keyword) const; + const std::string* findOperator(const std::string& line, int i, + const std::vector* possibleOperators) const; + std::string getCurrentWord(const std::string& line, size_t index) const; bool isDigit(char ch) const; bool isLegalNameChar(char ch) const; - bool isCharPotentialHeader(const string& line, size_t i) const; + bool isCharPotentialHeader(const std::string& line, size_t i) const; bool isCharPotentialOperator(char ch) const; - bool isDigitSeparator(const string& line, int i) const; - char peekNextChar(const string& line, int i) const; + bool isDigitSeparator(const std::string& line, int i) const; + char peekNextChar(const std::string& line, int i) const; }; // Class ASBase @@ -344,7 +342,7 @@ class ASBeautifier : protected ASBase ASBeautifier& operator=(ASBeautifier&&) = delete; virtual void init(ASSourceIterator* iter); - virtual string beautify(const string& originalLine); + virtual std::string beautify(const std::string& originalLine); void setCaseIndent(bool state); void setClassIndent(bool state); void setContinuationIndentation(int indent = 1); @@ -376,8 +374,8 @@ class ASBeautifier : protected ASBase int getFileType() const; int getIndentLength() const; int getTabLength() const; - string getIndentString() const; - string getNextWord(const string& line, size_t currPos) const; + std::string getIndentString() const; + std::string getNextWord(const std::string& line, size_t currPos) const; bool getAlignMethodColon() const; bool getBraceIndent() const; bool getBlockIndent() const; @@ -393,14 +391,14 @@ class ASBeautifier : protected ASBase protected: void deleteBeautifierVectors(); - int getNextProgramCharDistance(const string& line, int i) const; - int indexOf(const vector& container, const string* element) const; + int getNextProgramCharDistance(const std::string& line, int i) const; + int indexOf(const std::vector& container, const std::string* element) const; void setBlockIndent(bool state); void setBraceIndent(bool state); void setBraceIndentVtk(bool state); - string extractPreprocessorStatement(const string& line) const; - string trim(const string& str) const; - string rtrim(const string& str) const; + std::string extractPreprocessorStatement(const std::string& line) const; + std::string trim(const std::string& str) const; + std::string rtrim(const std::string& str) const; // variables set by ASFormatter - must be updated in activeBeautifierStack int inLineNumber; @@ -419,75 +417,75 @@ class ASBeautifier : protected ASBase bool isInIndentablePreproc; private: // functions - void adjustObjCMethodDefinitionIndentation(const string& line_); - void adjustObjCMethodCallIndentation(const string& line_); + void adjustObjCMethodDefinitionIndentation(const std::string& line_); + void adjustObjCMethodCallIndentation(const std::string& line_); void adjustParsedLineIndentation(size_t iPrelim, bool isInExtraHeaderIndent); void computePreliminaryIndentation(); - void parseCurrentLine(const string& line); + void parseCurrentLine(const std::string& line); void popLastContinuationIndent(); - void processPreprocessor(const string& preproc, const string& line); - void registerContinuationIndent(const string& line, int i, int spaceIndentCount_, + void processPreprocessor(const std::string& preproc, const std::string& line); + void registerContinuationIndent(const std::string& line, int i, int spaceIndentCount_, int tabIncrementIn, int minIndent, bool updateParenStack); - void registerContinuationIndentColon(const string& line, int i, int tabIncrementIn); + void registerContinuationIndentColon(const std::string& line, int i, int tabIncrementIn); void initVectors(); - void initTempStacksContainer(vector*>*& container, - vector*>* value); + void initTempStacksContainer(std::vector*>*& container, + std::vector*>* value); void clearObjCMethodDefinitionAlignment(); - void deleteBeautifierContainer(vector*& container); - void deleteTempStacksContainer(vector*>*& container); + void deleteBeautifierContainer(std::vector*& container); + void deleteTempStacksContainer(std::vector*>*& container); int adjustIndentCountForBreakElseIfComments() const; - int computeObjCColonAlignment(const string& line, int colonAlignPosition) const; + int computeObjCColonAlignment(const std::string& line, int colonAlignPosition) const; int convertTabToSpaces(int i, int tabIncrementIn) const; - int findObjCColonAlignment(const string& line) const; - int getContinuationIndentAssign(const string& line, size_t currPos) const; - int getContinuationIndentComma(const string& line, size_t currPos) const; - int getObjCFollowingKeyword(const string& line, int bracePos) const; - bool isIndentedPreprocessor(const string& line, size_t currPos) const; - bool isLineEndComment(const string& line, int startPos) const; - bool isPreprocessorConditionalCplusplus(const string& line) const; - bool isInPreprocessorUnterminatedComment(const string& line); + int findObjCColonAlignment(const std::string& line) const; + int getContinuationIndentAssign(const std::string& line, size_t currPos) const; + int getContinuationIndentComma(const std::string& line, size_t currPos) const; + int getObjCFollowingKeyword(const std::string& line, int bracePos) const; + bool isIndentedPreprocessor(const std::string& line, size_t currPos) const; + bool isLineEndComment(const std::string& line, int startPos) const; + bool isPreprocessorConditionalCplusplus(const std::string& line) const; + bool isInPreprocessorUnterminatedComment(const std::string& line); bool isTopLevel() const; - bool statementEndsWithComma(const string& line, int index) const; - const string& getIndentedLineReturn(const string& newLine, const string& originalLine) const; - string getIndentedSpaceEquivalent(const string& line_) const; - string preLineWS(int lineIndentCount, int lineSpaceIndentCount) const; + bool statementEndsWithComma(const std::string& line, int index) const; + const std::string& getIndentedLineReturn(const std::string& newLine, const std::string& originalLine) const; + std::string getIndentedSpaceEquivalent(const std::string& line_) const; + std::string preLineWS(int lineIndentCount, int lineSpaceIndentCount) const; template void deleteContainer(T& container); template void initContainer(T& container, T value); - vector*>* copyTempStacks(const ASBeautifier& other) const; - pair computePreprocessorIndent(); + std::vector*>* copyTempStacks(const ASBeautifier& other) const; + std::pair computePreprocessorIndent(); private: // variables int beautifierFileType; - vector* headers; - vector* nonParenHeaders; - vector* preBlockStatements; - vector* preCommandHeaders; - vector* assignmentOperators; - vector* nonAssignmentOperators; - vector* indentableHeaders; - - vector* waitingBeautifierStack; - vector* activeBeautifierStack; - vector* waitingBeautifierStackLengthStack; - vector* activeBeautifierStackLengthStack; - vector* headerStack; - vector* >* tempStacks; - vector* parenDepthStack; - vector* blockStatementStack; - vector* parenStatementStack; - vector* braceBlockStateStack; - vector* continuationIndentStack; - vector* continuationIndentStackSizeStack; - vector* parenIndentStack; - vector >* preprocIndentStack; + std::vector* headers; + std::vector* nonParenHeaders; + std::vector* preBlockStatements; + std::vector* preCommandHeaders; + std::vector* assignmentOperators; + std::vector* nonAssignmentOperators; + std::vector* indentableHeaders; + + std::vector* waitingBeautifierStack; + std::vector* activeBeautifierStack; + std::vector* waitingBeautifierStackLengthStack; + std::vector* activeBeautifierStackLengthStack; + std::vector* headerStack; + std::vector* >* tempStacks; + std::vector* parenDepthStack; + std::vector* blockStatementStack; + std::vector* parenStatementStack; + std::vector* braceBlockStateStack; + std::vector* continuationIndentStack; + std::vector* continuationIndentStackSizeStack; + std::vector* parenIndentStack; + std::vector >* preprocIndentStack; ASSourceIterator* sourceIterator; - const string* currentHeader; - const string* previousLastLineHeader; - const string* probationHeader; - const string* lastLineHeader; - string indentString; - string verbatimDelimiter; + const std::string* currentHeader; + const std::string* previousLastLineHeader; + const std::string* probationHeader; + const std::string* lastLineHeader; + std::string indentString; + std::string verbatimDelimiter; bool isInQuote; bool isInVerbatimQuote; bool haveLineContinuationChar; @@ -554,6 +552,7 @@ class ASBeautifier : protected ASBase bool foundPreCommandMacro; bool shouldAlignMethodColon; bool shouldIndentPreprocConditional; + bool lambdaIndicator; int indentCount; int spaceIndentCount; int spaceIndentObjCMethodAlignment; @@ -593,20 +592,20 @@ class ASEnhancer : protected ASBase public: // functions ASEnhancer() = default; void init(int, int, int, bool, bool, bool, bool, bool, bool, bool, - vector* >*); - void enhance(string& line, bool isInNamespace, bool isInPreprocessor, bool isInSQL); + std::vector* >*); + void enhance(std::string& line, bool isInNamespace, bool isInPreprocessor, bool isInSQL); private: // functions - void convertForceTabIndentToSpaces(string& line) const; - void convertSpaceIndentToForceTab(string& line) const; - size_t findCaseColon(const string& line, size_t caseIndex) const; - int indentLine(string& line, int indent) const; - bool isBeginDeclareSectionSQL(const string& line, size_t index) const; - bool isEndDeclareSectionSQL(const string& line, size_t index) const; - bool isOneLineBlockReached(const string& line, int startChar) const; - void parseCurrentLine(string& line, bool isInPreprocessor, bool isInSQL); - size_t processSwitchBlock(string& line, size_t index); - int unindentLine(string& line, int unindent) const; + void convertForceTabIndentToSpaces(std::string& line) const; + void convertSpaceIndentToForceTab(std::string& line) const; + size_t findCaseColon(const std::string& line, size_t caseIndex) const; + int indentLine(std::string& line, int indent) const; + bool isBeginDeclareSectionSQL(const std::string& line, size_t index) const; + bool isEndDeclareSectionSQL(const std::string& line, size_t index) const; + bool isOneLineBlockReached(const std::string& line, int startChar) const; + void parseCurrentLine(std::string& line, bool isInPreprocessor, bool isInSQL); + size_t processSwitchBlock(std::string& line, size_t index); + int unindentLine(std::string& line, int unindent) const; private: // options from command line or options file @@ -645,12 +644,12 @@ class ASEnhancer : protected ASBase }; SwitchVariables sw; // switch variables struct - vector switchStack; // stack vector of switch variables + std::vector switchStack; // stack std::vector of switch variables // event table variables bool nextLineIsEventIndent; // begin event table indent is reached bool isInEventTable; // need to indent an event table - vector* >* indentableMacros; + std::vector* >* indentableMacros; // SQL variables bool nextLineIsDeclareIndent; // begin declare section indent is reached @@ -674,7 +673,7 @@ class ASFormatter : public ASBeautifier void init(ASSourceIterator* si) override; bool hasMoreLines() const; - string nextLine(); + std::string nextLine(); LineEndFormat getLineEndFormat() const; bool getIsLineReady() const; void setFormattingStyle(FormatStyle style); @@ -742,8 +741,8 @@ class ASFormatter : public ASBeautifier char peekNextChar() const; BraceType getBraceType(); bool adjustChecksumIn(int adjustment); - bool computeChecksumIn(const string& currentLine_); - bool computeChecksumOut(const string& beautifiedLine); + bool computeChecksumIn(const std::string& currentLine_); + bool computeChecksumOut(const std::string& beautifiedLine); bool addBracesToStatement(); bool removeBracesFromStatement(); bool commentAndHeaderFollows(); @@ -756,25 +755,25 @@ class ASFormatter : public ASBeautifier bool isBeforeMultipleLineEndComments(int startPos) const; bool isBraceType(BraceType a, BraceType b) const; bool isClassInitializer() const; - bool isClosingHeader(const string* header) const; + bool isClosingHeader(const std::string* header) const; bool isCurrentBraceBroken() const; bool isDereferenceOrAddressOf() const; - bool isExecSQL(const string& line, size_t index) const; - bool isEmptyLine(const string& line) const; + bool isExecSQL(const std::string& line, size_t index) const; + bool isEmptyLine(const std::string& line) const; bool isExternC() const; bool isMultiStatementLine() const; bool isNextWordSharpNonParenHeader(int startChar) const; bool isNonInStatementArrayBrace() const; - bool isNumericVariable(const string& word) const; + bool isNumericVariable(const std::string& word) const; bool isOkToSplitFormattedLine(); bool isPointerOrReference() const; bool isPointerOrReferenceCentered() const; - bool isPointerOrReferenceVariable(const string& word) const; - bool isPointerToPointer(const string& line, int currPos) const; - bool isSharpStyleWithParen(const string* header) const; - bool isStructAccessModified(const string& firstLine, size_t index) const; - bool isIndentablePreprocessorBlock(const string& firstLine, size_t index); - bool isNDefPreprocStatement(const string& nextLine_, const string& preproc) const; + bool isPointerOrReferenceVariable(const std::string& word) const; + bool isPointerToPointer(const std::string& line, int currPos) const; + bool isSharpStyleWithParen(const std::string* header) const; + bool isStructAccessModified(const std::string& firstLine, size_t index) const; + bool isIndentablePreprocessorBlock(const std::string& firstLine, size_t index); + bool isNDefPreprocStatement(const std::string& nextLine_, const std::string& preproc) const; bool isUnaryOperator() const; bool isUniformInitializerBrace() const; bool isImmediatelyPostCast() const; @@ -787,24 +786,24 @@ class ASFormatter : public ASBeautifier int findObjCColonAlignment() const; int getCurrentLineCommentAdjustment(); int getNextLineCommentAdjustment(); - int isOneLineBlockReached(const string& line, int startChar) const; + int isOneLineBlockReached(const std::string& line, int startChar) const; void adjustComments(); void appendChar(char ch, bool canBreakLine); void appendCharInsideComments(); void appendClosingHeader(); - void appendOperator(const string& sequence, bool canBreakLine = true); - void appendSequence(const string& sequence, bool canBreakLine = true); + void appendOperator(const std::string& sequence, bool canBreakLine = true); + void appendSequence(const std::string& sequence, bool canBreakLine = true); void appendSpacePad(); void appendSpaceAfter(); void breakLine(bool isSplitLine = false); void buildLanguageVectors(); void updateFormattedLineSplitPoints(char appendedChar); - void updateFormattedLineSplitPointsOperator(const string& sequence); + void updateFormattedLineSplitPointsOperator(const std::string& sequence); void checkIfTemplateOpener(); void clearFormattedLineSplitPoints(); void convertTabToSpaces(); - void deleteContainer(vector*& container); - void findReturnTypeSplitPoint(const string& firstLine); + void deleteContainer(std::vector*& container); + void findReturnTypeSplitPoint(const std::string& firstLine); void formatArrayRunIn(); void formatRunIn(); void formatArrayBraces(BraceType braceType, bool isOpeningArrayBrace); @@ -825,13 +824,13 @@ class ASFormatter : public ASBeautifier void fixOptionVariableConflicts(); void goForward(int i); void isLineBreakBeforeClosingHeader(); - void initContainer(vector*& container, vector* value); + void initContainer(std::vector*& container, std::vector* value); void initNewLine(); void padObjCMethodColon(); void padObjCMethodPrefix(); void padObjCParamType(); void padObjCReturnType(); - void padOperators(const string* newOperator); + void padOperators(const std::string* newOperator); void padParens(); void processPreprocessor(); void resetEndOfStatement(); @@ -841,45 +840,45 @@ class ASFormatter : public ASBeautifier void trimContinuationLine(); void updateFormattedLineSplitPointsPointerOrReference(size_t index); size_t findFormattedLineSplitPoint() const; - size_t findNextChar(const string& line, char searchChar, int searchStart = 0) const; - const string* checkForHeaderFollowingComment(const string& firstLine) const; - const string* getFollowingOperator() const; - string getPreviousWord(const string& line, int currPos) const; - string peekNextText(const string& firstLine, + size_t findNextChar(const std::string& line, char searchChar, int searchStart = 0) const; + const std::string* checkForHeaderFollowingComment(const std::string& firstLine) const; + const std::string* getFollowingOperator() const; + std::string getPreviousWord(const std::string& line, int currPos) const; + std::string peekNextText(const std::string& firstLine, bool endOnEmptyLine = false, - const shared_ptr& streamArg = nullptr) const; + const std::shared_ptr& streamArg = nullptr) const; private: // variables int formatterFileType; - vector* headers; - vector* nonParenHeaders; - vector* preDefinitionHeaders; - vector* preCommandHeaders; - vector* operators; - vector* assignmentOperators; - vector* castOperators; - vector* >* indentableMacros; // for ASEnhancer + std::vector* headers; + std::vector* nonParenHeaders; + std::vector* preDefinitionHeaders; + std::vector* preCommandHeaders; + std::vector* operators; + std::vector* assignmentOperators; + std::vector* castOperators; + std::vector* >* indentableMacros; // for ASEnhancer ASSourceIterator* sourceIterator; ASEnhancer* enhancer; - vector* preBraceHeaderStack; - vector* braceTypeStack; - vector* parenStack; - vector* structStack; - vector* questionMarkStack; - - string currentLine; - string formattedLine; - string readyFormattedLine; - string verbatimDelimiter; - const string* currentHeader; + std::vector* preBraceHeaderStack; + std::vector* braceTypeStack; + std::vector* parenStack; + std::vector* structStack; + std::vector* questionMarkStack; + + std::string currentLine; + std::string formattedLine; + std::string readyFormattedLine; + std::string verbatimDelimiter; + const std::string* currentHeader; char currentChar; char previousChar; char previousNonWSChar; char previousCommandChar; char quoteChar; - streamoff preprocBlockEnd; + std::streamoff preprocBlockEnd; int charNum; int runInIndentChars; int nextLineSpacePadNum; @@ -889,6 +888,7 @@ class ASFormatter : public ASBeautifier int tabIncrementIn; int templateDepth; int squareBracketCount; + size_t checksumIn; size_t checksumOut; size_t currentLineFirstBraceNum; // first brace location on currentLine @@ -1078,11 +1078,11 @@ class ASFormatter : public ASBeautifier { return currentLine.compare(charNum, strlen(sequence), sequence) == 0; } // call ASBase::findHeader for the current character - const string* findHeader(const vector* headers_) + const std::string* findHeader(const std::vector* headers_) { return ASBase::findHeader(currentLine, charNum, headers_); } // call ASBase::findOperator for the current character - const string* findOperator(const vector* operators_) + const std::string* findOperator(const std::vector* operators_) { return ASBase::findOperator(currentLine, charNum, operators_); } }; // Class ASFormatter @@ -1090,8 +1090,8 @@ class ASFormatter : public ASBeautifier // astyle namespace global declarations //----------------------------------------------------------------------------- // sort comparison functions for ASResource -bool sortOnLength(const string* a, const string* b); -bool sortOnName(const string* a, const string* b); +bool sortOnLength(const std::string* a, const std::string* b); +bool sortOnName(const std::string* a, const std::string* b); } // namespace astyle diff --git a/AStyle/src/astyle_main.cpp b/AStyle/src/astyle_main.cpp index 28bd246..276e518 100644 --- a/AStyle/src/astyle_main.cpp +++ b/AStyle/src/astyle_main.cpp @@ -94,7 +94,7 @@ namespace astyle { jmethodID g_mid; #endif -const char* g_version = "3.2.1"; +const char* g_version = "3.3 beta"; //----------------------------------------------------------------------------- // ASStreamIterator class @@ -141,7 +141,7 @@ int ASStreamIterator::getStreamLength() const * @return string containing the next input line minus any end of line characters */ template -string ASStreamIterator::nextLine(bool emptyLineWasDeleted) +std::string ASStreamIterator::nextLine(bool emptyLineWasDeleted) { // verify that the current position is correct assert(peekStart == 0); @@ -236,10 +236,10 @@ string ASStreamIterator::nextLine(bool emptyLineWasDeleted) // when finished peeking you MUST call peekReset() // call this function from ASFormatter ONLY template -string ASStreamIterator::peekNextLine() +std::string ASStreamIterator::peekNextLine() { assert(hasMoreLines()); - string nextLine_; + std::string nextLine_; char ch; if (!peekStart) @@ -290,7 +290,7 @@ void ASStreamIterator::saveLastInputLine() // return position of the get pointer template -streamoff ASStreamIterator::tellg() +std::streamoff ASStreamIterator::tellg() { return inStream->tellg(); } @@ -332,7 +332,7 @@ bool ASStreamIterator::getLineEndChange(int lineEndFormat) const ASConsole::ASConsole(ASFormatter& formatterArg) : formatter(formatterArg) { - errorStream = &cerr; + errorStream = &std::cerr; // command line options isRecursive = false; isDryRun = false; @@ -357,11 +357,11 @@ ASConsole::ASConsole(ASFormatter& formatterArg) : formatter(formatterArg) } // rewrite a stringstream converting the line ends -void ASConsole::convertLineEnds(ostringstream& out, int lineEnd) +void ASConsole::convertLineEnds(std::ostringstream& out, int lineEnd) { assert(lineEnd == LINEEND_WINDOWS || lineEnd == LINEEND_LINUX || lineEnd == LINEEND_MACOLD); - const string& inStr = out.str(); // avoids strange looking syntax - string outStr; // the converted output + const std::string& inStr = out.str(); // avoids strange looking syntax + std::string outStr; // the converted output int inLength = (int) inStr.length(); for (int pos = 0; pos < inLength; pos++) { @@ -494,7 +494,7 @@ void ASConsole::convertLineEnds(std::ostringstream& out, int lineEnd) { */ -void ASConsole::correctMixedLineEnds(ostringstream& out) +void ASConsole::correctMixedLineEnds(std::ostringstream& out) { LineEndFormat lineEndFormat = LINEEND_DEFAULT; if (outputEOL == "\r\n") @@ -545,14 +545,14 @@ FileEncoding ASConsole::detectEncoding(const char* data, size_t dataSize) const // error exit without a message void ASConsole::error() const { - (*errorStream) << _("Artistic Style has terminated\n") << endl; + (*errorStream) << _("Artistic Style has terminated\n") << std::endl; exit(EXIT_FAILURE); } // error exit with a message void ASConsole::error(const char* why, const char* what) const { - (*errorStream) << why << ' ' << what << endl; + (*errorStream) << why << ' ' << what << std::endl; error(); } @@ -582,8 +582,8 @@ void ASConsole::formatCinToCout() // The Linux cin.tellg() will return -1 (invalid). // Copying the input sequentially to a stringstream before // formatting solves the problem for both. - istream* inStream = &cin; - stringstream outStream; + std::istream* inStream = &std::cin; + std::stringstream outStream; char ch; inStream->get(ch); while (!inStream->eof() && !inStream->fail()) @@ -591,7 +591,7 @@ void ASConsole::formatCinToCout() outStream.put(ch); inStream->get(ch); } - ASStreamIterator streamIterator(&outStream); + ASStreamIterator streamIterator(&outStream); // Windows pipe or redirection always outputs Windows line-ends. // Linux pipe or redirection will output any line end. #ifdef _WIN32 @@ -604,11 +604,11 @@ void ASConsole::formatCinToCout() while (formatter.hasMoreLines()) { - cout << formatter.nextLine(); + std::cout << formatter.nextLine(); if (formatter.hasMoreLines()) { setOutputEOL(lineEndFormat, streamIterator.getOutputEOL()); - cout << outputEOL; + std::cout << outputEOL; } else { @@ -616,12 +616,12 @@ void ASConsole::formatCinToCout() if (formatter.getIsLineReady()) { setOutputEOL(lineEndFormat, streamIterator.getOutputEOL()); - cout << outputEOL; - cout << formatter.nextLine(); + std::cout << outputEOL; + std::cout << formatter.nextLine(); } } } - cout.flush(); + std::cout.flush(); } /** @@ -629,31 +629,31 @@ void ASConsole::formatCinToCout() * * @param fileName_ The path and name of the file to be processed. */ -void ASConsole::formatFile(const string& fileName_) +void ASConsole::formatFile(const std::string& fileName_) { - stringstream in; - ostringstream out; + std::stringstream in; + std::ostringstream out; FileEncoding encoding = readFile(fileName_, in); // Unless a specific language mode has been set, set the language mode // according to the file's suffix. if (!formatter.getModeManuallySet()) { - if (stringEndsWith(fileName_, string(".java"))) + if (stringEndsWith(fileName_, std::string(".java"))) formatter.setJavaStyle(); - else if (stringEndsWith(fileName_, string(".cs"))) + else if (stringEndsWith(fileName_, std::string(".cs"))) formatter.setSharpStyle(); else formatter.setCStyle(); } // set line end format - string nextLine; // next output line + std::string nextLine; // next output line filesAreIdentical = true; // input and output files are identical LineEndFormat lineEndFormat = formatter.getLineEndFormat(); initializeOutputEOL(lineEndFormat); // do this AFTER setting the file mode - ASStreamIterator streamIterator(&in); + ASStreamIterator streamIterator(&in); formatter.init(&streamIterator); // format the file @@ -686,7 +686,7 @@ void ASConsole::formatFile(const string& fileName_) { if (streamIterator.checkForEmptyLine) { - if (nextLine.find_first_not_of(" \t") != string::npos) + if (nextLine.find_first_not_of(" \t") != std::string::npos) filesAreIdentical = false; } else if (!streamIterator.compareToInputBuffer(nextLine)) @@ -702,7 +702,7 @@ void ASConsole::formatFile(const string& fileName_) } // remove targetDirectory from filename if required by print - string displayName; + std::string displayName; if (hasWildcard) displayName = fileName_.substr(targetDirectory.length() + 1); else @@ -737,22 +737,22 @@ void ASConsole::formatFile(const string& fileName_) * nearest parent directory if found, otherwise an empty * string. */ -string ASConsole::findProjectOptionFilePath(const string& fileName_) const +std::string ASConsole::findProjectOptionFilePath(const std::string& fileName_) const { - string parent; + std::string parent; if (!fileNameVector.empty()) { - string first = fileNameVector.front(); + std::string first = fileNameVector.front(); - if (first.find_first_of("*?") != string::npos) + if (first.find_first_of("*?") != std::string::npos) { // First item has wildcards - get rid of them for now size_t endPath = first.find_last_of(g_fileSeparator); - if (endPath != string::npos) + if (endPath != std::string::npos) { - first.erase(endPath + 1, string::npos); + first.erase(endPath + 1, std::string::npos); } else { first = "."; first.push_back(g_fileSeparator); @@ -779,12 +779,12 @@ string ASConsole::findProjectOptionFilePath(const string& fileName_) const } // remove filename from path size_t endPath = parent.find_last_of(g_fileSeparator); - if (endPath != string::npos) + if (endPath != std::string::npos) parent = parent.substr(0, endPath + 1); while (!parent.empty()) { - string filepath = parent + fileName_; + std::string filepath = parent + fileName_; if (fileExists(filepath.c_str())) return filepath; if (fileName_ == ".astylerc") @@ -795,27 +795,27 @@ string ASConsole::findProjectOptionFilePath(const string& fileName_) const } parent = getParentDirectory(parent); } - return string(); + return std::string(); } // for unit testing -vector ASConsole::getExcludeHitsVector() const +std::vector ASConsole::getExcludeHitsVector() const { return excludeHitsVector; } // for unit testing -vector ASConsole::getExcludeVector() const +std::vector ASConsole::getExcludeVector() const { return excludeVector; } // for unit testing -vector ASConsole::getFileName() const +std::vector ASConsole::getFileName() const { return fileName; } // for unit testing -vector ASConsole::getFileNameVector() const +std::vector ASConsole::getFileNameVector() const { return fileNameVector; } // for unit testing -vector ASConsole::getFileOptionsVector() const +std::vector ASConsole::getFileOptionsVector() const { return fileOptionsVector; } // for unit testing @@ -843,7 +843,7 @@ bool ASConsole::getIsFormattedOnly() const { return isFormattedOnly; } // for unit testing -string ASConsole::getLanguageID() const +std::string ASConsole::getLanguageID() const { return localizer.getLanguageID(); } // for unit testing @@ -867,15 +867,15 @@ bool ASConsole::getNoBackup() const { return noBackup; } // for unit testing -string ASConsole::getOptionFileName() const +std::string ASConsole::getOptionFileName() const { return optionFileName; } // for unit testing -vector ASConsole::getOptionsVector() const +std::vector ASConsole::getOptionsVector() const { return optionsVector; } // for unit testing -string ASConsole::getOrigSuffix() const +std::string ASConsole::getOrigSuffix() const { return origSuffix; } // for unit testing @@ -883,26 +883,26 @@ bool ASConsole::getPreserveDate() const { return preserveDate; } // for unit testing -string ASConsole::getProjectOptionFileName() const +std::string ASConsole::getProjectOptionFileName() const { assert(projectOptionFileName.length() > 0); // remove the directory path size_t start = projectOptionFileName.find_last_of(g_fileSeparator); - if (start == string::npos) + if (start == std::string::npos) start = 0; return projectOptionFileName.substr(start + 1); } // for unit testing -vector ASConsole::getProjectOptionsVector() const +std::vector ASConsole::getProjectOptionsVector() const { return projectOptionsVector; } // for unit testing -string ASConsole::getStdPathIn() const +std::string ASConsole::getStdPathIn() const { return stdPathIn; } // for unit testing -string ASConsole::getStdPathOut() const +std::string ASConsole::getStdPathOut() const { return stdPathOut; } // for unit testing @@ -910,37 +910,37 @@ void ASConsole::setBypassBrowserOpen(bool state) { bypassBrowserOpen = state; } // for unit testing -ostream* ASConsole::getErrorStream() const +std::ostream* ASConsole::getErrorStream() const { return errorStream; } -void ASConsole::setErrorStream(ostream* errStreamPtr) +void ASConsole::setErrorStream(std::ostream* errStreamPtr) { errorStream = errStreamPtr; } // build a vector of argv options // the program path argv[0] is excluded -vector ASConsole::getArgvOptions(int argc, char** argv) +std::vector ASConsole::getArgvOptions(int argc, char** argv) { if (argc > 0) astyleExePath = getFullPathName(argv[0]); - vector argvOptions; + std::vector argvOptions; for (int i = 1; i < argc; i++) { - argvOptions.emplace_back(string(argv[i])); + argvOptions.emplace_back(std::string(argv[i])); } return argvOptions; } -string ASConsole::getParam(const string& arg, const char* op) +std::string ASConsole::getParam(const std::string& arg, const char* op) { return arg.substr(strlen(op)); } -void ASConsole::getTargetFilenames(string& targetFilename_, - vector& targetFilenameVector) const +void ASConsole::getTargetFilenames(std::string& targetFilename_, + std::vector& targetFilenameVector) const { size_t beg = 0; size_t sep = 0; @@ -948,9 +948,9 @@ void ASConsole::getTargetFilenames(string& targetFilename_, { // find next target sep = targetFilename_.find_first_of(",;", beg); - if (sep == string::npos) + if (sep == std::string::npos) sep = targetFilename_.length(); - string fileExtension = targetFilename_.substr(beg, sep - beg); + std::string fileExtension = targetFilename_.substr(beg, sep - beg); beg = sep + 1; // remove whitespace while (fileExtension.length() > 0 @@ -993,13 +993,13 @@ void ASConsole::initializeOutputEOL(LineEndFormat lineEndFormat) } // read a file into the stringstream 'in' -FileEncoding ASConsole::readFile(const string& fileName_, stringstream& in) const +FileEncoding ASConsole::readFile(const std::string& fileName_, std::stringstream& in) const { const int blockSize = 65536; // 64 KB - ifstream fin(fileName_.c_str(), ios::binary); + std::ifstream fin(fileName_.c_str(), std::ios::binary); if (!fin) error("Cannot open file", fileName_.c_str()); - char* data = new (nothrow) char[blockSize]; + char* data = new (std::nothrow) char[blockSize]; if (data == nullptr) error("Cannot allocate memory to open file", fileName_.c_str()); fin.read(data, blockSize); @@ -1018,16 +1018,16 @@ FileEncoding ASConsole::readFile(const string& fileName_, stringstream& in) cons { // convert utf-16 to utf-8 size_t utf8Size = encode.utf8LengthFromUtf16(data, dataSize, isBigEndian); - char* utf8Out = new (nothrow) char[utf8Size]; + char* utf8Out = new (std::nothrow) char[utf8Size]; if (utf8Out == nullptr) error("Cannot allocate memory for utf-8 conversion", fileName_.c_str()); size_t utf8Len = encode.utf16ToUtf8(data, dataSize, isBigEndian, firstBlock, utf8Out); assert(utf8Len <= utf8Size); - in << string(utf8Out, utf8Len); + in << std::string(utf8Out, utf8Len); delete[] utf8Out; } else - in << string(data, dataSize); + in << std::string(data, dataSize); fin.read(data, blockSize); if (fin.bad()) error("Cannot read file", fileName_.c_str()); @@ -1063,26 +1063,26 @@ void ASConsole::setIsVerbose(bool state) void ASConsole::setNoBackup(bool state) { noBackup = state; } -void ASConsole::setOptionFileName(const string& name) +void ASConsole::setOptionFileName(const std::string& name) { optionFileName = name; } -void ASConsole::setOrigSuffix(const string& suffix) +void ASConsole::setOrigSuffix(const std::string& suffix) { origSuffix = suffix; } void ASConsole::setPreserveDate(bool state) { preserveDate = state; } -void ASConsole::setProjectOptionFileName(const string& optfilepath) +void ASConsole::setProjectOptionFileName(const std::string& optfilepath) { projectOptionFileName = optfilepath; } -void ASConsole::setStdPathIn(const string& path) +void ASConsole::setStdPathIn(const std::string& path) { stdPathIn = path; } -void ASConsole::setStdPathOut(const string& path) +void ASConsole::setStdPathOut(const std::string& path) { stdPathOut = path; } // set outputEOL variable -void ASConsole::setOutputEOL(LineEndFormat lineEndFormat, const string& currentEOL) +void ASConsole::setOutputEOL(LineEndFormat lineEndFormat, const std::string& currentEOL) { if (lineEndFormat == LINEEND_DEFAULT) { @@ -1122,7 +1122,7 @@ void ASConsole::displayLastError() nullptr ); // Display the string. - (*errorStream) << "Error (" << lastError << ") " << msgBuf << endl; + (*errorStream) << "Error (" << lastError << ") " << msgBuf << std::endl; // Free the buffer. LocalFree(msgBuf); } @@ -1134,13 +1134,13 @@ void ASConsole::displayLastError() * * @return The path of the current directory */ -string ASConsole::getCurrentDirectory(const string& fileName_) const +std::string ASConsole::getCurrentDirectory(const std::string& fileName_) const { char currdir[MAX_PATH]; currdir[0] = '\0'; if (!GetCurrentDirectory(sizeof(currdir), currdir)) error("Cannot find file", fileName_.c_str()); - return string(currdir); + return std::string(currdir); } /** @@ -1150,14 +1150,14 @@ string ASConsole::getCurrentDirectory(const string& fileName_) const * @param directory The path of the directory to be processed. * @param wildcards A vector of wildcards to be processed (e.g. *.cpp). */ -void ASConsole::getFileNames(const string& directory, const vector& wildcards) +void ASConsole::getFileNames(const std::string& directory, const std::vector& wildcards) { - vector subDirectory; // sub directories of directory + std::vector subDirectory; // sub directories of directory WIN32_FIND_DATA findFileData; // for FindFirstFile and FindNextFile // Find the first file in the directory // Find will get at least "." and "..". - string firstFile = directory + "\\*"; + std::string firstFile = directory + "\\*"; HANDLE hFind = FindFirstFile(firstFile.c_str(), &findFileData); if (hFind == INVALID_HANDLE_VALUE) @@ -1184,7 +1184,7 @@ void ASConsole::getFileNames(const string& directory, const vector& wild if (!isRecursive) continue; // if a sub directory and recursive, save sub directory - string subDirectoryPath = directory + g_fileSeparator + findFileData.cFileName; + std::string subDirectoryPath = directory + g_fileSeparator + findFileData.cFileName; if (isPathExclued(subDirectoryPath)) printMsg(_("Exclude %s\n"), subDirectoryPath.substr(mainDirectoryLength)); else @@ -1192,11 +1192,11 @@ void ASConsole::getFileNames(const string& directory, const vector& wild continue; } - string filePathName = directory + g_fileSeparator + findFileData.cFileName; + std::string filePathName = directory + g_fileSeparator + findFileData.cFileName; // check exclude before wildcmp to avoid "unmatched exclude" error bool isExcluded = isPathExclued(filePathName); // save file name if wildcard match - for (const string& wildcard : wildcards) + for (const std::string& wildcard : wildcards) { if (wildcmp(wildcard.c_str(), findFileData.cFileName)) { @@ -1218,13 +1218,13 @@ void ASConsole::getFileNames(const string& directory, const vector& wild // recurse into sub directories // if not doing recursive subDirectory is empty - for (const string& subDirectoryName : subDirectory) + for (const std::string& subDirectoryName : subDirectory) getFileNames(subDirectoryName, wildcards); } // WINDOWS function to get the full path name from the relative path name // Return the full path name or an empty string if failed. -string ASConsole::getFullPathName(const string& relativePath) const +std::string ASConsole::getFullPathName(const std::string& relativePath) const { char fullPath[MAX_PATH]; GetFullPathName(relativePath.c_str(), MAX_PATH, fullPath, nullptr); @@ -1239,7 +1239,7 @@ string ASConsole::getFullPathName(const string& relativePath) const * @param lcid The LCID of the locale to be used for testing. * @return The formatted number. */ -string ASConsole::getNumberFormat(int num, size_t lcid) const +std::string ASConsole::getNumberFormat(int num, size_t lcid) const { #if defined(_MSC_VER) || defined(__MINGW32__) || defined(__BORLANDC__) || defined(__GNUC__) // Compilers that don't support C++ locales should still support this assert. @@ -1249,9 +1249,9 @@ string ASConsole::getNumberFormat(int num, size_t lcid) const assert(locale().name() == "C"); #endif // convert num to a string - stringstream alphaNum; + std::stringstream alphaNum; alphaNum << num; - string number = alphaNum.str(); + std::string number = alphaNum.str(); if (useAscii) return number; @@ -1259,21 +1259,21 @@ string ASConsole::getNumberFormat(int num, size_t lcid) const if (lcid == 0) lcid = LOCALE_USER_DEFAULT; int outSize = ::GetNumberFormat(lcid, 0, number.c_str(), nullptr, nullptr, 0); - char* outBuf = new (nothrow) char[outSize]; + char* outBuf = new (std::nothrow) char[outSize]; if (outBuf == nullptr) return number; ::GetNumberFormat(lcid, 0, number.c_str(), nullptr, outBuf, outSize); - string formattedNum(outBuf); + std::string formattedNum(outBuf); delete[] outBuf; // remove the decimal int decSize = ::GetLocaleInfo(lcid, LOCALE_SDECIMAL, nullptr, 0); - char* decBuf = new (nothrow) char[decSize]; + char* decBuf = new (std::nothrow) char[decSize]; if (decBuf == nullptr) return number; ::GetLocaleInfo(lcid, LOCALE_SDECIMAL, decBuf, decSize); size_t i = formattedNum.rfind(decBuf); delete[] decBuf; - if (i != string::npos) + if (i != std::string::npos) formattedNum.erase(i); if (!formattedNum.length()) formattedNum = "0"; @@ -1287,7 +1287,7 @@ string ASConsole::getNumberFormat(int num, size_t lcid) const * @returns true if absPath is HOME or is an invalid absolute * path, false otherwise. */ -bool ASConsole::isHomeOrInvalidAbsPath(const string& absPath) const +bool ASConsole::isHomeOrInvalidAbsPath(const std::string& absPath) const { const char* const env = getenv("USERPROFILE"); if (env == nullptr) @@ -1304,7 +1304,7 @@ void ASConsole::launchDefaultBrowser(const char* filePathIn /*nullptr*/) const struct stat statbuf; const char* envPaths[] = { "PROGRAMFILES(X86)", "PROGRAMFILES" }; size_t pathsLen = sizeof(envPaths) / sizeof(envPaths[0]); - string htmlDefaultPath; + std::string htmlDefaultPath; for (size_t i = 0; i < pathsLen; i++) { const char* const envPath = getenv(envPaths[i]); @@ -1321,7 +1321,7 @@ void ASConsole::launchDefaultBrowser(const char* filePathIn /*nullptr*/) const htmlDefaultPath.append("\\"); // build file path - string htmlFilePath; + std::string htmlFilePath; if (filePathIn == nullptr) htmlFilePath = htmlDefaultPath + "astyle.html"; else @@ -1364,12 +1364,12 @@ void ASConsole::launchDefaultBrowser(const char* filePathIn /*nullptr*/) const * @param fileName_ The filename is used only for the error message. * @return The path of the current directory */ -string ASConsole::getCurrentDirectory(const string& fileName_) const +std::string ASConsole::getCurrentDirectory(const std::string& fileName_) const { const char* const currdir = getenv("PWD"); if (currdir == nullptr) error("Cannot find file", fileName_.c_str()); - return string(currdir); + return std::string(currdir); } /** @@ -1379,11 +1379,11 @@ string ASConsole::getCurrentDirectory(const string& fileName_) const * @param directory The path of the directory to be processed. * @param wildcards A vector of wildcards to be processed (e.g. *.cpp). */ -void ASConsole::getFileNames(const string& directory, const vector& wildcards) +void ASConsole::getFileNames(const std::string& directory, const std::vector& wildcards) { struct dirent* entry; // entry from readdir() struct stat statbuf; // entry from stat() - vector subDirectory; // sub directories of this directory + std::vector subDirectory; // sub directories of this directory // errno is defined in and is set for errors in opendir, readdir, or stat errno = 0; @@ -1399,7 +1399,7 @@ void ASConsole::getFileNames(const string& directory, const vector& wild while ((entry = readdir(dp)) != nullptr) { // get file status - string entryFilepath = directory + g_fileSeparator + entry->d_name; + std::string entryFilepath = directory + g_fileSeparator + entry->d_name; if (stat(entryFilepath.c_str(), &statbuf) != 0) { if (errno == EOVERFLOW) // file over 2 GB is OK @@ -1430,7 +1430,7 @@ void ASConsole::getFileNames(const string& directory, const vector& wild // check exclude before wildcmp to avoid "unmatched exclude" error bool isExcluded = isPathExclued(entryFilepath); // save file name if wildcard match - for (const string& wildcard : wildcards) + for (const std::string& wildcard : wildcards) { if (wildcmp(wildcard.c_str(), entry->d_name) != 0) { @@ -1465,25 +1465,25 @@ void ASConsole::getFileNames(const string& directory, const vector& wild } // LINUX function to get the full path name from the relative path name -// Return the full path name or an empty string if failed. -string ASConsole::getFullPathName(const string& relativePath) const +// Return the full path name or an empty std::string if failed. +std::string ASConsole::getFullPathName(const std::string& relativePath) const { char* fullPath = realpath(relativePath.c_str(), nullptr); if (fullPath == nullptr) - return string(); - const string p(fullPath); + return std::string(); + const std::string p(fullPath); free(fullPath); return p; } // LINUX function to get the documentation file path prefix // from the executable file path. -// Return the documentation path prefix or an empty string if failed. -string ASConsole::getHtmlInstallPrefix() const +// Return the documentation path prefix or an empty std::string if failed. +std::string ASConsole::getHtmlInstallPrefix() const { - string astyleHtmlPrefix = astyleExePath; + std::string astyleHtmlPrefix = astyleExePath; size_t end = astyleHtmlPrefix.find("/bin/"); - if (end == string::npos) + if (end == std::string::npos) return ""; astyleHtmlPrefix = astyleHtmlPrefix.substr(0, end); return astyleHtmlPrefix; @@ -1497,7 +1497,7 @@ string ASConsole::getHtmlInstallPrefix() const * size_t is for compatibility with the Windows function. * @return The formatted number. */ -string ASConsole::getNumberFormat(int num, size_t /*lcid*/) const +std::string ASConsole::getNumberFormat(int num, size_t /*lcid*/) const { #if defined(_MSC_VER) || defined(__MINGW32__) || defined(__BORLANDC__) || defined(__GNUC__) // Compilers that don't support C++ locales should still support this assert. @@ -1524,14 +1524,14 @@ string ASConsole::getNumberFormat(int num, size_t /*lcid*/) const * @param separator The thousands group separator from the locale. * @return The formatted number. */ -string ASConsole::getNumberFormat(int num, const char* groupingArg, const char* separator) const +std::string ASConsole::getNumberFormat(int num, const char* groupingArg, const char* separator) const { // convert num to a string - stringstream alphaNum; + std::stringstream alphaNum; alphaNum << num; - string number = alphaNum.str(); + std::string number = alphaNum.str(); // format the number from right to left - string formattedNum; + std::string formattedNum; size_t ig = 0; // grouping index int grouping = groupingArg[ig]; int i = number.length(); @@ -1541,7 +1541,7 @@ string ASConsole::getNumberFormat(int num, const char* groupingArg, const char* while (i > 0) { // extract a group of numbers - string group; + std::string group; if (i < grouping) group = number; else @@ -1569,7 +1569,7 @@ string ASConsole::getNumberFormat(int num, const char* groupingArg, const char* * @returns true if absPath is HOME or is an invalid absolute * path, false otherwise. */ -bool ASConsole::isHomeOrInvalidAbsPath(const string& absPath) const +bool ASConsole::isHomeOrInvalidAbsPath(const std::string& absPath) const { const char* const env = getenv("HOME"); @@ -1588,19 +1588,19 @@ bool ASConsole::isHomeOrInvalidAbsPath(const string& absPath) const void ASConsole::launchDefaultBrowser(const char* filePathIn /*nullptr*/) const { #ifdef __APPLE__ - string htmlDefaultPrefix = "/usr/local"; + std::string htmlDefaultPrefix = "/usr/local"; #else - string htmlDefaultPrefix = "/usr"; + std::string htmlDefaultPrefix = "/usr"; #endif - string htmlDefaultPath = htmlDefaultPrefix + "/share/doc/astyle/html/"; - string htmlDefaultFile = "astyle.html"; - string htmlFilePath; + std::string htmlDefaultPath = htmlDefaultPrefix + "/share/doc/astyle/html/"; + std::string htmlDefaultFile = "astyle.html"; + std::string htmlFilePath; struct stat statbuf; // build html path if (filePathIn == nullptr) { - string htmlPrefix = getHtmlInstallPrefix(); + std::string htmlPrefix = getHtmlInstallPrefix(); if (htmlPrefix.empty()) htmlFilePath = htmlDefaultPrefix + htmlDefaultPath + htmlDefaultFile; else @@ -1634,14 +1634,14 @@ void ASConsole::launchDefaultBrowser(const char* filePathIn /*nullptr*/) const #else const char* fileOpen = "xdg-open"; #endif - string searchPath; + std::string searchPath; char* searchDir = strtok(paths, ":"); while (searchDir != nullptr) { searchPath = searchDir; if (searchPath.length() > 0 && searchPath[searchPath.length() - 1] != g_fileSeparator) - searchPath.append(string(1, g_fileSeparator)); + searchPath.append(std::string(1, g_fileSeparator)); searchPath.append(fileOpen); if (stat(searchPath.c_str(), &statbuf) == 0 && (statbuf.st_mode & S_IFREG)) break; @@ -1671,11 +1671,11 @@ void ASConsole::launchDefaultBrowser(const char* filePathIn /*nullptr*/) const * @return The parent directory of absPath, or an empty string if * one cannot be found. */ -string ASConsole::getParentDirectory(const string& absPath) const +std::string ASConsole::getParentDirectory(const std::string& absPath) const { if (isHomeOrInvalidAbsPath(absPath)) { - return string(); + return std::string(); } size_t offset = absPath.size() - 1; if (absPath[absPath.size() - 1] == g_fileSeparator) @@ -1683,25 +1683,25 @@ string ASConsole::getParentDirectory(const string& absPath) const offset -= 1; } size_t idx = absPath.rfind(g_fileSeparator, offset); - if (idx == string::npos) + if (idx == std::string::npos) { - return string(); + return std::string(); } - string str = absPath.substr(0, idx + 1); + std::string str = absPath.substr(0, idx + 1); return str; } // get individual file names from the command-line file path -void ASConsole::getFilePaths(const string& filePath) +void ASConsole::getFilePaths(const std::string& filePath) { fileName.clear(); - targetDirectory = string(); - targetFilename = string(); - vector targetFilenameVector; + targetDirectory = std::string(); + targetFilename = std::string(); + std::vector targetFilenameVector; // separate directory and file name size_t separator = filePath.find_last_of(g_fileSeparator); - if (separator == string::npos) + if (separator == std::string::npos) { // if no directory is present, use the currently active directory targetDirectory = getCurrentDirectory(filePath); @@ -1723,7 +1723,7 @@ void ASConsole::getFilePaths(const string& filePath) // check filename for wildcards hasWildcard = false; - if (targetFilename.find_first_of("*?") != string::npos) + if (targetFilename.find_first_of("*?") != std::string::npos) hasWildcard = true; // If the filename is not quoted on Linux, bash will replace the @@ -1738,7 +1738,7 @@ void ASConsole::getFilePaths(const string& filePath) } bool hasMultipleTargets = false; - if (targetFilename.find_first_of(",;") != string::npos) + if (targetFilename.find_first_of(",;") != std::string::npos) hasMultipleTargets = true; // display directory name for wildcard processing @@ -1753,7 +1753,7 @@ void ASConsole::getFilePaths(const string& filePath) for (size_t ix = 0; ix < excludeHitsVectorSize; ix++) excludeHitsVector[ix] = false; - // create a vector of paths and file names to process + // create a std::vector of paths and file names to process if (hasWildcard || isRecursive || hasMultipleTargets) { getTargetFilenames(targetFilename, targetFilenameVector); @@ -1762,7 +1762,7 @@ void ASConsole::getFilePaths(const string& filePath) else { // verify a single file is not a directory (needed on Linux) - string entryFilepath = targetDirectory + g_fileSeparator + targetFilename; + std::string entryFilepath = targetDirectory + g_fileSeparator + targetFilename; struct stat statbuf; if (stat(entryFilepath.c_str(), &statbuf) == 0 && (statbuf.st_mode & S_IFREG)) fileName.emplace_back(entryFilepath); @@ -1822,17 +1822,17 @@ bool ASConsole::fileNameVectorIsEmpty() const return fileNameVector.empty(); } -bool ASConsole::isOption(const string& arg, const char* op) +bool ASConsole::isOption(const std::string& arg, const char* op) { return arg == op; } -bool ASConsole::isOption(const string& arg, const char* a, const char* b) +bool ASConsole::isOption(const std::string& arg, const char* a, const char* b) { return (isOption(arg, a) || isOption(arg, b)); } -bool ASConsole::isParamOption(const string& arg, const char* option) +bool ASConsole::isParamOption(const std::string& arg, const char* option) { bool retVal = arg.compare(0, strlen(option), option) == 0; // if comparing for short option, 2nd char of arg must be numeric @@ -1842,18 +1842,18 @@ bool ASConsole::isParamOption(const string& arg, const char* option) return retVal; } -// compare a path to the exclude vector +// compare a path to the exclude std::vector // used for both directories and filenames // updates the g_excludeHitsVector // return true if a match -bool ASConsole::isPathExclued(const string& subPath) +bool ASConsole::isPathExclued(const std::string& subPath) { bool retVal = false; - // read the exclude vector checking for a match + // read the exclude std::vector checking for a match for (size_t i = 0; i < excludeVector.size(); i++) { - string exclude = excludeVector[i]; + std::string exclude = excludeVector[i]; if (subPath.length() < exclude.length()) continue; @@ -1867,7 +1867,7 @@ bool ASConsole::isPathExclued(const string& subPath) continue; } - string compare = subPath.substr(compareStart); + std::string compare = subPath.substr(compareStart); if (!g_isCaseSensitive) { // make it case insensitive for Windows @@ -1889,505 +1889,505 @@ bool ASConsole::isPathExclued(const string& subPath) void ASConsole::printHelp() const { - cout << endl; - cout << " Artistic Style " << g_version << endl; - cout << " Maintained by: Andre Simon, Jim Pattee\n"; - cout << " Original Author: Tal Davidson\n"; - cout << endl; - cout << "Usage:\n"; - cout << "------\n"; - cout << " astyle [OPTIONS] File1 File2 File3 [...]\n"; - cout << endl; - cout << " astyle [OPTIONS] < Original > Beautified\n"; - cout << endl; - cout << " When indenting a specific file, the resulting indented file RETAINS\n"; - cout << " the original file-name. The original pre-indented file is renamed,\n"; - cout << " with a suffix of \'.orig\' added to the original filename.\n"; - cout << endl; - cout << " Wildcards (* and ?) may be used in the filename.\n"; - cout << " A \'recursive\' option can process directories recursively.\n"; - cout << " Multiple file extensions may be separated by a comma.\n"; - cout << endl; - cout << " By default, astyle is set up to indent with four spaces per indent,\n"; - cout << " a maximal indentation of 40 spaces inside continuous statements,\n"; - cout << " a minimum indentation of eight spaces inside conditional statements,\n"; - cout << " and NO formatting options.\n"; - cout << endl; - cout << "Options:\n"; - cout << "--------\n"; - cout << " This program follows the usual GNU command line syntax.\n"; - cout << " Long options (starting with '--') must be written one at a time.\n"; - cout << " Short options (starting with '-') may be appended together.\n"; - cout << " Thus, -bps4 is the same as -b -p -s4.\n"; - cout << endl; - cout << "Option Files:\n"; - cout << "-------------\n"; - cout << " Artistic Style looks for a default option file and/or a project\n"; - cout << " option file in the following order:\n"; - cout << " 1. The command line options have precedence.\n"; - cout << " 2. The project option file has precedence over the default file\n"; - cout << " o the file name indicated by the --project= command line option.\n"; - cout << " o the file named .astylerc or _ astylerc.\n"; - cout << " o the file name identified by ARTISTIC_STYLE_PROJECT_OPTIONS.\n"; - cout << " o the file is disabled by --project=none on the command line.\n"; - cout << " 3. The default option file that can be used for all projects.\n"; - cout << " o the file path indicated by the --options= command line option.\n"; - cout << " o the file path indicated by ARTISTIC_STYLE_OPTIONS.\n"; - cout << " o the file named .astylerc in the HOME directory (for Linux).\n"; - cout << " o the file name astylerc in the APPDATA directory (for Windows).\n"; - cout << " o the file is disabled by --project=none on the command line.\n"; - cout << " Long options within the option files may be written without '--'.\n"; - cout << " Line-end comments begin with a '#'.\n"; - cout << endl; - cout << "Disable Formatting:\n"; - cout << "-------------------\n"; - cout << " Disable Block\n"; - cout << " Blocks of code can be disabled with the comment tags *INDENT-OFF*\n"; - cout << " and *INDENT-ON*. It must be contained in a one-line comment.\n"; - cout << endl; - cout << " Disable Line\n"; - cout << " Padding of operators can be disabled on a single line using the\n"; - cout << " comment tag *NOPAD*. It must be contained in a line-end comment.\n"; - cout << endl; - cout << "Brace Style Options:\n"; - cout << "--------------------\n"; - cout << " default brace style\n"; - cout << " If no brace style is requested, the opening braces will not be\n"; - cout << " changed and closing braces will be broken from the preceding line.\n"; - cout << endl; - cout << " --style=allman OR --style=bsd OR --style=break OR -A1\n"; - cout << " Allman style formatting/indenting.\n"; - cout << " Broken braces.\n"; - cout << endl; - cout << " --style=java OR --style=attach OR -A2\n"; - cout << " Java style formatting/indenting.\n"; - cout << " Attached braces.\n"; - cout << endl; - cout << " --style=kr OR --style=k&r OR --style=k/r OR -A3\n"; - cout << " Kernighan & Ritchie style formatting/indenting.\n"; - cout << " Linux braces.\n"; - cout << endl; - cout << " --style=stroustrup OR -A4\n"; - cout << " Stroustrup style formatting/indenting.\n"; - cout << " Linux braces, with broken closing headers.\n"; - cout << endl; - cout << " --style=whitesmith OR -A5\n"; - cout << " Whitesmith style formatting/indenting.\n"; - cout << " Broken, indented braces.\n"; - cout << " Indented class blocks and switch blocks.\n"; - cout << endl; - cout << " --style=vtk OR -A15\n"; - cout << " VTK style formatting/indenting.\n"; - cout << " Broken, indented braces except for the opening braces.\n"; - cout << endl; - cout << " --style=ratliff OR --style=banner OR -A6\n"; - cout << " Ratliff style formatting/indenting.\n"; - cout << " Attached, indented braces.\n"; - cout << endl; - cout << " --style=gnu OR -A7\n"; - cout << " GNU style formatting/indenting.\n"; - cout << " Broken braces, indented blocks.\n"; - cout << endl; - cout << " --style=linux OR --style=knf OR -A8\n"; - cout << " Linux style formatting/indenting.\n"; - cout << " Linux braces, minimum conditional indent is one-half indent.\n"; - cout << endl; - cout << " --style=horstmann OR --style=run-in OR -A9\n"; - cout << " Horstmann style formatting/indenting.\n"; - cout << " Run-in braces, indented switches.\n"; - cout << endl; - cout << " --style=1tbs OR --style=otbs OR -A10\n"; - cout << " One True Brace Style formatting/indenting.\n"; - cout << " Linux braces, add braces to all conditionals.\n"; - cout << endl; - cout << " --style=google OR -A14\n"; - cout << " Google style formatting/indenting.\n"; - cout << " Attached braces, indented class modifiers.\n"; - cout << endl; - cout << " --style=mozilla OR -A16\n"; - cout << " Mozilla style formatting/indenting.\n"; - cout << " Linux braces, with broken braces for structs and enums,\n"; - cout << " and attached braces for namespaces.\n"; - cout << endl; - cout << " --style=webkit OR -A17\n"; - cout << " WebKit style formatting/indenting.\n"; - cout << " Linux braces, with attached closing headers.\n"; - cout << endl; - cout << " --style=pico OR -A11\n"; - cout << " Pico style formatting/indenting.\n"; - cout << " Run-in opening braces and attached closing braces.\n"; - cout << " Uses keep one line blocks and keep one line statements.\n"; - cout << endl; - cout << " --style=lisp OR -A12\n"; - cout << " Lisp style formatting/indenting.\n"; - cout << " Attached opening braces and attached closing braces.\n"; - cout << " Uses keep one line statements.\n"; - cout << endl; - cout << "Tab Options:\n"; - cout << "------------\n"; - cout << " default indent option\n"; - cout << " If no indentation option is set, the default\n"; - cout << " option of 4 spaces per indent will be used.\n"; - cout << endl; - cout << " --indent=spaces=# OR -s#\n"; - cout << " Indent using # spaces per indent. Not specifying #\n"; - cout << " will result in a default of 4 spaces per indent.\n"; - cout << endl; - cout << " --indent=tab OR --indent=tab=# OR -t OR -t#\n"; - cout << " Indent using tab characters, assuming that each\n"; - cout << " indent is # spaces long. Not specifying # will result\n"; - cout << " in a default assumption of 4 spaces per indent.\n"; - cout << endl; - cout << " --indent=force-tab=# OR -T#\n"; - cout << " Indent using tab characters, assuming that each\n"; - cout << " indent is # spaces long. Force tabs to be used in areas\n"; - cout << " AStyle would prefer to use spaces.\n"; - cout << endl; - cout << " --indent=force-tab-x=# OR -xT#\n"; - cout << " Allows the tab length to be set to a length that is different\n"; - cout << " from the indent length. This may cause the indentation to be\n"; - cout << " a mix of both spaces and tabs. This option sets the tab length.\n"; - cout << endl; - cout << "Brace Modify Options:\n"; - cout << "---------------------\n"; - cout << " --attach-namespaces OR -xn\n"; - cout << " Attach braces to a namespace statement.\n"; - cout << endl; - cout << " --attach-classes OR -xc\n"; - cout << " Attach braces to a class statement.\n"; - cout << endl; - cout << " --attach-inlines OR -xl\n"; - cout << " Attach braces to class inline function definitions.\n"; - cout << endl; - cout << " --attach-extern-c OR -xk\n"; - cout << " Attach braces to an extern \"C\" statement.\n"; - cout << endl; - cout << " --attach-closing-while OR -xV\n"; - cout << " Attach closing while of do-while to the closing brace.\n"; - cout << endl; - cout << "Indentation Options:\n"; - cout << "--------------------\n"; - cout << " --indent-classes OR -C\n"; - cout << " Indent 'class' blocks so that the entire block is indented.\n"; - cout << endl; - cout << " --indent-modifiers OR -xG\n"; - cout << " Indent 'class' access modifiers, 'public:', 'protected:' or\n"; - cout << " 'private:', one half indent. The rest of the class is not\n"; - cout << " indented. \n"; - cout << endl; - cout << " --indent-switches OR -S\n"; - cout << " Indent 'switch' blocks, so that the inner 'case XXX:'\n"; - cout << " headers are indented in relation to the switch block.\n"; - cout << endl; - cout << " --indent-cases OR -K\n"; - cout << " Indent case blocks from the 'case XXX:' headers.\n"; - cout << " Case statements not enclosed in blocks are NOT indented.\n"; - cout << endl; - cout << " --indent-namespaces OR -N\n"; - cout << " Indent the contents of namespace blocks.\n"; - cout << endl; - cout << " --indent-after-parens OR -xU\n"; - cout << " Indent, instead of align, continuation lines following lines\n"; - cout << " that contain an opening paren '(' or an assignment '='. \n"; - cout << endl; - cout << " --indent-continuation=# OR -xt#\n"; - cout << " Indent continuation lines an additional # indents.\n"; - cout << " The valid values are 0 thru 4 indents.\n"; - cout << " The default value is 1 indent.\n"; - cout << endl; - cout << " --indent-labels OR -L\n"; - cout << " Indent labels so that they appear one indent less than\n"; - cout << " the current indentation level, rather than being\n"; - cout << " flushed completely to the left (which is the default).\n"; - cout << endl; - cout << " --indent-preproc-block OR -xW\n"; - cout << " Indent preprocessor blocks at brace level 0.\n"; - cout << " Without this option the preprocessor block is not indented.\n"; - cout << endl; - cout << " --indent-preproc-cond OR -xw\n"; - cout << " Indent preprocessor conditional statements #if/#else/#endif\n"; - cout << " to the same level as the source code.\n"; - cout << endl; - cout << " --indent-preproc-define OR -w\n"; - cout << " Indent multi-line preprocessor #define statements.\n"; - cout << endl; - cout << " --indent-col1-comments OR -Y\n"; - cout << " Indent line comments that start in column one.\n"; - cout << endl; - cout << " --min-conditional-indent=# OR -m#\n"; - cout << " Indent a minimal # spaces in a continuous conditional\n"; - cout << " belonging to a conditional header.\n"; - cout << " The valid values are:\n"; - cout << " 0 - no minimal indent.\n"; - cout << " 1 - indent at least one additional indent.\n"; - cout << " 2 - indent at least two additional indents.\n"; - cout << " 3 - indent at least one-half an additional indent.\n"; - cout << " The default value is 2, two additional indents.\n"; - cout << endl; - cout << " --max-continuation-indent=# OR -M#\n"; - cout << " Indent a maximal # spaces in a continuation line,\n"; - cout << " relative to the previous line.\n"; - cout << " The minimum and default value is 40.\n"; - cout << endl; - cout << "Padding Options:\n"; - cout << "----------------\n"; - cout << " --break-blocks OR -f\n"; - cout << " Insert empty lines around unrelated blocks, labels, classes, ...\n"; - cout << endl; - cout << " --break-blocks=all OR -F\n"; - cout << " Like --break-blocks, except also insert empty lines \n"; - cout << " around closing headers (e.g. 'else', 'catch', ...).\n"; - cout << endl; - cout << " --pad-oper OR -p\n"; - cout << " Insert space padding around operators.\n"; - cout << endl; - cout << " --pad-comma OR -xg\n"; - cout << " Insert space padding after commas.\n"; - cout << endl; - cout << " --pad-paren OR -P\n"; - cout << " Insert space padding around parenthesis on both the outside\n"; - cout << " and the inside.\n"; - cout << endl; - cout << " --pad-paren-out OR -d\n"; - cout << " Insert space padding around parenthesis on the outside only.\n"; - cout << endl; - cout << " --pad-first-paren-out OR -xd\n"; - cout << " Insert space padding around first parenthesis in a series on\n"; - cout << " the outside only.\n"; - cout << endl; - cout << " --pad-paren-in OR -D\n"; - cout << " Insert space padding around parenthesis on the inside only.\n"; - cout << endl; - cout << " --pad-header OR -H\n"; - cout << " Insert space padding after paren headers (e.g. 'if', 'for'...).\n"; - cout << endl; - cout << " --unpad-paren OR -U\n"; - cout << " Remove unnecessary space padding around parenthesis. This\n"; - cout << " can be used in combination with the 'pad' options above.\n"; - cout << endl; - cout << " --delete-empty-lines OR -xe\n"; - cout << " Delete empty lines within a function or method.\n"; - cout << " It will NOT delete lines added by the break-blocks options.\n"; - cout << endl; - cout << " --fill-empty-lines OR -E\n"; - cout << " Fill empty lines with the white space of their\n"; - cout << " previous lines.\n"; - cout << endl; - cout << " --align-pointer=type OR -k1\n"; - cout << " --align-pointer=middle OR -k2\n"; - cout << " --align-pointer=name OR -k3\n"; - cout << " Attach a pointer or reference operator (*, &, or ^) to either\n"; - cout << " the operator type (left), middle, or operator name (right).\n"; - cout << " To align the reference separately use --align-reference.\n"; - cout << endl; - cout << " --align-reference=none OR -W0\n"; - cout << " --align-reference=type OR -W1\n"; - cout << " --align-reference=middle OR -W2\n"; - cout << " --align-reference=name OR -W3\n"; - cout << " Attach a reference operator (&) to either\n"; - cout << " the operator type (left), middle, or operator name (right).\n"; - cout << " If not set, follow pointer alignment.\n"; - cout << endl; - cout << "Formatting Options:\n"; - cout << "-------------------\n"; - cout << " --break-closing-braces OR -y\n"; - cout << " Break braces before closing headers (e.g. 'else', 'catch', ...).\n"; - cout << " Use with --style=java, --style=kr, --style=stroustrup,\n"; - cout << " --style=linux, or --style=1tbs.\n"; - cout << endl; - cout << " --break-elseifs OR -e\n"; - cout << " Break 'else if()' statements into two different lines.\n"; - cout << endl; - cout << " --break-one-line-headers OR -xb\n"; - cout << " Break one line headers (e.g. 'if', 'while', 'else', ...) from a\n"; - cout << " statement residing on the same line.\n"; - cout << endl; - cout << " --add-braces OR -j\n"; - cout << " Add braces to unbraced one line conditional statements.\n"; - cout << endl; - cout << " --add-one-line-braces OR -J\n"; - cout << " Add one line braces to unbraced one line conditional\n"; - cout << " statements.\n"; - cout << endl; - cout << " --remove-braces OR -xj\n"; - cout << " Remove braces from a braced one line conditional statements.\n"; - cout << endl; - cout << " --break-return-type OR -xB\n"; - cout << " --break-return-type-decl OR -xD\n"; - cout << " Break the return type from the function name. Options are\n"; - cout << " for the function definitions and the function declarations.\n"; - cout << endl; - cout << " --attach-return-type OR -xf\n"; - cout << " --attach-return-type-decl OR -xh\n"; - cout << " Attach the return type to the function name. Options are\n"; - cout << " for the function definitions and the function declarations.\n"; - cout << endl; - cout << " --keep-one-line-blocks OR -O\n"; - cout << " Don't break blocks residing completely on one line.\n"; - cout << endl; - cout << " --keep-one-line-statements OR -o\n"; - cout << " Don't break lines containing multiple statements into\n"; - cout << " multiple single-statement lines.\n"; - cout << endl; - cout << " --convert-tabs OR -c\n"; - cout << " Convert tabs to the appropriate number of spaces.\n"; - cout << endl; - cout << " --close-templates OR -xy\n"; - cout << " Close ending angle brackets on template definitions.\n"; - cout << endl; - cout << " --remove-comment-prefix OR -xp\n"; - cout << " Remove the leading '*' prefix on multi-line comments and\n"; - cout << " indent the comment text one indent.\n"; - cout << endl; - cout << " --max-code-length=# OR -xC#\n"; - cout << " --break-after-logical OR -xL\n"; - cout << " max-code-length=# will break the line if it exceeds more than\n"; - cout << " # characters. The valid values are 50 thru 200.\n"; - cout << " If the line contains logical conditionals they will be placed\n"; - cout << " first on the new line. The option break-after-logical will\n"; - cout << " cause the logical conditional to be placed last on the\n"; - cout << " previous line.\n"; - cout << endl; - cout << " --mode=c\n"; - cout << " Indent a C or C++ source file (this is the default).\n"; - cout << endl; - cout << " --mode=java\n"; - cout << " Indent a Java source file.\n"; - cout << endl; - cout << " --mode=cs\n"; - cout << " Indent a C# source file.\n"; - cout << endl; - cout << " --mode=objc\n"; - cout << " Indent an Objective-C source file.\n"; - cout << endl; - cout << " --mode=js\n"; - cout << " Indent a JavaScript source file (experimental).\n"; - cout << endl; - cout << "Objective-C Options:\n"; - cout << "--------------------\n"; - cout << " --pad-method-prefix OR -xQ\n"; - cout << " Insert space padding after the '-' or '+' Objective-C\n"; - cout << " method prefix.\n"; - cout << endl; - cout << " --unpad-method-prefix OR -xR\n"; - cout << " Remove all space padding after the '-' or '+' Objective-C\n"; - cout << " method prefix.\n"; - cout << endl; - cout << " --pad-return-type OR -xq\n"; - cout << " Insert space padding after the Objective-C return type.\n"; - cout << endl; - cout << " --unpad-return-type OR -xr\n"; - cout << " Remove all space padding after the Objective-C return type.\n"; - cout << endl; - cout << " --pad-param-type OR -xS\n"; - cout << " Insert space padding after the Objective-C param type.\n"; - cout << endl; - cout << " --unpad-param-type OR -xs\n"; - cout << " Remove all space padding after the Objective-C param type.\n"; - cout << endl; - cout << " --align-method-colon OR -xM\n"; - cout << " Align the colons in an Objective-C method definition.\n"; - cout << endl; - cout << " --pad-method-colon=none OR -xP\n"; - cout << " --pad-method-colon=all OR -xP1\n"; - cout << " --pad-method-colon=after OR -xP2\n"; - cout << " --pad-method-colon=before OR -xP3\n"; - cout << " Add or remove space padding before or after the colons in an\n"; - cout << " Objective-C method call.\n"; - cout << endl; - cout << "Other Options:\n"; - cout << "--------------\n"; - cout << " --suffix=####\n"; - cout << " Append the suffix #### instead of '.orig' to original filename.\n"; - cout << endl; - cout << " --suffix=none OR -n\n"; - cout << " Do not retain a backup of the original file.\n"; - cout << endl; - cout << " --recursive OR -r OR -R\n"; - cout << " Process subdirectories recursively.\n"; - cout << endl; - cout << " --dry-run\n"; - cout << " Perform a trial run with no changes made to check for formatting.\n"; - cout << endl; - cout << " --exclude=####\n"; - cout << " Specify a file or directory #### to be excluded from processing.\n"; - cout << endl; - cout << " --ignore-exclude-errors OR -i\n"; - cout << " Allow processing to continue if there are errors in the exclude=####\n"; - cout << " options. It will display the unmatched excludes.\n"; - cout << endl; - cout << " --ignore-exclude-errors-x OR -xi\n"; - cout << " Allow processing to continue if there are errors in the exclude=####\n"; - cout << " options. It will NOT display the unmatched excludes.\n"; - cout << endl; - cout << " --errors-to-stdout OR -X\n"; - cout << " Print errors and help information to standard-output rather than\n"; - cout << " to standard-error.\n"; - cout << endl; - cout << " --preserve-date OR -Z\n"; - cout << " Preserve the original file's date and time modified. The time\n"; - cout << " modified will be changed a few micro seconds to force a compile.\n"; - cout << endl; - cout << " --verbose OR -v\n"; - cout << " Verbose mode. Extra informational messages will be displayed.\n"; - cout << endl; - cout << " --formatted OR -Q\n"; - cout << " Formatted display mode. Display only the files that have been\n"; - cout << " formatted.\n"; - cout << endl; - cout << " --quiet OR -q\n"; - cout << " Quiet mode. Suppress all output except error messages.\n"; - cout << endl; - cout << " --lineend=windows OR -z1\n"; - cout << " --lineend=linux OR -z2\n"; - cout << " --lineend=macold OR -z3\n"; - cout << " Force use of the specified line end style. Valid options\n"; - cout << " are windows (CRLF), linux (LF), and macold (CR).\n"; - cout << endl; - cout << "Command Line Only:\n"; - cout << "------------------\n"; - cout << " --options=####\n"; - cout << " --options=none\n"; - cout << " Specify a default option file #### to read and use.\n"; - cout << " It must contain a file path and a file name.\n"; - cout << " 'none' disables the default option file.\n"; - cout << endl; - cout << " --project\n"; - cout << " --project=####\n"; - cout << " --project=none\n"; - cout << " Specify a project option file #### to read and use.\n"; - cout << " It must contain a file name only, without a directory path.\n"; - cout << " The file should be included in the project top-level directory.\n"; - cout << " The default file name is .astylerc or _astylerc.\n"; - cout << " 'none' disables the project or environment variable file.\n"; - cout << endl; - cout << " --ascii OR -I\n"; - cout << " The displayed output will be ascii characters only.\n"; - cout << endl; - cout << " --version OR -V\n"; - cout << " Print version number.\n"; - cout << endl; - cout << " --help OR -h OR -?\n"; - cout << " Print this help message.\n"; - cout << endl; - cout << " --html OR -!\n"; - cout << " Open the HTML help file \"astyle.html\" in the default browser.\n"; - cout << " The documentation must be installed in the standard install path.\n"; - cout << endl; - cout << " --html=####\n"; - cout << " Open a HTML help file in the default browser using the file path\n"; - cout << " ####. The path may include a directory path and a file name, or a\n"; - cout << " file name only. Paths containing spaces must be enclosed in quotes.\n"; - cout << endl; - cout << " --stdin=####\n"; - cout << " Use the file path #### as input to single file formatting.\n"; - cout << " This is a replacement for redirection.\n"; - cout << endl; - cout << " --stdout=####\n"; - cout << " Use the file path #### as output from single file formatting.\n"; - cout << " This is a replacement for redirection.\n"; - cout << endl; - cout << endl; + std::cout << std::endl; + std::cout << " Artistic Style " << g_version << std::endl; + std::cout << " Maintained by: Andre Simon, Jim Pattee\n"; + std::cout << " Original Author: Tal Davidson\n"; + std::cout << std::endl; + std::cout << "Usage:\n"; + std::cout << "------\n"; + std::cout << " astyle [OPTIONS] File1 File2 File3 [...]\n"; + std::cout << std::endl; + std::cout << " astyle [OPTIONS] < Original > Beautified\n"; + std::cout << std::endl; + std::cout << " When indenting a specific file, the resulting indented file RETAINS\n"; + std::cout << " the original file-name. The original pre-indented file is renamed,\n"; + std::cout << " with a suffix of \'.orig\' added to the original filename.\n"; + std::cout << std::endl; + std::cout << " Wildcards (* and ?) may be used in the filename.\n"; + std::cout << " A \'recursive\' option can process directories recursively.\n"; + std::cout << " Multiple file extensions may be separated by a comma.\n"; + std::cout << std::endl; + std::cout << " By default, astyle is set up to indent with four spaces per indent,\n"; + std::cout << " a maximal indentation of 40 spaces inside continuous statements,\n"; + std::cout << " a minimum indentation of eight spaces inside conditional statements,\n"; + std::cout << " and NO formatting options.\n"; + std::cout << std::endl; + std::cout << "Options:\n"; + std::cout << "--------\n"; + std::cout << " This program follows the usual GNU command line syntax.\n"; + std::cout << " Long options (starting with '--') must be written one at a time.\n"; + std::cout << " Short options (starting with '-') may be appended together.\n"; + std::cout << " Thus, -bps4 is the same as -b -p -s4.\n"; + std::cout << std::endl; + std::cout << "Option Files:\n"; + std::cout << "-------------\n"; + std::cout << " Artistic Style looks for a default option file and/or a project\n"; + std::cout << " option file in the following order:\n"; + std::cout << " 1. The command line options have precedence.\n"; + std::cout << " 2. The project option file has precedence over the default file\n"; + std::cout << " o the file name indicated by the --project= command line option.\n"; + std::cout << " o the file named .astylerc or _ astylerc.\n"; + std::cout << " o the file name identified by ARTISTIC_STYLE_PROJECT_OPTIONS.\n"; + std::cout << " o the file is disabled by --project=none on the command line.\n"; + std::cout << " 3. The default option file that can be used for all projects.\n"; + std::cout << " o the file path indicated by the --options= command line option.\n"; + std::cout << " o the file path indicated by ARTISTIC_STYLE_OPTIONS.\n"; + std::cout << " o the file named .astylerc in the HOME directory (for Linux).\n"; + std::cout << " o the file name astylerc in the APPDATA directory (for Windows).\n"; + std::cout << " o the file is disabled by --project=none on the command line.\n"; + std::cout << " Long options within the option files may be written without '--'.\n"; + std::cout << " Line-end comments begin with a '#'.\n"; + std::cout << std::endl; + std::cout << "Disable Formatting:\n"; + std::cout << "-------------------\n"; + std::cout << " Disable Block\n"; + std::cout << " Blocks of code can be disabled with the comment tags *INDENT-OFF*\n"; + std::cout << " and *INDENT-ON*. It must be contained in a one-line comment.\n"; + std::cout << std::endl; + std::cout << " Disable Line\n"; + std::cout << " Padding of operators can be disabled on a single line using the\n"; + std::cout << " comment tag *NOPAD*. It must be contained in a line-end comment.\n"; + std::cout << std::endl; + std::cout << "Brace Style Options:\n"; + std::cout << "--------------------\n"; + std::cout << " default brace style\n"; + std::cout << " If no brace style is requested, the opening braces will not be\n"; + std::cout << " changed and closing braces will be broken from the preceding line.\n"; + std::cout << std::endl; + std::cout << " --style=allman OR --style=bsd OR --style=break OR -A1\n"; + std::cout << " Allman style formatting/indenting.\n"; + std::cout << " Broken braces.\n"; + std::cout << std::endl; + std::cout << " --style=java OR --style=attach OR -A2\n"; + std::cout << " Java style formatting/indenting.\n"; + std::cout << " Attached braces.\n"; + std::cout << std::endl; + std::cout << " --style=kr OR --style=k&r OR --style=k/r OR -A3\n"; + std::cout << " Kernighan & Ritchie style formatting/indenting.\n"; + std::cout << " Linux braces.\n"; + std::cout << std::endl; + std::cout << " --style=stroustrup OR -A4\n"; + std::cout << " Stroustrup style formatting/indenting.\n"; + std::cout << " Linux braces, with broken closing headers.\n"; + std::cout << std::endl; + std::cout << " --style=whitesmith OR -A5\n"; + std::cout << " Whitesmith style formatting/indenting.\n"; + std::cout << " Broken, indented braces.\n"; + std::cout << " Indented class blocks and switch blocks.\n"; + std::cout << std::endl; + std::cout << " --style=vtk OR -A15\n"; + std::cout << " VTK style formatting/indenting.\n"; + std::cout << " Broken, indented braces except for the opening braces.\n"; + std::cout << std::endl; + std::cout << " --style=ratliff OR --style=banner OR -A6\n"; + std::cout << " Ratliff style formatting/indenting.\n"; + std::cout << " Attached, indented braces.\n"; + std::cout << std::endl; + std::cout << " --style=gnu OR -A7\n"; + std::cout << " GNU style formatting/indenting.\n"; + std::cout << " Broken braces, indented blocks.\n"; + std::cout << std::endl; + std::cout << " --style=linux OR --style=knf OR -A8\n"; + std::cout << " Linux style formatting/indenting.\n"; + std::cout << " Linux braces, minimum conditional indent is one-half indent.\n"; + std::cout << std::endl; + std::cout << " --style=horstmann OR --style=run-in OR -A9\n"; + std::cout << " Horstmann style formatting/indenting.\n"; + std::cout << " Run-in braces, indented switches.\n"; + std::cout << std::endl; + std::cout << " --style=1tbs OR --style=otbs OR -A10\n"; + std::cout << " One True Brace Style formatting/indenting.\n"; + std::cout << " Linux braces, add braces to all conditionals.\n"; + std::cout << std::endl; + std::cout << " --style=google OR -A14\n"; + std::cout << " Google style formatting/indenting.\n"; + std::cout << " Attached braces, indented class modifiers.\n"; + std::cout << std::endl; + std::cout << " --style=mozilla OR -A16\n"; + std::cout << " Mozilla style formatting/indenting.\n"; + std::cout << " Linux braces, with broken braces for structs and enums,\n"; + std::cout << " and attached braces for namespaces.\n"; + std::cout << std::endl; + std::cout << " --style=webkit OR -A17\n"; + std::cout << " WebKit style formatting/indenting.\n"; + std::cout << " Linux braces, with attached closing headers.\n"; + std::cout << std::endl; + std::cout << " --style=pico OR -A11\n"; + std::cout << " Pico style formatting/indenting.\n"; + std::cout << " Run-in opening braces and attached closing braces.\n"; + std::cout << " Uses keep one line blocks and keep one line statements.\n"; + std::cout << std::endl; + std::cout << " --style=lisp OR -A12\n"; + std::cout << " Lisp style formatting/indenting.\n"; + std::cout << " Attached opening braces and attached closing braces.\n"; + std::cout << " Uses keep one line statements.\n"; + std::cout << std::endl; + std::cout << "Tab Options:\n"; + std::cout << "------------\n"; + std::cout << " default indent option\n"; + std::cout << " If no indentation option is set, the default\n"; + std::cout << " option of 4 spaces per indent will be used.\n"; + std::cout << std::endl; + std::cout << " --indent=spaces=# OR -s#\n"; + std::cout << " Indent using # spaces per indent. Not specifying #\n"; + std::cout << " will result in a default of 4 spaces per indent.\n"; + std::cout << std::endl; + std::cout << " --indent=tab OR --indent=tab=# OR -t OR -t#\n"; + std::cout << " Indent using tab characters, assuming that each\n"; + std::cout << " indent is # spaces long. Not specifying # will result\n"; + std::cout << " in a default assumption of 4 spaces per indent.\n"; + std::cout << std::endl; + std::cout << " --indent=force-tab=# OR -T#\n"; + std::cout << " Indent using tab characters, assuming that each\n"; + std::cout << " indent is # spaces long. Force tabs to be used in areas\n"; + std::cout << " AStyle would prefer to use spaces.\n"; + std::cout << std::endl; + std::cout << " --indent=force-tab-x=# OR -xT#\n"; + std::cout << " Allows the tab length to be set to a length that is different\n"; + std::cout << " from the indent length. This may cause the indentation to be\n"; + std::cout << " a mix of both spaces and tabs. This option sets the tab length.\n"; + std::cout << std::endl; + std::cout << "Brace Modify Options:\n"; + std::cout << "---------------------\n"; + std::cout << " --attach-namespaces OR -xn\n"; + std::cout << " Attach braces to a namespace statement.\n"; + std::cout << std::endl; + std::cout << " --attach-classes OR -xc\n"; + std::cout << " Attach braces to a class statement.\n"; + std::cout << std::endl; + std::cout << " --attach-inlines OR -xl\n"; + std::cout << " Attach braces to class inline function definitions.\n"; + std::cout << std::endl; + std::cout << " --attach-extern-c OR -xk\n"; + std::cout << " Attach braces to an extern \"C\" statement.\n"; + std::cout << std::endl; + std::cout << " --attach-closing-while OR -xV\n"; + std::cout << " Attach closing while of do-while to the closing brace.\n"; + std::cout << std::endl; + std::cout << "Indentation Options:\n"; + std::cout << "--------------------\n"; + std::cout << " --indent-classes OR -C\n"; + std::cout << " Indent 'class' blocks so that the entire block is indented.\n"; + std::cout << std::endl; + std::cout << " --indent-modifiers OR -xG\n"; + std::cout << " Indent 'class' access modifiers, 'public:', 'protected:' or\n"; + std::cout << " 'private:', one half indent. The rest of the class is not\n"; + std::cout << " indented. \n"; + std::cout << std::endl; + std::cout << " --indent-switches OR -S\n"; + std::cout << " Indent 'switch' blocks, so that the inner 'case XXX:'\n"; + std::cout << " headers are indented in relation to the switch block.\n"; + std::cout << std::endl; + std::cout << " --indent-cases OR -K\n"; + std::cout << " Indent case blocks from the 'case XXX:' headers.\n"; + std::cout << " Case statements not enclosed in blocks are NOT indented.\n"; + std::cout << std::endl; + std::cout << " --indent-namespaces OR -N\n"; + std::cout << " Indent the contents of namespace blocks.\n"; + std::cout << std::endl; + std::cout << " --indent-after-parens OR -xU\n"; + std::cout << " Indent, instead of align, continuation lines following lines\n"; + std::cout << " that contain an opening paren '(' or an assignment '='. \n"; + std::cout << std::endl; + std::cout << " --indent-continuation=# OR -xt#\n"; + std::cout << " Indent continuation lines an additional # indents.\n"; + std::cout << " The valid values are 0 thru 4 indents.\n"; + std::cout << " The default value is 1 indent.\n"; + std::cout << std::endl; + std::cout << " --indent-labels OR -L\n"; + std::cout << " Indent labels so that they appear one indent less than\n"; + std::cout << " the current indentation level, rather than being\n"; + std::cout << " flushed completely to the left (which is the default).\n"; + std::cout << std::endl; + std::cout << " --indent-preproc-block OR -xW\n"; + std::cout << " Indent preprocessor blocks at brace level 0.\n"; + std::cout << " Without this option the preprocessor block is not indented.\n"; + std::cout << std::endl; + std::cout << " --indent-preproc-cond OR -xw\n"; + std::cout << " Indent preprocessor conditional statements #if/#else/#endif\n"; + std::cout << " to the same level as the source code.\n"; + std::cout << std::endl; + std::cout << " --indent-preproc-define OR -w\n"; + std::cout << " Indent multi-line preprocessor #define statements.\n"; + std::cout << std::endl; + std::cout << " --indent-col1-comments OR -Y\n"; + std::cout << " Indent line comments that start in column one.\n"; + std::cout << std::endl; + std::cout << " --min-conditional-indent=# OR -m#\n"; + std::cout << " Indent a minimal # spaces in a continuous conditional\n"; + std::cout << " belonging to a conditional header.\n"; + std::cout << " The valid values are:\n"; + std::cout << " 0 - no minimal indent.\n"; + std::cout << " 1 - indent at least one additional indent.\n"; + std::cout << " 2 - indent at least two additional indents.\n"; + std::cout << " 3 - indent at least one-half an additional indent.\n"; + std::cout << " The default value is 2, two additional indents.\n"; + std::cout << std::endl; + std::cout << " --max-continuation-indent=# OR -M#\n"; + std::cout << " Indent a maximal # spaces in a continuation line,\n"; + std::cout << " relative to the previous line.\n"; + std::cout << " The minimum and default value is 40.\n"; + std::cout << std::endl; + std::cout << "Padding Options:\n"; + std::cout << "----------------\n"; + std::cout << " --break-blocks OR -f\n"; + std::cout << " Insert empty lines around unrelated blocks, labels, classes, ...\n"; + std::cout << std::endl; + std::cout << " --break-blocks=all OR -F\n"; + std::cout << " Like --break-blocks, except also insert empty lines \n"; + std::cout << " around closing headers (e.g. 'else', 'catch', ...).\n"; + std::cout << std::endl; + std::cout << " --pad-oper OR -p\n"; + std::cout << " Insert space padding around operators.\n"; + std::cout << std::endl; + std::cout << " --pad-comma OR -xg\n"; + std::cout << " Insert space padding after commas.\n"; + std::cout << std::endl; + std::cout << " --pad-paren OR -P\n"; + std::cout << " Insert space padding around parenthesis on both the outside\n"; + std::cout << " and the inside.\n"; + std::cout << std::endl; + std::cout << " --pad-paren-out OR -d\n"; + std::cout << " Insert space padding around parenthesis on the outside only.\n"; + std::cout << std::endl; + std::cout << " --pad-first-paren-out OR -xd\n"; + std::cout << " Insert space padding around first parenthesis in a series on\n"; + std::cout << " the outside only.\n"; + std::cout << std::endl; + std::cout << " --pad-paren-in OR -D\n"; + std::cout << " Insert space padding around parenthesis on the inside only.\n"; + std::cout << std::endl; + std::cout << " --pad-header OR -H\n"; + std::cout << " Insert space padding after paren headers (e.g. 'if', 'for'...).\n"; + std::cout << std::endl; + std::cout << " --unpad-paren OR -U\n"; + std::cout << " Remove unnecessary space padding around parenthesis. This\n"; + std::cout << " can be used in combination with the 'pad' options above.\n"; + std::cout << std::endl; + std::cout << " --delete-empty-lines OR -xe\n"; + std::cout << " Delete empty lines within a function or method.\n"; + std::cout << " It will NOT delete lines added by the break-blocks options.\n"; + std::cout << std::endl; + std::cout << " --fill-empty-lines OR -E\n"; + std::cout << " Fill empty lines with the white space of their\n"; + std::cout << " previous lines.\n"; + std::cout << std::endl; + std::cout << " --align-pointer=type OR -k1\n"; + std::cout << " --align-pointer=middle OR -k2\n"; + std::cout << " --align-pointer=name OR -k3\n"; + std::cout << " Attach a pointer or reference operator (*, &, or ^) to either\n"; + std::cout << " the operator type (left), middle, or operator name (right).\n"; + std::cout << " To align the reference separately use --align-reference.\n"; + std::cout << std::endl; + std::cout << " --align-reference=none OR -W0\n"; + std::cout << " --align-reference=type OR -W1\n"; + std::cout << " --align-reference=middle OR -W2\n"; + std::cout << " --align-reference=name OR -W3\n"; + std::cout << " Attach a reference operator (&) to either\n"; + std::cout << " the operator type (left), middle, or operator name (right).\n"; + std::cout << " If not set, follow pointer alignment.\n"; + std::cout << std::endl; + std::cout << "Formatting Options:\n"; + std::cout << "-------------------\n"; + std::cout << " --break-closing-braces OR -y\n"; + std::cout << " Break braces before closing headers (e.g. 'else', 'catch', ...).\n"; + std::cout << " Use with --style=java, --style=kr, --style=stroustrup,\n"; + std::cout << " --style=linux, or --style=1tbs.\n"; + std::cout << std::endl; + std::cout << " --break-elseifs OR -e\n"; + std::cout << " Break 'else if()' statements into two different lines.\n"; + std::cout << std::endl; + std::cout << " --break-one-line-headers OR -xb\n"; + std::cout << " Break one line headers (e.g. 'if', 'while', 'else', ...) from a\n"; + std::cout << " statement residing on the same line.\n"; + std::cout << std::endl; + std::cout << " --add-braces OR -j\n"; + std::cout << " Add braces to unbraced one line conditional statements.\n"; + std::cout << std::endl; + std::cout << " --add-one-line-braces OR -J\n"; + std::cout << " Add one line braces to unbraced one line conditional\n"; + std::cout << " statements.\n"; + std::cout << std::endl; + std::cout << " --remove-braces OR -xj\n"; + std::cout << " Remove braces from a braced one line conditional statements.\n"; + std::cout << std::endl; + std::cout << " --break-return-type OR -xB\n"; + std::cout << " --break-return-type-decl OR -xD\n"; + std::cout << " Break the return type from the function name. Options are\n"; + std::cout << " for the function definitions and the function declarations.\n"; + std::cout << std::endl; + std::cout << " --attach-return-type OR -xf\n"; + std::cout << " --attach-return-type-decl OR -xh\n"; + std::cout << " Attach the return type to the function name. Options are\n"; + std::cout << " for the function definitions and the function declarations.\n"; + std::cout << std::endl; + std::cout << " --keep-one-line-blocks OR -O\n"; + std::cout << " Don't break blocks residing completely on one line.\n"; + std::cout << std::endl; + std::cout << " --keep-one-line-statements OR -o\n"; + std::cout << " Don't break lines containing multiple statements into\n"; + std::cout << " multiple single-statement lines.\n"; + std::cout << std::endl; + std::cout << " --convert-tabs OR -c\n"; + std::cout << " Convert tabs to the appropriate number of spaces.\n"; + std::cout << std::endl; + std::cout << " --close-templates OR -xy\n"; + std::cout << " Close ending angle brackets on template definitions.\n"; + std::cout << std::endl; + std::cout << " --remove-comment-prefix OR -xp\n"; + std::cout << " Remove the leading '*' prefix on multi-line comments and\n"; + std::cout << " indent the comment text one indent.\n"; + std::cout << std::endl; + std::cout << " --max-code-length=# OR -xC#\n"; + std::cout << " --break-after-logical OR -xL\n"; + std::cout << " max-code-length=# will break the line if it exceeds more than\n"; + std::cout << " # characters. The valid values are 50 thru 200.\n"; + std::cout << " If the line contains logical conditionals they will be placed\n"; + std::cout << " first on the new line. The option break-after-logical will\n"; + std::cout << " cause the logical conditional to be placed last on the\n"; + std::cout << " previous line.\n"; + std::cout << std::endl; + std::cout << " --mode=c\n"; + std::cout << " Indent a C or C++ source file (this is the default).\n"; + std::cout << std::endl; + std::cout << " --mode=java\n"; + std::cout << " Indent a Java source file.\n"; + std::cout << std::endl; + std::cout << " --mode=cs\n"; + std::cout << " Indent a C# source file.\n"; + std::cout << std::endl; + std::cout << " --mode=objc\n"; + std::cout << " Indent an Objective-C source file.\n"; + std::cout << std::endl; + std::cout << " --mode=js\n"; + std::cout << " Indent a JavaScript source file (experimental).\n"; + std::cout << std::endl; + std::cout << "Objective-C Options:\n"; + std::cout << "--------------------\n"; + std::cout << " --pad-method-prefix OR -xQ\n"; + std::cout << " Insert space padding after the '-' or '+' Objective-C\n"; + std::cout << " method prefix.\n"; + std::cout << std::endl; + std::cout << " --unpad-method-prefix OR -xR\n"; + std::cout << " Remove all space padding after the '-' or '+' Objective-C\n"; + std::cout << " method prefix.\n"; + std::cout << std::endl; + std::cout << " --pad-return-type OR -xq\n"; + std::cout << " Insert space padding after the Objective-C return type.\n"; + std::cout << std::endl; + std::cout << " --unpad-return-type OR -xr\n"; + std::cout << " Remove all space padding after the Objective-C return type.\n"; + std::cout << std::endl; + std::cout << " --pad-param-type OR -xS\n"; + std::cout << " Insert space padding after the Objective-C param type.\n"; + std::cout << std::endl; + std::cout << " --unpad-param-type OR -xs\n"; + std::cout << " Remove all space padding after the Objective-C param type.\n"; + std::cout << std::endl; + std::cout << " --align-method-colon OR -xM\n"; + std::cout << " Align the colons in an Objective-C method definition.\n"; + std::cout << std::endl; + std::cout << " --pad-method-colon=none OR -xP\n"; + std::cout << " --pad-method-colon=all OR -xP1\n"; + std::cout << " --pad-method-colon=after OR -xP2\n"; + std::cout << " --pad-method-colon=before OR -xP3\n"; + std::cout << " Add or remove space padding before or after the colons in an\n"; + std::cout << " Objective-C method call.\n"; + std::cout << std::endl; + std::cout << "Other Options:\n"; + std::cout << "--------------\n"; + std::cout << " --suffix=####\n"; + std::cout << " Append the suffix #### instead of '.orig' to original filename.\n"; + std::cout << std::endl; + std::cout << " --suffix=none OR -n\n"; + std::cout << " Do not retain a backup of the original file.\n"; + std::cout << std::endl; + std::cout << " --recursive OR -r OR -R\n"; + std::cout << " Process subdirectories recursively.\n"; + std::cout << std::endl; + std::cout << " --dry-run\n"; + std::cout << " Perform a trial run with no changes made to check for formatting.\n"; + std::cout << std::endl; + std::cout << " --exclude=####\n"; + std::cout << " Specify a file or directory #### to be excluded from processing.\n"; + std::cout << std::endl; + std::cout << " --ignore-exclude-errors OR -i\n"; + std::cout << " Allow processing to continue if there are errors in the exclude=####\n"; + std::cout << " options. It will display the unmatched excludes.\n"; + std::cout << std::endl; + std::cout << " --ignore-exclude-errors-x OR -xi\n"; + std::cout << " Allow processing to continue if there are errors in the exclude=####\n"; + std::cout << " options. It will NOT display the unmatched excludes.\n"; + std::cout << std::endl; + std::cout << " --errors-to-stdout OR -X\n"; + std::cout << " Print errors and help information to standard-output rather than\n"; + std::cout << " to standard-error.\n"; + std::cout << std::endl; + std::cout << " --preserve-date OR -Z\n"; + std::cout << " Preserve the original file's date and time modified. The time\n"; + std::cout << " modified will be changed a few micro seconds to force a compile.\n"; + std::cout << std::endl; + std::cout << " --verbose OR -v\n"; + std::cout << " Verbose mode. Extra informational messages will be displayed.\n"; + std::cout << std::endl; + std::cout << " --formatted OR -Q\n"; + std::cout << " Formatted display mode. Display only the files that have been\n"; + std::cout << " formatted.\n"; + std::cout << std::endl; + std::cout << " --quiet OR -q\n"; + std::cout << " Quiet mode. Suppress all output except error messages.\n"; + std::cout << std::endl; + std::cout << " --lineend=windows OR -z1\n"; + std::cout << " --lineend=linux OR -z2\n"; + std::cout << " --lineend=macold OR -z3\n"; + std::cout << " Force use of the specified line end style. Valid options\n"; + std::cout << " are windows (CRLF), linux (LF), and macold (CR).\n"; + std::cout << std::endl; + std::cout << "Command Line Only:\n"; + std::cout << "------------------\n"; + std::cout << " --options=####\n"; + std::cout << " --options=none\n"; + std::cout << " Specify a default option file #### to read and use.\n"; + std::cout << " It must contain a file path and a file name.\n"; + std::cout << " 'none' disables the default option file.\n"; + std::cout << std::endl; + std::cout << " --project\n"; + std::cout << " --project=####\n"; + std::cout << " --project=none\n"; + std::cout << " Specify a project option file #### to read and use.\n"; + std::cout << " It must contain a file name only, without a directory path.\n"; + std::cout << " The file should be included in the project top-level directory.\n"; + std::cout << " The default file name is .astylerc or _astylerc.\n"; + std::cout << " 'none' disables the project or environment variable file.\n"; + std::cout << std::endl; + std::cout << " --ascii OR -I\n"; + std::cout << " The displayed output will be ascii characters only.\n"; + std::cout << std::endl; + std::cout << " --version OR -V\n"; + std::cout << " Print version number.\n"; + std::cout << std::endl; + std::cout << " --help OR -h OR -?\n"; + std::cout << " Print this help message.\n"; + std::cout << std::endl; + std::cout << " --html OR -!\n"; + std::cout << " Open the HTML help file \"astyle.html\" in the default browser.\n"; + std::cout << " The documentation must be installed in the standard install path.\n"; + std::cout << std::endl; + std::cout << " --html=####\n"; + std::cout << " Open a HTML help file in the default browser using the file path\n"; + std::cout << " ####. The path may include a directory path and a file name, or a\n"; + std::cout << " file name only. Paths containing spaces must be enclosed in quotes.\n"; + std::cout << std::endl; + std::cout << " --stdin=####\n"; + std::cout << " Use the file path #### as input to single file formatting.\n"; + std::cout << " This is a replacement for redirection.\n"; + std::cout << std::endl; + std::cout << " --stdout=####\n"; + std::cout << " Use the file path #### as output from single file formatting.\n"; + std::cout << " This is a replacement for redirection.\n"; + std::cout << std::endl; + std::cout << std::endl; } /** @@ -2401,12 +2401,12 @@ void ASConsole::processFiles() clock_t startTime = clock(); // start time of file formatting // loop thru input fileNameVector and process the files - for (const string& fileNameVectorName : fileNameVector) + for (const std::string& fileNameVectorName : fileNameVector) { getFilePaths(fileNameVectorName); // loop thru fileName vector formatting the files - for (const string& file : fileName) + for (const std::string& file : fileName) formatFile(file); } @@ -2418,17 +2418,17 @@ void ASConsole::processFiles() // process options from the command line and option files // build the vectors fileNameVector, excludeVector, optionsVector, // projectOptionsVector and fileOptionsVector -void ASConsole::processOptions(const vector& argvOptions) +void ASConsole::processOptions(const std::vector& argvOptions) { bool ok = true; bool optionFileRequired = false; bool shouldParseOptionFile = true; bool projectOptionFileRequired = false; bool shouldParseProjectOptionFile = true; - string projectOptionArg; // save for display + std::string projectOptionArg; // save for display // get command line options - for (string arg : argvOptions) + for (std::string arg : argvOptions) { if (isOption(arg, "-I") || isOption(arg, "--ascii")) @@ -2486,7 +2486,7 @@ void ASConsole::processOptions(const vector& argvOptions) } else if (isParamOption(arg, "--html=")) { - string htmlFilePath = getParam(arg, "--html="); + std::string htmlFilePath = getParam(arg, "--html="); launchDefaultBrowser(htmlFilePath.c_str()); exit(EXIT_SUCCESS); } @@ -2498,13 +2498,13 @@ void ASConsole::processOptions(const vector& argvOptions) } else if (isParamOption(arg, "--stdin=")) { - string path = getParam(arg, "--stdin="); + std::string path = getParam(arg, "--stdin="); standardizePath(path); setStdPathIn(path); } else if (isParamOption(arg, "--stdout=")) { - string path = getParam(arg, "--stdout="); + std::string path = getParam(arg, "--stdout="); standardizePath(path); setStdPathOut(path); } @@ -2538,7 +2538,7 @@ void ASConsole::processOptions(const vector& argvOptions) const char* const env = getenv("HOME"); if (env != nullptr) { - string name = string(env) + "/.astylerc"; + std::string name = std::string(env) + "/.astylerc"; if (fileExists(name.c_str())) setOptionFileName(name); } @@ -2549,7 +2549,7 @@ void ASConsole::processOptions(const vector& argvOptions) const char* const env = getenv("APPDATA"); if (env != nullptr) { - string name = string(env) + "\\astylerc"; + std::string name = std::string(env) + "\\astylerc"; if (fileExists(name.c_str())) setOptionFileName(name); } @@ -2560,7 +2560,7 @@ void ASConsole::processOptions(const vector& argvOptions) // find project option file if (projectOptionFileRequired) { - string optfilepath = findProjectOptionFilePath(projectOptionFileName); + std::string optfilepath = findProjectOptionFilePath(projectOptionFileName); if (optfilepath.empty() || projectOptionArg.empty()) error(_("Cannot open project option file"), projectOptionArg.c_str()); standardizePath(optfilepath); @@ -2571,7 +2571,7 @@ void ASConsole::processOptions(const vector& argvOptions) const char* const env = getenv("ARTISTIC_STYLE_PROJECT_OPTIONS"); if (env != nullptr) { - string optfilepath = findProjectOptionFilePath(env); + std::string optfilepath = findProjectOptionFilePath(env); standardizePath(optfilepath); setProjectOptionFileName(optfilepath); } @@ -2580,7 +2580,7 @@ void ASConsole::processOptions(const vector& argvOptions) ASOptions options(formatter, *this); if (!optionFileName.empty()) { - stringstream optionsIn; + std::stringstream optionsIn; if (!fileExists(optionFileName.c_str())) error(_("Cannot open default option file"), optionFileName.c_str()); FileEncoding encoding = readFile(optionFileName, optionsIn); @@ -2593,7 +2593,7 @@ void ASConsole::processOptions(const vector& argvOptions) } options.importOptions(optionsIn, fileOptionsVector); ok = options.parseOptions(fileOptionsVector, - string(_("Invalid default options:"))); + std::string(_("Invalid default options:"))); } else if (optionFileRequired) error(_("Cannot open default option file"), optionFileName.c_str()); @@ -2601,13 +2601,13 @@ void ASConsole::processOptions(const vector& argvOptions) if (!ok) { (*errorStream) << options.getOptionErrors(); - (*errorStream) << _("For help on options type 'astyle -h'") << endl; + (*errorStream) << _("For help on options type 'astyle -h'") << std::endl; error(); } if (!projectOptionFileName.empty()) { - stringstream projectOptionsIn; + std::stringstream projectOptionsIn; if (!fileExists(projectOptionFileName.c_str())) error(_("Cannot open project option file"), projectOptionFileName.c_str()); FileEncoding encoding = readFile(projectOptionFileName, projectOptionsIn); @@ -2620,23 +2620,23 @@ void ASConsole::processOptions(const vector& argvOptions) } options.importOptions(projectOptionsIn, projectOptionsVector); ok = options.parseOptions(projectOptionsVector, - string(_("Invalid project options:"))); + std::string(_("Invalid project options:"))); } if (!ok) { (*errorStream) << options.getOptionErrors(); - (*errorStream) << _("For help on options type 'astyle -h'") << endl; + (*errorStream) << _("For help on options type 'astyle -h'") << std::endl; error(); } // parse the command line options vector for errors ok = options.parseOptions(optionsVector, - string(_("Invalid command line options:"))); + std::string(_("Invalid command line options:"))); if (!ok) { (*errorStream) << options.getOptionErrors(); - (*errorStream) << _("For help on options type 'astyle -h'") << endl; + (*errorStream) << _("For help on options type 'astyle -h'") << std::endl; error(); } } @@ -2680,7 +2680,7 @@ void ASConsole::renameFile(const char* oldFileName, const char* newFileName, con // make sure file separators are correct type (Windows or Linux) // remove ending file separator // remove beginning file separator if requested and NOT a complete file path -void ASConsole::standardizePath(string& path, bool removeBeginningSeparator /*false*/) const +void ASConsole::standardizePath(std::string& path, bool removeBeginningSeparator /*false*/) const { #ifdef __VMS struct FAB fab; @@ -2732,7 +2732,7 @@ void ASConsole::standardizePath(string& path, bool removeBeginningSeparator /*fa for (size_t i = 0; i < path.length(); i++) { i = path.find_first_of("/\\", i); - if (i == string::npos) + if (i == std::string::npos) break; path[i] = g_fileSeparator; } @@ -2741,7 +2741,7 @@ void ASConsole::standardizePath(string& path, bool removeBeginningSeparator /*fa path.erase(0, 1); } -void ASConsole::printMsg(const char* msg, const string& data) const +void ASConsole::printMsg(const char* msg, const std::string& data) const { if (isQuiet) return; @@ -2750,7 +2750,7 @@ void ASConsole::printMsg(const char* msg, const string& data) const void ASConsole::printSeparatingLine() const { - string line; + std::string line; for (size_t i = 0; i < 60; i++) line.append("-"); printMsg("%s\n", line); @@ -2769,7 +2769,7 @@ void ASConsole::printVerboseHeader() const strftime(str, 20, "%x", ptr); // print the header // 60 is the length of the separator in printSeparatingLine() - string header = "Artistic Style " + string(g_version); + std::string header = "Artistic Style " + std::string(g_version); size_t numSpaces = 60 - header.length() - strlen(str); header.append(numSpaces, ' '); header.append(str); @@ -2790,8 +2790,8 @@ void ASConsole::printVerboseStats(clock_t startTime) const return; if (hasWildcard) printSeparatingLine(); - string formatted = getNumberFormat(filesFormatted); - string unchanged = getNumberFormat(filesUnchanged); + std::string formatted = getNumberFormat(filesFormatted); + std::string unchanged = getNumberFormat(filesUnchanged); printf(_(" %s formatted %s unchanged "), formatted.c_str(), unchanged.c_str()); // show processing time @@ -2817,7 +2817,7 @@ void ASConsole::printVerboseStats(clock_t startTime) const printf(_("%d min %d sec "), min, minsec); } - string lines = getNumberFormat(linesOut); + std::string lines = getNumberFormat(linesOut); printf(_("%s lines\n"), lines.c_str()); printf("\n"); } @@ -2829,7 +2829,7 @@ void ASConsole::sleep(int seconds) const while (clock() < endwait) {} } -bool ASConsole::stringEndsWith(const string& str, const string& suffix) const +bool ASConsole::stringEndsWith(const std::string& str, const std::string& suffix) const { int strIndex = (int) str.length() - 1; int suffixIndex = (int) suffix.length() - 1; @@ -2848,7 +2848,7 @@ bool ASConsole::stringEndsWith(const string& str, const string& suffix) const return true; } -void ASConsole::updateExcludeVector(const string& suffixParam) +void ASConsole::updateExcludeVector(const std::string& suffixParam) { excludeVector.emplace_back(suffixParam); standardizePath(excludeVector.back(), true); @@ -2933,7 +2933,7 @@ int ASConsole::wildcmp(const char* wild, const char* data) const return !*wild; } -void ASConsole::writeFile(const string& fileName_, FileEncoding encoding, ostringstream& out) const +void ASConsole::writeFile(const std::string& fileName_, FileEncoding encoding, std::ostringstream& out) const { // save date accessed and date modified of original file struct stat stBuf; @@ -2944,13 +2944,13 @@ void ASConsole::writeFile(const string& fileName_, FileEncoding encoding, ostrin // create a backup if (!noBackup) { - string origFileName = fileName_ + origSuffix; + std::string origFileName = fileName_ + origSuffix; removeFile(origFileName.c_str(), "Cannot remove pre-existing backup file"); renameFile(fileName_.c_str(), origFileName.c_str(), "Cannot create backup file"); } // write the output file - ofstream fout(fileName_.c_str(), ios::binary | ios::trunc); + std::ofstream fout(fileName_.c_str(), std::ios::binary | std::ios::trunc); if (!fout) error("Cannot open output file", fileName_.c_str()); if (encoding == UTF_16LE || encoding == UTF_16BE) @@ -2962,7 +2962,7 @@ void ASConsole::writeFile(const string& fileName_, FileEncoding encoding, ostrin size_t utf16Len = encode.utf8ToUtf16(const_cast(out.str().c_str()), out.str().length(), isBigEndian, utf16Out); assert(utf16Len <= utf16Size); - fout << string(utf16Out, utf16Len); + fout << std::string(utf16Out, utf16Len); delete[] utf16Out; } else @@ -2987,7 +2987,7 @@ void ASConsole::writeFile(const string& fileName_, FileEncoding encoding, ostrin if (statErr) { perror("errno message"); - (*errorStream) << "********* Cannot preserve file date" << endl; + (*errorStream) << "********* Cannot preserve file date" << std::endl; } } } @@ -3047,7 +3047,7 @@ char16_t* ASLibrary::formatUtf16(const char16_t* pSourceIn, // the source to be // The data will be converted before being returned to the calling program. char* STDCALL ASLibrary::tempMemoryAllocation(unsigned long memoryNeeded) { - char* buffer = new (nothrow) char[memoryNeeded]; + char* buffer = new (std::nothrow) char[memoryNeeded]; return buffer; } @@ -3092,7 +3092,7 @@ char* ASLibrary::convertUtf16ToUtf8(const char16_t* utf16In) const size_t dataSize = encode.utf16len(utf16In) * sizeof(char16_t); bool isBigEndian = encode.getBigEndian(); size_t utf8Size = encode.utf8LengthFromUtf16(data, dataSize, isBigEndian) + 1; - char* utf8Out = new (nothrow) char[utf8Size]; + char* utf8Out = new (std::nothrow) char[utf8Size]; if (utf8Out == nullptr) return nullptr; #ifdef NDEBUG @@ -3130,11 +3130,11 @@ ASOptions::ASOptions(ASFormatter& formatterArg, ASConsole& consoleArg) * * @return true if no errors, false if errors */ -bool ASOptions::parseOptions(vector& optionsVector, const string& errorInfo) +bool ASOptions::parseOptions(std::vector& optionsVector, const std::string& errorInfo) { - vector::iterator option; - string arg; - string subArg; + std::vector::iterator option; + std::string arg; + std::string subArg; optionErrors.clear(); for (option = optionsVector.begin(); option != optionsVector.end(); ++option) @@ -3175,7 +3175,7 @@ bool ASOptions::parseOptions(vector& optionsVector, const string& errorI return true; } -void ASOptions::parseOption(const string& arg, const string& errorInfo) +void ASOptions::parseOption(const std::string& arg, const std::string& errorInfo) { if (isOption(arg, "A1", "style=allman") || isOption(arg, "style=bsd") || isOption(arg, "style=break")) { @@ -3270,7 +3270,7 @@ void ASOptions::parseOption(const string& arg, const string& errorInfo) else if (isParamOption(arg, "t", "indent=tab=")) { int spaceNum = 4; - string spaceNumParam = getParam(arg, "t", "indent=tab="); + std::string spaceNumParam = getParam(arg, "t", "indent=tab="); if (spaceNumParam.length() > 0) spaceNum = atoi(spaceNumParam.c_str()); if (spaceNum < 2 || spaceNum > 20) @@ -3287,7 +3287,7 @@ void ASOptions::parseOption(const string& arg, const string& errorInfo) else if (isParamOption(arg, "T", "indent=force-tab=")) { int spaceNum = 4; - string spaceNumParam = getParam(arg, "T", "indent=force-tab="); + std::string spaceNumParam = getParam(arg, "T", "indent=force-tab="); if (spaceNumParam.length() > 0) spaceNum = atoi(spaceNumParam.c_str()); if (spaceNum < 2 || spaceNum > 20) @@ -3304,7 +3304,7 @@ void ASOptions::parseOption(const string& arg, const string& errorInfo) else if (isParamOption(arg, "xT", "indent=force-tab-x=")) { int tabNum = 8; - string tabNumParam = getParam(arg, "xT", "indent=force-tab-x="); + std::string tabNumParam = getParam(arg, "xT", "indent=force-tab-x="); if (tabNumParam.length() > 0) tabNum = atoi(tabNumParam.c_str()); if (tabNum < 2 || tabNum > 20) @@ -3321,7 +3321,7 @@ void ASOptions::parseOption(const string& arg, const string& errorInfo) else if (isParamOption(arg, "s", "indent=spaces=")) { int spaceNum = 4; - string spaceNumParam = getParam(arg, "s", "indent=spaces="); + std::string spaceNumParam = getParam(arg, "s", "indent=spaces="); if (spaceNumParam.length() > 0) spaceNum = atoi(spaceNumParam.c_str()); if (spaceNum < 2 || spaceNum > 20) @@ -3338,7 +3338,7 @@ void ASOptions::parseOption(const string& arg, const string& errorInfo) else if (isParamOption(arg, "xt", "indent-continuation=")) { int contIndent = 1; - string contIndentParam = getParam(arg, "xt", "indent-continuation="); + std::string contIndentParam = getParam(arg, "xt", "indent-continuation="); if (contIndentParam.length() > 0) contIndent = atoi(contIndentParam.c_str()); if (contIndent < 0) @@ -3351,7 +3351,7 @@ void ASOptions::parseOption(const string& arg, const string& errorInfo) else if (isParamOption(arg, "m", "min-conditional-indent=")) { int minIndent = MINCOND_TWO; - string minIndentParam = getParam(arg, "m", "min-conditional-indent="); + std::string minIndentParam = getParam(arg, "m", "min-conditional-indent="); if (minIndentParam.length() > 0) minIndent = atoi(minIndentParam.c_str()); if (minIndent >= MINCOND_END) @@ -3362,7 +3362,7 @@ void ASOptions::parseOption(const string& arg, const string& errorInfo) else if (isParamOption(arg, "M", "max-continuation-indent=")) { int maxIndent = 40; - string maxIndentParam = getParam(arg, "M", "max-continuation-indent="); + std::string maxIndentParam = getParam(arg, "M", "max-continuation-indent="); if (maxIndentParam.length() > 0) maxIndent = atoi(maxIndentParam.c_str()); if (maxIndent < 40) @@ -3519,7 +3519,7 @@ void ASOptions::parseOption(const string& arg, const string& errorInfo) else if (isParamOption(arg, "k")) { int align = 0; - string styleParam = getParam(arg, "k"); + std::string styleParam = getParam(arg, "k"); if (styleParam.length() > 0) align = atoi(styleParam.c_str()); if (align < 1 || align > 3) @@ -3550,7 +3550,7 @@ void ASOptions::parseOption(const string& arg, const string& errorInfo) else if (isParamOption(arg, "W")) { int align = 0; - string styleParam = getParam(arg, "W"); + std::string styleParam = getParam(arg, "W"); if (styleParam.length() > 0) align = atoi(styleParam.c_str()); if (align < 0 || align > 3) @@ -3567,7 +3567,7 @@ void ASOptions::parseOption(const string& arg, const string& errorInfo) else if (isParamOption(arg, "max-code-length=")) { int maxLength = 50; - string maxLengthParam = getParam(arg, "max-code-length="); + std::string maxLengthParam = getParam(arg, "max-code-length="); if (maxLengthParam.length() > 0) maxLength = atoi(maxLengthParam.c_str()); if (maxLength < 50) @@ -3580,7 +3580,7 @@ void ASOptions::parseOption(const string& arg, const string& errorInfo) else if (isParamOption(arg, "xC")) { int maxLength = 50; - string maxLengthParam = getParam(arg, "xC"); + std::string maxLengthParam = getParam(arg, "xC"); if (maxLengthParam.length() > 0) maxLength = atoi(maxLengthParam.c_str()); if (maxLength > 200) @@ -3643,7 +3643,7 @@ void ASOptions::parseOption(const string& arg, const string& errorInfo) // To avoid compiler limit of blocks nested too deep. // Return 'true' if the option was found and processed. // Return 'false' if the option was not found. -bool ASOptions::parseOptionContinued(const string& arg, const string& errorInfo) +bool ASOptions::parseOptionContinued(const std::string& arg, const std::string& errorInfo) { // Objective-C options if (isOption(arg, "xQ", "pad-method-prefix")) @@ -3706,7 +3706,7 @@ bool ASOptions::parseOptionContinued(const string& arg, const string& errorInfo) } else if (isParamOption(arg, "suffix=")) { - string suffixParam = getParam(arg, "suffix="); + std::string suffixParam = getParam(arg, "suffix="); if (suffixParam.length() > 0) { console.setOrigSuffix(suffixParam); @@ -3714,7 +3714,7 @@ bool ASOptions::parseOptionContinued(const string& arg, const string& errorInfo) } else if (isParamOption(arg, "exclude=")) { - string suffixParam = getParam(arg, "exclude="); + std::string suffixParam = getParam(arg, "exclude="); if (suffixParam.length() > 0) console.updateExcludeVector(suffixParam); } @@ -3752,7 +3752,7 @@ bool ASOptions::parseOptionContinued(const string& arg, const string& errorInfo) } else if (isOption(arg, "X", "errors-to-stdout")) { - console.setErrorStream(&cout); + console.setErrorStream(&std::cout); } else if (isOption(arg, "lineend=windows")) { @@ -3769,7 +3769,7 @@ bool ASOptions::parseOptionContinued(const string& arg, const string& errorInfo) else if (isParamOption(arg, "z")) { int lineendType = 0; - string lineendParam = getParam(arg, "z"); + std::string lineendParam = getParam(arg, "z"); if (lineendParam.length() > 0) lineendType = atoi(lineendParam.c_str()); if (lineendType < 1 || lineendType > 3) @@ -3790,12 +3790,12 @@ bool ASOptions::parseOptionContinued(const string& arg, const string& errorInfo) } // End of parseOptionContinued function // Parse options from the option file. -void ASOptions::importOptions(stringstream& in, vector& optionsVector) +void ASOptions::importOptions(std::stringstream& in, std::vector& optionsVector) { char ch; bool isInQuote = false; char quoteChar = ' '; - string currentToken; + std::string currentToken; while (in) { @@ -3838,39 +3838,39 @@ void ASOptions::importOptions(stringstream& in, vector& optionsVector) } } -string ASOptions::getOptionErrors() const +std::string ASOptions::getOptionErrors() const { return optionErrors.str(); } -string ASOptions::getParam(const string& arg, const char* op) +std::string ASOptions::getParam(const std::string& arg, const char* op) { return arg.substr(strlen(op)); } -string ASOptions::getParam(const string& arg, const char* op1, const char* op2) +std::string ASOptions::getParam(const std::string& arg, const char* op1, const char* op2) { return isParamOption(arg, op1) ? getParam(arg, op1) : getParam(arg, op2); } -bool ASOptions::isOption(const string& arg, const char* op) +bool ASOptions::isOption(const std::string& arg, const char* op) { return arg == op; } -bool ASOptions::isOption(const string& arg, const char* op1, const char* op2) +bool ASOptions::isOption(const std::string& arg, const char* op1, const char* op2) { return (isOption(arg, op1) || isOption(arg, op2)); } -void ASOptions::isOptionError(const string& arg, const string& errorInfo) +void ASOptions::isOptionError(const std::string& arg, const std::string& errorInfo) { if (optionErrors.str().length() == 0) - optionErrors << errorInfo << endl; // need main error message - optionErrors << "\t" << arg << endl; + optionErrors << errorInfo << std::endl; // need main error message + optionErrors << "\t" << arg << std::endl; } -bool ASOptions::isParamOption(const string& arg, const char* option) +bool ASOptions::isParamOption(const std::string& arg, const char* option) { bool retVal = arg.compare(0, strlen(option), option) == 0; // if comparing for short option, 2nd char of arg must be numeric @@ -3880,7 +3880,7 @@ bool ASOptions::isParamOption(const string& arg, const char* option) return retVal; } -bool ASOptions::isParamOption(const string& arg, const char* option1, const char* option2) +bool ASOptions::isParamOption(const std::string& arg, const char* option1, const char* option2) { return isParamOption(arg, option1) || isParamOption(arg, option2); } @@ -4183,7 +4183,7 @@ jstring STDCALL Java_AStyleInterface_AStyleMain(JNIEnv* env, g_mid = env->GetMethodID(cls, "ErrorHandler", "(ILjava/lang/String;)V"); if (g_mid == nullptr) { - cout << "Cannot find java method ErrorHandler" << endl; + std::cout << "Cannot find java method ErrorHandler" << std::endl; return textErr; } @@ -4217,7 +4217,7 @@ void STDCALL javaErrorHandler(int errorNumber, const char* errorMessage) char* STDCALL javaMemoryAlloc(unsigned long memoryNeeded) { // error condition is checked after return from AStyleMain - char* buffer = new (nothrow) char[memoryNeeded]; + char* buffer = new (std::nothrow) char[memoryNeeded]; return buffer; } @@ -4314,8 +4314,8 @@ extern "C" EXPORT char* STDCALL AStyleMain(const char* pSourceIn, // the source ASFormatter formatter; ASOptions options(formatter); - vector optionsVector; - stringstream opt(pOptions); + std::vector optionsVector; + std::stringstream opt(pOptions); options.importOptions(opt, optionsVector); @@ -4323,9 +4323,9 @@ extern "C" EXPORT char* STDCALL AStyleMain(const char* pSourceIn, // the source if (!ok) fpErrorHandler(130, options.getOptionErrors().c_str()); - stringstream in(pSourceIn); - ASStreamIterator streamIterator(&in); - ostringstream out; + std::stringstream in(pSourceIn); + ASStreamIterator streamIterator(&in); + std::ostringstream out; formatter.init(&streamIterator); while (formatter.hasMoreLines()) @@ -4381,11 +4381,11 @@ int main(int argc, char** argv) { // create objects ASFormatter formatter; - unique_ptr console(new ASConsole(formatter)); + std::unique_ptr console(new ASConsole(formatter)); // process command line and option files // build the vectors fileNameVector, optionsVector, and fileOptionsVector - vector argvOptions; + std::vector argvOptions; argvOptions = console->getArgvOptions(argc, argv); console->processOptions(argvOptions); diff --git a/AStyle/src/astyle_main.h b/AStyle/src/astyle_main.h index bcae474..31e4e24 100644 --- a/AStyle/src/astyle_main.h +++ b/AStyle/src/astyle_main.h @@ -110,29 +110,29 @@ class ASStreamIterator : public ASSourceIterator ~ASStreamIterator() override; bool getLineEndChange(int lineEndFormat) const; int getStreamLength() const override; - string nextLine(bool emptyLineWasDeleted) override; - string peekNextLine() override; + std::string nextLine(bool emptyLineWasDeleted) override; + std::string peekNextLine() override; void peekReset() override; void saveLastInputLine(); - streamoff tellg() override; + std::streamoff tellg() override; private: T* inStream; // pointer to the input stream - string buffer; // current input line - string prevBuffer; // previous input line - string outputEOL; // next output end of line char + std::string buffer; // current input line + std::string prevBuffer; // previous input line + std::string outputEOL; // next output end of line char int eolWindows; // number of Windows line endings, CRLF int eolLinux; // number of Linux line endings, LF int eolMacOld; // number of old Mac line endings. CR - streamoff streamLength; // length of the input file stream - streamoff peekStart; // starting position for peekNextLine + std::streamoff streamLength; // length of the input file stream + std::streamoff peekStart; // starting position for peekNextLine bool prevLineDeleted; // the previous input line was deleted public: // inline functions - bool compareToInputBuffer(const string& nextLine_) const + bool compareToInputBuffer(const std::string& nextLine_) const { return (nextLine_ == prevBuffer); } - const string& getOutputEOL() const { return outputEOL; } - streamoff getPeekStart() const override { return peekStart; } + const std::string& getOutputEOL() const { return outputEOL; } + std::streamoff getPeekStart() const override { return peekStart; } bool hasMoreLines() const override { return !inStream->eof(); } }; @@ -179,28 +179,28 @@ class ASOptions #else ASOptions(ASFormatter& formatterArg, ASConsole& consoleArg); #endif - string getOptionErrors() const; - void importOptions(stringstream& in, vector& optionsVector); - bool parseOptions(vector& optionsVector, const string& errorInfo); + std::string getOptionErrors() const; + void importOptions(std::stringstream& in, std::vector& optionsVector); + bool parseOptions(std::vector& optionsVector, const std::string& errorInfo); private: // variables ASFormatter& formatter; - stringstream optionErrors; // option error messages + std::stringstream optionErrors; // option error messages #ifndef ASTYLE_LIB ASConsole& console; // DO NOT USE for ASTYLE_LIB #endif // functions - string getParam(const string& arg, const char* op); - string getParam(const string& arg, const char* op1, const char* op2); - bool isOption(const string& arg, const char* op); - bool isOption(const string& arg, const char* op1, const char* op2); - void isOptionError(const string& arg, const string& errorInfo); - bool isParamOption(const string& arg, const char* option); - bool isParamOption(const string& arg, const char* option1, const char* option2); - void parseOption(const string& arg, const string& errorInfo); - bool parseOptionContinued(const string& arg, const string& errorInfo); + std::string getParam(const std::string& arg, const char* op); + std::string getParam(const std::string& arg, const char* op1, const char* op2); + bool isOption(const std::string& arg, const char* op); + bool isOption(const std::string& arg, const char* op1, const char* op2); + void isOptionError(const std::string& arg, const std::string& errorInfo); + bool isParamOption(const std::string& arg, const char* option); + bool isParamOption(const std::string& arg, const char* option1, const char* option2); + void parseOption(const std::string& arg, const std::string& errorInfo); + bool parseOptionContinued(const std::string& arg, const std::string& errorInfo); }; #ifndef ASTYLE_LIB @@ -215,7 +215,7 @@ class ASConsole ASFormatter& formatter; // reference to the ASFormatter object ASEncoding encode; // file encoding conversion ASLocalizer localizer; // language translation - ostream* errorStream; // direct error messages to cerr or cout + std::ostream* errorStream; // direct error messages to cerr or std::cout // command line options bool isRecursive; // recursive option bool isDryRun; // dry-run option @@ -237,38 +237,38 @@ class ASConsole bool lineEndsMixed; // output has mixed line ends int linesOut; // number of output lines - string outputEOL; // current line end - string prevEOL; // previous line end - string astyleExePath; // absolute executable path and name from argv[0] - string optionFileName; // file path and name of the options file - string origSuffix; // suffix= option - string projectOptionFileName; // file path and name of the project options file - string stdPathIn; // path to input from stdin= - string stdPathOut; // path to output from stdout= - string targetDirectory; // path to the directory being processed - string targetFilename; // file name being processed - - vector excludeVector; // exclude from wildcard hits - vector excludeHitsVector; // exclude flags for error reporting - vector fileNameVector; // file paths and names from the command line - vector optionsVector; // options from the command line - vector projectOptionsVector;// project options from the project options file - vector fileOptionsVector; // options from the options file - vector fileName; // files to be processed including path + std::string outputEOL; // current line end + std::string prevEOL; // previous line end + std::string astyleExePath; // absolute executable path and name from argv[0] + std::string optionFileName; // file path and name of the options file + std::string origSuffix; // suffix= option + std::string projectOptionFileName; // file path and name of the project options file + std::string stdPathIn; // path to input from stdin= + std::string stdPathOut; // path to output from stdout= + std::string targetDirectory; // path to the directory being processed + std::string targetFilename; // file name being processed + + std::vector excludeVector; // exclude from wildcard hits + std::vector excludeHitsVector; // exclude flags for error reporting + std::vector fileNameVector; // file paths and names from the command line + std::vector optionsVector; // options from the command line + std::vector projectOptionsVector;// project options from the project options file + std::vector fileOptionsVector; // options from the options file + std::vector fileName; // files to be processed including path public: // functions explicit ASConsole(ASFormatter& formatterArg); ASConsole(const ASConsole&) = delete; ASConsole& operator=(ASConsole const&) = delete; - void convertLineEnds(ostringstream& out, int lineEnd); + void convertLineEnds(std::ostringstream& out, int lineEnd); FileEncoding detectEncoding(const char* data, size_t dataSize) const; void error() const; void error(const char* why, const char* what) const; void formatCinToCout(); - vector getArgvOptions(int argc, char** argv); + std::vector getArgvOptions(int argc, char** argv); bool fileExists(const char* file) const; bool fileNameVectorIsEmpty() const; - ostream* getErrorStream() const; + std::ostream* getErrorStream() const; bool getFilesAreIdentical() const; int getFilesFormatted() const; bool getIgnoreExcludeErrors() const; @@ -281,19 +281,19 @@ class ASConsole bool getLineEndsMixed() const; bool getNoBackup() const; bool getPreserveDate() const; - string getLanguageID() const; - string getNumberFormat(int num, size_t lcid = 0) const; - string getNumberFormat(int num, const char* groupingArg, const char* separator) const; - string getOptionFileName() const; - string getOrigSuffix() const; - string getProjectOptionFileName() const; - string getStdPathIn() const; - string getStdPathOut() const; - void getTargetFilenames(string& targetFilename_, vector& targetFilenameVector) const; + std::string getLanguageID() const; + std::string getNumberFormat(int num, size_t lcid = 0) const; + std::string getNumberFormat(int num, const char* groupingArg, const char* separator) const; + std::string getOptionFileName() const; + std::string getOrigSuffix() const; + std::string getProjectOptionFileName() const; + std::string getStdPathIn() const; + std::string getStdPathOut() const; + void getTargetFilenames(std::string& targetFilename_, std::vector& targetFilenameVector) const; void processFiles(); - void processOptions(const vector& argvOptions); + void processOptions(const std::vector& argvOptions); void setBypassBrowserOpen(bool state); - void setErrorStream(ostream* errStreamPtr); + void setErrorStream(std::ostream* errStreamPtr); void setIgnoreExcludeErrors(bool state); void setIgnoreExcludeErrorsAndDisplay(bool state); void setIsDryRun(bool state); @@ -302,54 +302,54 @@ class ASConsole void setIsRecursive(bool state); void setIsVerbose(bool state); void setNoBackup(bool state); - void setOptionFileName(const string& name); - void setOrigSuffix(const string& suffix); + void setOptionFileName(const std::string& name); + void setOrigSuffix(const std::string& suffix); void setPreserveDate(bool state); - void setProjectOptionFileName(const string& optfilepath); - void setStdPathIn(const string& path); - void setStdPathOut(const string& path); - void standardizePath(string& path, bool removeBeginningSeparator = false) const; - bool stringEndsWith(const string& str, const string& suffix) const; - void updateExcludeVector(const string& suffixParam); - vector getExcludeVector() const; - vector getExcludeHitsVector() const; - vector getFileNameVector() const; - vector getOptionsVector() const; - vector getProjectOptionsVector() const; - vector getFileOptionsVector() const; - vector getFileName() const; + void setProjectOptionFileName(const std::string& optfilepath); + void setStdPathIn(const std::string& path); + void setStdPathOut(const std::string& path); + void standardizePath(std::string& path, bool removeBeginningSeparator = false) const; + bool stringEndsWith(const std::string& str, const std::string& suffix) const; + void updateExcludeVector(const std::string& suffixParam); + std::vector getExcludeVector() const; + std::vector getExcludeHitsVector() const; + std::vector getFileNameVector() const; + std::vector getOptionsVector() const; + std::vector getProjectOptionsVector() const; + std::vector getFileOptionsVector() const; + std::vector getFileName() const; private: // functions - void correctMixedLineEnds(ostringstream& out); - void formatFile(const string& fileName_); - string getParentDirectory(const string& absPath) const; - string findProjectOptionFilePath(const string& fileName_) const; - string getCurrentDirectory(const string& fileName_) const; - void getFileNames(const string& directory, const vector& wildcards); - void getFilePaths(const string& filePath); - string getFullPathName(const string& relativePath) const; - string getHtmlInstallPrefix() const; - string getParam(const string& arg, const char* op); - bool isHomeOrInvalidAbsPath(const string& absPath) const; + void correctMixedLineEnds(std::ostringstream& out); + void formatFile(const std::string& fileName_); + std::string getParentDirectory(const std::string& absPath) const; + std::string findProjectOptionFilePath(const std::string& fileName_) const; + std::string getCurrentDirectory(const std::string& fileName_) const; + void getFileNames(const std::string& directory, const std::vector& wildcards); + void getFilePaths(const std::string& filePath); + std::string getFullPathName(const std::string& relativePath) const; + std::string getHtmlInstallPrefix() const; + std::string getParam(const std::string& arg, const char* op); + bool isHomeOrInvalidAbsPath(const std::string& absPath) const; void initializeOutputEOL(LineEndFormat lineEndFormat); - bool isOption(const string& arg, const char* op); - bool isOption(const string& arg, const char* a, const char* b); - bool isParamOption(const string& arg, const char* option); - bool isPathExclued(const string& subPath); + bool isOption(const std::string& arg, const char* op); + bool isOption(const std::string& arg, const char* a, const char* b); + bool isParamOption(const std::string& arg, const char* option); + bool isPathExclued(const std::string& subPath); void launchDefaultBrowser(const char* filePathIn = nullptr) const; void printHelp() const; - void printMsg(const char* msg, const string& data) const; + void printMsg(const char* msg, const std::string& data) const; void printSeparatingLine() const; void printVerboseHeader() const; void printVerboseStats(clock_t startTime) const; - FileEncoding readFile(const string& fileName_, stringstream& in) const; + FileEncoding readFile(const std::string& fileName_, std::stringstream& in) const; void removeFile(const char* fileName_, const char* errMsg) const; void renameFile(const char* oldFileName, const char* newFileName, const char* errMsg) const; - void setOutputEOL(LineEndFormat lineEndFormat, const string& currentEOL); + void setOutputEOL(LineEndFormat lineEndFormat, const std::string& currentEOL); void sleep(int seconds) const; int waitForRemove(const char* newFileName) const; int wildcmp(const char* wild, const char* data) const; - void writeFile(const string& fileName_, FileEncoding encoding, ostringstream& out) const; + void writeFile(const std::string& fileName_, FileEncoding encoding, std::ostringstream& out) const; #ifdef _WIN32 void displayLastError(); #endif