MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / try_as_string

Function try_as_string

include/jsoncons/basic_json.hpp:3852–3895  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3850
3851 template <typename T,typename Alloc, typename TempAlloc>
3852 typename std::enable_if<ext_traits::is_string<T>::value &&
3853 std::is_same<char_type,typename T::value_type>::value,conversion_result<T>>::type
3854 try_as_string(const allocator_set<Alloc,TempAlloc>& aset) const
3855 {
3856 using value_type = T;
3857 using result_type = conversion_result<value_type>;
3858
3859 switch (storage_kind())
3860 {
3861 case json_storage_kind::short_str:
3862 {
3863 auto& stor = cast<short_string_storage>();
3864 return result_type(jsoncons::make_obj_using_allocator<value_type>(aset.get_allocator(), stor.data(), stor.length()));
3865 }
3866 case json_storage_kind::long_str:
3867 {
3868 auto& stor = cast<long_string_storage>();
3869 return result_type(jsoncons::make_obj_using_allocator<value_type>(aset.get_allocator(), stor.data(), stor.length()));
3870 }
3871 case json_storage_kind::byte_str:
3872 {
3873 auto& stor = cast<byte_string_storage>();
3874 value_type s = jsoncons::make_obj_using_allocator<value_type>(aset.get_allocator());
3875 bytes_to_string(stor.data(), stor.data()+stor.length(), tag(), s);
3876 return result_type(std::move(s));
3877 }
3878 case json_storage_kind::const_json_ref:
3879 return cast<const_json_ref_storage>().value().template try_as_string<T>(aset);
3880 case json_storage_kind::json_ref:
3881 return cast<json_ref_storage>().value().template try_as_string<T>(aset);
3882 default:
3883 {
3884 value_type s = jsoncons::make_obj_using_allocator<value_type>(aset.get_allocator());
3885 basic_compact_json_encoder<char_type,jsoncons::string_sink<value_type>,TempAlloc> encoder(s, aset.get_temp_allocator());
3886 std::error_code ec;
3887 dump(encoder, ec);
3888 if (JSONCONS_UNLIKELY(ec))
3889 {
3890 return result_type(jsoncons::unexpect, ec);
3891 }
3892 return result_type(std::move(s));
3893 }
3894 }
3895 }
3896
3897 template <typename CharsAlloc>
3898 std::basic_string<char_type,char_traits_type,CharsAlloc> as_string(const CharsAlloc& alloc) const

Callers

nothing calls this directly

Calls 9

storage_kindFunction · 0.85
bytes_to_stringFunction · 0.85
tagFunction · 0.85
dumpFunction · 0.85
get_temp_allocatorMethod · 0.80
get_allocatorMethod · 0.45
dataMethod · 0.45
lengthMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected