| 61 | }; |
| 62 | |
| 63 | cm::optional<CostEntry> splitCostLine(cm::string_view line) |
| 64 | { |
| 65 | std::string part; |
| 66 | cm::string_view::size_type pos1 = line.size(); |
| 67 | cm::string_view::size_type pos2 = line.find_last_of(' ', pos1); |
| 68 | auto findNext = [line, &part, &pos1, &pos2]() -> bool { |
| 69 | if (pos2 != cm::string_view::npos) { |
| 70 | cm::string_view sub = line.substr(pos2 + 1, pos1 - pos2 - 1); |
| 71 | part.assign(sub.begin(), sub.end()); |
| 72 | pos1 = pos2; |
| 73 | if (pos1 > 0) { |
| 74 | pos2 = line.find_last_of(' ', pos1 - 1); |
| 75 | } |
| 76 | return true; |
| 77 | } |
| 78 | return false; |
| 79 | }; |
| 80 | |
| 81 | // parse the cost |
| 82 | if (!findNext()) { |
| 83 | return cm::nullopt; |
| 84 | } |
| 85 | float cost = static_cast<float>(atof(part.c_str())); |
| 86 | |
| 87 | // parse the previous runs |
| 88 | if (!findNext()) { |
| 89 | return cm::nullopt; |
| 90 | } |
| 91 | int prev = atoi(part.c_str()); |
| 92 | |
| 93 | // from start to the last found space is the name |
| 94 | return CostEntry{ line.substr(0, pos1), prev, cost }; |
| 95 | } |
| 96 | |
| 97 | } |
| 98 | |