| 199 | //------------------------------------------------------------------------------ |
| 200 | |
| 201 | static int splitString(const std::string& input, unsigned int fieldWidth, bool stripWhitespace, |
| 202 | std::vector<std::string>& results, bool includeEmpties) |
| 203 | { |
| 204 | if (input.empty()) |
| 205 | { |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | unsigned int thisField = 0; |
| 210 | std::string thisFieldText; |
| 211 | std::string parsedField; |
| 212 | |
| 213 | while (thisField * fieldWidth < input.size()) |
| 214 | { |
| 215 | thisFieldText = input.substr(thisField * fieldWidth, fieldWidth); |
| 216 | |
| 217 | if (stripWhitespace) |
| 218 | { |
| 219 | unsigned int startIndex = 0, endIndex = static_cast<unsigned int>(thisFieldText.size()) - 1; |
| 220 | while (startIndex < thisFieldText.size() && |
| 221 | isspace(static_cast<int>(thisFieldText.at(startIndex)))) |
| 222 | { |
| 223 | ++startIndex; |
| 224 | } |
| 225 | while (endIndex > 0 && isspace(static_cast<int>(thisFieldText.at(endIndex)))) |
| 226 | { |
| 227 | --endIndex; |
| 228 | } |
| 229 | |
| 230 | if (startIndex <= endIndex) |
| 231 | { |
| 232 | parsedField = thisFieldText.substr(startIndex, (endIndex - startIndex) + 1); |
| 233 | } |
| 234 | else |
| 235 | { |
| 236 | parsedField = std::string(); |
| 237 | } |
| 238 | } |
| 239 | else |
| 240 | { |
| 241 | parsedField = thisFieldText; |
| 242 | } |
| 243 | ++thisField; |
| 244 | if (!parsedField.empty() || includeEmpties) |
| 245 | { |
| 246 | results.push_back(parsedField); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | return static_cast<int>(results.size()); |
| 251 | } |
| 252 | |
| 253 | //------------------------------------------------------------------------------ |
| 254 | |