Function parse

Synopsis

#include <include/sajson.h>

template <typename AllocationStrategy, typename StringType>
document parse(const AllocationStrategy &strategy, const StringType &string)

Description

Parses a string of JSON bytes into a document, given an allocation strategy instance. Any kind of string type is valid as long as a mutable_string_view can be constructed from it.

Valid allocation strategies are single_allocation, dynamic_allocation, and bounded_allocation.

A document is returned whether or not the parse succeeds: success state is available by calling document::is_valid().

Mentioned in

Source

Lines 2586-2599 in include/sajson.h.

template <typename AllocationStrategy, typename StringType>
document parse(const AllocationStrategy& strategy, const StringType& string) {
    mutable_string_view input(string);

    bool success;
    auto allocator = strategy.make_allocator(input.length(), &success);
    if (!success) {
        return document(input, 1, 1, ERROR_OUT_OF_MEMORY, 0);
    }

    return parser<typename AllocationStrategy::allocator>(
               input, std::move(allocator))
        .get_document();
}





Add Discussion as Guest

Log in