Exemplo n.º 1
0
    void end_structure() 
    {
        JSONCONS_ASSERT(stack2_.size() > 0);
        if (stack_[stack2_.back()].value_.is_object())
        {
            size_t count = top_ - (stack2_.back() + 1);
            auto s = stack_.begin() + (stack2_.back()+1);
            auto send = s + count;
            stack_[stack2_.back()].value_.object_value().insert(
                std::make_move_iterator(s),
                std::make_move_iterator(send),
                move_pair);
            top_ -= count;
        }
        else
        {
            size_t count = top_ - (stack2_.back() + 1);
            stack_[stack2_.back()].value_.resize(count);

            auto s = stack_.begin() + (stack2_.back()+1);
            auto dend = stack_[stack2_.back()].value_.elements().end();
            for (auto it = stack_[stack2_.back()].value_.elements().begin();
                 it != dend; ++it, ++s)
            {
                *it = std::move(s->value_);
            }
            top_ -= count;
        }
    }
Exemplo n.º 2
0
typename std::enable_if<std::is_integral<T>::value && !std::is_signed<T>::value,to_integer_result<T>>::type
to_integer(const CharT* s, size_t length)
{
    static_assert(std::numeric_limits<T>::is_specialized, "Integer type not specialized");
    JSONCONS_ASSERT(length > 0);

    T n = 0;
    to_integer_errc ec{};

    const CharT* end = s + length; 

    static const T max_value = (std::numeric_limits<T>::max)();
    static const T max_value_div_10 = max_value / 10;
    for (; s < end; ++s)
    {
        T x = *s - '0';
        if (n > max_value_div_10)
        {
            ec = to_integer_errc::overflow;
            break;
        }
        n = n * 10;
        if (n > max_value - x)
        {
            ec = to_integer_errc::overflow;
            break;
        }

        n += x;
    }

    return to_integer_result<T>({ n,ec });
}
Exemplo n.º 3
0
typename std::enable_if<std::is_integral<T>::value && !std::is_signed<T>::value,to_integer_result<T>>::type
base16_to_integer(const CharT* s, size_t length)
{
    static_assert(std::numeric_limits<T>::is_specialized, "Integer type not specialized");
    JSONCONS_ASSERT(length > 0);

    T n = 0;
    to_integer_errc ec{};
    const CharT* end = s + length; 

    static const T max_value = (std::numeric_limits<T>::max)();
    static const T max_value_div_16 = max_value / 16;
    for (; s < end; ++s)
    {
        CharT c = *s;
        T x = *s;
        switch (c)
        {
            case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8': case '9':
                x = c - '0';
                break;
            case 'a':case 'b':case 'c':case 'd':case 'e':case 'f':
                x = c - ('a' - 10);
                break;
            case 'A':case 'B':case 'C':case 'D':case 'E':case 'F':
                x = c - ('A' - 10);
                break;
            default:
                throw std::runtime_error("Invalid hex digit");
        }
        if (n > max_value_div_16)
        {
            ec = to_integer_errc::overflow;
            break;
        }
        n = n * 16;
        if (n > max_value - x)
        {
            ec = to_integer_errc::overflow;
            break;
        }

        n += x;
    }

    return to_integer_result<T>({ n,ec });
}
Exemplo n.º 4
0
 const Char* as(const basic_json<Char, Alloc>& val) const
 {
     JSONCONS_ASSERT(val.is_string());
     return val.second.string_value_.c_str();
 }
Exemplo n.º 5
0
 typename jsoncons::null_type as(const basic_json<Char, Alloc>& val) const
 {
     JSONCONS_ASSERT(val.is_null());
     return jsoncons::null_type();
 }
Exemplo n.º 6
0
 void remove_range(size_t from_index, size_t to_index) 
 {
     JSONCONS_ASSERT(from_index <= to_index);
     JSONCONS_ASSERT(to_index <= elements_.size());
     elements_.erase(elements_.begin()+from_index,elements_.begin()+to_index);
 }
Exemplo n.º 7
0
 void remove_range(size_t from_index, size_t to_index) 
 {
     JSONCONS_ASSERT(from_index <= to_index);
     JSONCONS_ASSERT(to_index <= members_.size());
     members_.erase(members_.begin()+from_index,members_.begin()+to_index);
 }
Exemplo n.º 8
0
 void pop_initial()
 {
     JSONCONS_ASSERT(top_ == 1);
     result_.swap(stack_[0].value_);
     --top_;
 }
Exemplo n.º 9
0
 void pop_array()
 {
     stack2_.pop_back();
     JSONCONS_ASSERT(top_ > 0);
 }
Exemplo n.º 10
0
 void pop_object()
 {
     stack2_.pop_back();
     JSONCONS_ASSERT(top_ > 0);
 }
Exemplo n.º 11
0
 typename basic_json<Char, Alloc>::object as(const basic_json<Char, Alloc>& val) const
 {
     JSONCONS_ASSERT(val.is_object());
     return val.is_empty() ? typename basic_json<Char, Alloc>::object() : val.object_value();
 }