helper function for parsing decimal data (for std::tm)
| 17 | |
| 18 | // helper function for parsing decimal data (for std::tm) |
| 19 | int parse10(char const * & p1, char * & p2) |
| 20 | { |
| 21 | long v = std::strtol(p1, &p2, 10); |
| 22 | if (p2 != p1) |
| 23 | { |
| 24 | if (v < 0) |
| 25 | throw soci::soci_error("Negative date/time field component."); |
| 26 | |
| 27 | if (v > INT_MAX) |
| 28 | throw soci::soci_error("Out of range date/time field component."); |
| 29 | |
| 30 | p1 = p2 + 1; |
| 31 | |
| 32 | // Cast is safe due to check above. |
| 33 | return static_cast<int>(v); |
| 34 | } |
| 35 | else |
| 36 | { |
| 37 | throw soci::soci_error("Cannot parse date/time field component."); |
| 38 | |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | } // namespace anonymous |
| 43 |