| 154 | } |
| 155 | |
| 156 | static 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 | |
| 179 | template<bool is_reject> |
| 180 | static value selectattr(const func_args & args) { |
nothing calls this directly
no test coverage detected