| 15 | TLERegistry general_tle_registry; |
| 16 | |
| 17 | int parseTLEStream(std::istream &inputStream, TLERegistry &new_registry) |
| 18 | { |
| 19 | std::string this_line; |
| 20 | std::deque<std::string> tle_lines; |
| 21 | int total_lines = 0; |
| 22 | while (std::getline(inputStream, this_line)) |
| 23 | { |
| 24 | this_line.erase(0, this_line.find_first_not_of(" \t\n\r")); |
| 25 | this_line.erase(this_line.find_last_not_of(" \t\n\r") + 1); |
| 26 | if (this_line != "") |
| 27 | tle_lines.push_back(this_line); |
| 28 | |
| 29 | if (tle_lines.size() == 3) |
| 30 | { |
| 31 | bool checksum_good = true; |
| 32 | for (int i = 1; i < 3; i++) |
| 33 | { |
| 34 | if (!isdigit(tle_lines[i].back()) || !isdigit(tle_lines[i].front()) || tle_lines[i].front() - '0' != i) |
| 35 | { |
| 36 | checksum_good = false; |
| 37 | break; |
| 38 | } |
| 39 | |
| 40 | int checksum = tle_lines[i].back() - '0'; |
| 41 | int actualsum = 0; |
| 42 | for (int j = 0; j < (int)tle_lines[i].size() - 1; j++) |
| 43 | { |
| 44 | if (tle_lines[i][j] == '-') |
| 45 | actualsum++; |
| 46 | else if (isdigit(tle_lines[i][j])) |
| 47 | actualsum += tle_lines[i][j] - '0'; |
| 48 | } |
| 49 | |
| 50 | checksum_good = checksum == actualsum % 10; |
| 51 | if (!checksum_good) |
| 52 | break; |
| 53 | } |
| 54 | if (!checksum_good) |
| 55 | { |
| 56 | tle_lines.pop_front(); |
| 57 | continue; |
| 58 | } |
| 59 | |
| 60 | int norad; |
| 61 | try |
| 62 | { |
| 63 | std::string noradstr = tle_lines[2].substr(2, tle_lines[2].substr(2, tle_lines[2].size() - 1).find(' ')); |
| 64 | norad = std::stoi(noradstr); |
| 65 | } |
| 66 | catch (std::exception &) |
| 67 | { |
| 68 | tle_lines.pop_front(); |
| 69 | continue; |
| 70 | } |
| 71 | |
| 72 | new_registry.push_back({norad, tle_lines[0], tle_lines[1], tle_lines[2]}); |
| 73 | tle_lines.clear(); |
| 74 | total_lines++; |
no test coverage detected