jsonException.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * jsonException.cpp for jsonstroller
  3. *
  4. * Author: isundil <isundill@gmail.com>
  5. **/
  6. #include <string>
  7. #include "jsonException.hh"
  8. JsonException::JsonException(const std::string &wh, unsigned long long pos, LinearHistory &h): offset(pos), history(h), _what(wh)
  9. { }
  10. JsonHexvalueException::JsonHexvalueException(const std::string &what, unsigned long long o, LinearHistory &h): JsonFormatException(o, h)
  11. {
  12. _what = what;
  13. }
  14. JsonHexvalueException::JsonHexvalueException(char c, unsigned long long o, LinearHistory &h): JsonFormatException(o, h)
  15. {
  16. _what = JsonHexvalueException::msg(c);
  17. }
  18. JsonFormatException::JsonFormatException(unsigned long long pos, LinearHistory &h):
  19. JsonException("invalid value", pos, h)
  20. { }
  21. JsonNotJsonException::JsonNotJsonException(unsigned long long pos, LinearHistory &h):
  22. JsonException("expected json entry, got token", pos, h)
  23. { }
  24. JsonEscapedException::JsonEscapedException(char ch, unsigned long long pos, LinearHistory &h):
  25. JsonException("unexpected escaped char " +c, pos, h), c(ch)
  26. { }
  27. JsonUnexpectedException::JsonUnexpectedException(const char expected, unsigned long long offset, LinearHistory &h): JsonException("expected " +expected, offset, h)
  28. { }
  29. std::string JsonHexvalueException::msg(char c)
  30. {
  31. std::string what = "invalid hex value '";
  32. what += c + '\'';
  33. return what;
  34. }
  35. unsigned int JsonException::currentLine() const
  36. { return history.currentLine(); }
  37. unsigned int JsonException::currentCol() const
  38. { return history.totalSize(); }
  39. std::string JsonException::getHistory() const
  40. { return history.toString(); }
  41. const char *JsonException::what() const noexcept
  42. { return _what.c_str(); }