/////////////////////////////////////////////////////////////////////////// Accept a list of projects, and return an indented list that reflects the hierarchy. Input - "one" "one.two" "one.two.three" "one.four" "two" Output - "one" " one.two" " one.two.three" " one.four" "two" There are two optional arguments, 'whitespace', and 'delimiter', - whitespace is the string used to build the pre
| 183 | // - defaults to the period, '.' |
| 184 | // |
| 185 | const std::string indentProject(const std::string& project, |
| 186 | const std::string& whitespace /* = " " */, |
| 187 | char delimiter /* = '.' */) { |
| 188 | // Count the delimiters in *i. |
| 189 | std::string prefix = ""; |
| 190 | std::string::size_type pos = 0; |
| 191 | std::string::size_type lastpos = 0; |
| 192 | while ((pos = project.find(delimiter, pos + 1)) != std::string::npos) { |
| 193 | if (pos != project.size() - 1) { |
| 194 | prefix += whitespace; |
| 195 | lastpos = pos; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | std::string child = ""; |
| 200 | if (lastpos == 0) |
| 201 | child = project; |
| 202 | else |
| 203 | child = project.substr(lastpos + 1); |
| 204 | |
| 205 | return prefix + child; |
| 206 | } |
| 207 | |
| 208 | //////////////////////////////////////////////////////////////////////////////// |
| 209 | const std::vector<std::string> extractParents(const std::string& project, |