* 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. */
| 5175 | * @return is the previous word or an empty string if none found. |
| 5176 | */ |
| 5177 | string ASFormatter::getPreviousWord(const string &line, int currPos) const |
| 5178 | { |
| 5179 | // get the last legal word (may be a number) |
| 5180 | if (currPos == 0) |
| 5181 | return string(); |
| 5182 | |
| 5183 | size_t end = line.find_last_not_of(" \t", currPos - 1); |
| 5184 | if (end == string::npos || !isLegalNameChar(line[end])) |
| 5185 | return string(); |
| 5186 | |
| 5187 | int start; // start of the previous word |
| 5188 | for (start = end; start > -1; start--) |
| 5189 | { |
| 5190 | if (!isLegalNameChar(line[start]) || line[start] == '.') |
| 5191 | break; |
| 5192 | } |
| 5193 | start++; |
| 5194 | |
| 5195 | return (line.substr(start, end - start + 1)); |
| 5196 | } |
| 5197 | |
| 5198 | /** |
| 5199 | * check if a line break is needed when a closing bracket |
nothing calls this directly
no outgoing calls
no test coverage detected