aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/yajl/yajl_parser.cpp
blob: fc605306825203e73861d8338d5340ef57e4c272 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "yajl_parser.h"

#include <errno.h>

#include <util/string/cast.h>

long long
yajl_parse_integer(const unsigned char *number, unsigned int length) {
    try {
        return FromString<long long>((const char*)number, length);
    } catch (const yexception& ex) {
        errno = ERANGE;
        return (*number == '-') ? LLONG_MIN : LLONG_MAX;
    }
}

unsigned long long
yajl_parse_unsigned_integer(const unsigned char *number, unsigned int length) {
    try {
        return FromString<unsigned long long>((const char*)number, length);
    } catch (const yexception& ex) {
        errno = ERANGE;
        return (*number == '-') ? 0ull : ULLONG_MAX;
    }
}

extern "C" void FormatDoubleYandex(char* buf, size_t len, double val) {
    buf[ToString(val, buf, len)] = 0;
}