MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / tojson

Function tojson

subprojects/llama.cpp/common/jinja/value.cpp:156–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154}
155
156static value tojson(const func_args & args) {
157 args.ensure_count(1, 5);
158 value val_ascii = args.get_kwarg_or_pos("ensure_ascii", 1);
159 value val_indent = args.get_kwarg_or_pos("indent", 2);
160 value val_separators = args.get_kwarg_or_pos("separators", 3);
161 value val_sort = args.get_kwarg_or_pos("sort_keys", 4);
162 int indent = -1;
163 if (is_val<value_int>(val_indent)) {
164 indent = static_cast<int>(val_indent->as_int());
165 }
166 if (val_ascii->as_bool()) { // undefined == false
167 throw not_implemented_exception("tojson ensure_ascii=true not implemented");
168 }
169 if (val_sort->as_bool()) { // undefined == false
170 throw not_implemented_exception("tojson sort_keys=true not implemented");
171 }
172 auto separators = (is_val<value_array>(val_separators) ? val_separators : mk_val<value_array>())->as_array();
173 std::string item_sep = separators.size() > 0 ? separators[0]->as_string().str() : (indent < 0 ? ", " : ",");
174 std::string key_sep = separators.size() > 1 ? separators[1]->as_string().str() : ": ";
175 std::string json_str = value_to_json(args.get_pos(0), indent, item_sep, key_sep);
176 return mk_val<value_string>(json_str);
177}
178
179template<bool is_reject>
180static value selectattr(const func_args & args) {

Callers

nothing calls this directly

Calls 10

value_to_jsonFunction · 0.85
ensure_countMethod · 0.80
get_kwarg_or_posMethod · 0.80
get_posMethod · 0.80
sizeMethod · 0.65
as_intMethod · 0.45
as_boolMethod · 0.45
strMethod · 0.45
as_stringMethod · 0.45

Tested by

no test coverage detected