* adjust comment position because of adding or deleting spaces * the spaces are added or deleted to formattedLine * spacePadNum contains the adjustment */
| 3107 | * spacePadNum contains the adjustment |
| 3108 | */ |
| 3109 | void ASFormatter::adjustComments(void) |
| 3110 | { |
| 3111 | assert(spacePadNum != 0); |
| 3112 | assert(currentLine.compare(charNum, 2, "//") == 0 |
| 3113 | || currentLine.compare(charNum, 2, "/*") == 0); |
| 3114 | |
| 3115 | |
| 3116 | // block comment must be closed on this line with nothing after it |
| 3117 | if (currentLine.compare(charNum, 2, "/*") == 0) |
| 3118 | { |
| 3119 | size_t endNum = currentLine.find("*/", charNum + 2); |
| 3120 | if (endNum == string::npos) |
| 3121 | return; |
| 3122 | if (currentLine.find_first_not_of(" \t", endNum + 2) != string::npos) |
| 3123 | return; |
| 3124 | } |
| 3125 | |
| 3126 | size_t len = formattedLine.length(); |
| 3127 | // don't adjust a tab |
| 3128 | if (formattedLine[len - 1] == '\t') |
| 3129 | return; |
| 3130 | // if spaces were removed, need to add spaces before the comment |
| 3131 | if (spacePadNum < 0) |
| 3132 | { |
| 3133 | int adjust = -spacePadNum; // make the number positive |
| 3134 | formattedLine.append(adjust, ' '); |
| 3135 | } |
| 3136 | // if spaces were added, need to delete extra spaces before the comment |
| 3137 | // if cannot be done put the comment one space after the last text |
| 3138 | else if (spacePadNum > 0) |
| 3139 | { |
| 3140 | int adjust = spacePadNum; |
| 3141 | size_t lastText = formattedLine.find_last_not_of(' '); |
| 3142 | if (lastText != string::npos |
| 3143 | && lastText < len - adjust - 1) |
| 3144 | formattedLine.resize(len - adjust); |
| 3145 | else if (len > lastText + 2) |
| 3146 | formattedLine.resize(lastText + 2); |
| 3147 | else if (len < lastText + 2) |
| 3148 | formattedLine.append(len - lastText, ' '); |
| 3149 | } |
| 3150 | } |
| 3151 | |
| 3152 | /** |
| 3153 | * append the current bracket inside the end of line comments |
nothing calls this directly
no outgoing calls
no test coverage detected