yajl_parser.cpp 782 B

1234567891011121314151617181920212223242526272829
  1. #include "yajl_parser.h"
  2. #include <errno.h>
  3. #include <util/string/cast.h>
  4. long long
  5. yajl_parse_integer(const unsigned char *number, unsigned int length) {
  6. try {
  7. return FromString<long long>((const char*)number, length);
  8. } catch (const yexception& ex) {
  9. errno = ERANGE;
  10. return (*number == '-') ? LLONG_MIN : LLONG_MAX;
  11. }
  12. }
  13. unsigned long long
  14. yajl_parse_unsigned_integer(const unsigned char *number, unsigned int length) {
  15. try {
  16. return FromString<unsigned long long>((const char*)number, length);
  17. } catch (const yexception& ex) {
  18. errno = ERANGE;
  19. return (*number == '-') ? 0ull : ULLONG_MAX;
  20. }
  21. }
  22. extern "C" void FormatDoubleYandex(char* buf, size_t len, double val) {
  23. buf[ToString(val, buf, len)] = 0;
  24. }