parse.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * parse.cpp - time parsing
  3. * Copyright (C) 2017 caryoscelus
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <sstream>
  19. #include <core/parse.h>
  20. #include <core/time/parse.h>
  21. namespace rainynite::core {
  22. TimePeriod parse_time_period(string const& s) {
  23. std::istringstream stream(s);
  24. return parse_time_period(stream);
  25. }
  26. TimePeriod parse_time_period(std::istream& stream) {
  27. if (stream.get() != '[')
  28. throw ParseError("Unsupported time period format: expected '['");
  29. auto a = parse_time(stream);
  30. if (stream.get() != ',')
  31. throw ParseError("Unsupported time period format: expected ','");
  32. auto b = parse_time(stream);
  33. if (stream.get() != ')')
  34. throw ParseError("Unsupported time period format: expected ')'");
  35. return TimePeriod(a, b);
  36. }
  37. Time parse_time(string const& s) {
  38. std::istringstream stream(s);
  39. return parse_time(stream);
  40. }
  41. Time parse_time(std::istream& stream) {
  42. Time result;
  43. double frames;
  44. if (stream >> frames) {
  45. if (stream.get() == 'f' && stream.get() == '@') {
  46. int fps;
  47. if (stream >> fps) {
  48. result.set_fps(fps);
  49. result.set_frames(frames);
  50. return result;
  51. }
  52. }
  53. } else {
  54. //
  55. }
  56. throw ParseError("Unsupported time format");
  57. }
  58. } // namespace rainynite::core