| 1976 | |
| 1977 | template <typename Source> |
| 1978 | static |
| 1979 | typename std::enable_if<ext_traits::is_string_view_of<Source,char_type>::value,basic_json>::type |
| 1980 | parse(const Source& source, |
| 1981 | const basic_json_decode_options<char_type>& options = basic_json_options<char_type>()) |
| 1982 | { |
| 1983 | json_decoder<basic_json> decoder; |
| 1984 | basic_json_parser<char_type> parser(options); |
| 1985 | |
| 1986 | auto r = unicode_traits::detect_encoding_from_bom(source.data(), source.size()); |
| 1987 | if (!(r.encoding == unicode_traits::encoding_kind::utf8 || r.encoding == unicode_traits::encoding_kind::undetected)) |
| 1988 | { |
| 1989 | JSONCONS_THROW(ser_error(json_errc::illegal_unicode_character,parser.line(),parser.column())); |
| 1990 | } |
| 1991 | std::size_t offset = (r.ptr - source.data()); |
| 1992 | parser.update(source.data()+offset,source.size()-offset); |
| 1993 | parser.parse_some(decoder); |
| 1994 | parser.finish_parse(decoder); |
| 1995 | parser.check_done(); |
| 1996 | if (JSONCONS_UNLIKELY(!decoder.is_valid())) |
| 1997 | { |
| 1998 | JSONCONS_THROW(ser_error(json_errc::source_error, "Failed to parse json string")); |
| 1999 | } |
| 2000 | return decoder.get_result(); |
| 2001 | } |
| 2002 | |
| 2003 | template <typename Source,typename TempAlloc > |
| 2004 | static |