Splits a line in parameter name and values.
| 46 | |
| 47 | // Splits a line in parameter name and values. |
| 48 | std::vector<std::string> |
| 49 | SplitLine(const std::string & fullLine, const std::string & line) |
| 50 | { |
| 51 | std::vector<std::string> splittedLine(1); |
| 52 | |
| 53 | /** Count the number of quotes in the line. If it is an odd value, the |
| 54 | * line contains an error; strings should start and end with a quote, so |
| 55 | * the total number of quotes is even. |
| 56 | */ |
| 57 | std::size_t numQuotes = itksys::SystemTools::CountChar(line.c_str(), '"'); |
| 58 | if (numQuotes % 2 == 1) |
| 59 | { |
| 60 | /** An invalid parameter line. */ |
| 61 | ThrowException(fullLine, "This line has an odd number of quotes (\")."); |
| 62 | } |
| 63 | |
| 64 | /** Loop over the line. */ |
| 65 | unsigned int index = 0; |
| 66 | numQuotes = 0; |
| 67 | for (const char currentChar : line) |
| 68 | { |
| 69 | if (currentChar == '"') |
| 70 | { |
| 71 | /** Start a new element. */ |
| 72 | splittedLine.push_back(""); |
| 73 | ++index; |
| 74 | ++numQuotes; |
| 75 | } |
| 76 | else if (currentChar == ' ') |
| 77 | { |
| 78 | /** Only start a new element if it is not a quote, otherwise just add |
| 79 | * the space to the string. |
| 80 | */ |
| 81 | if (numQuotes % 2 == 0) |
| 82 | { |
| 83 | splittedLine.push_back(""); |
| 84 | ++index; |
| 85 | } |
| 86 | else |
| 87 | { |
| 88 | splittedLine[index].push_back(currentChar); |
| 89 | } |
| 90 | } |
| 91 | else |
| 92 | { |
| 93 | /** Add this character to the element. */ |
| 94 | splittedLine[index].push_back(currentChar); |
| 95 | } |
| 96 | } |
| 97 | return splittedLine; |
| 98 | |
| 99 | } // end SplitLine() |
| 100 | |
| 101 | |
| 102 | // Fills the specified ParameterMap with valid entries. |
no test coverage detected