Skip to content

Commit

Permalink
Rename JSON::print() to to_json()
Browse files Browse the repository at this point in the history
  • Loading branch information
madmiraal committed Dec 21, 2020
1 parent 1a04dcc commit 749e205
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 27 deletions.
6 changes: 3 additions & 3 deletions core/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2438,12 +2438,12 @@ Variant JSONParseResult::get_result() const {
}

void _JSON::_bind_methods() {
ClassDB::bind_method(D_METHOD("print", "value", "indent", "sort_keys"), &_JSON::print, DEFVAL(String()), DEFVAL(false));
ClassDB::bind_method(D_METHOD("to_json", "value", "indent", "sort_keys"), &_JSON::to_json, DEFVAL(String()), DEFVAL(false));
ClassDB::bind_method(D_METHOD("parse", "json"), &_JSON::parse);
}

String _JSON::print(const Variant &p_value, const String &p_indent, bool p_sort_keys) {
return JSON::print(p_value, p_indent, p_sort_keys);
String _JSON::to_json(const Variant &p_value, const String &p_indent, bool p_sort_keys) {
return JSON::to_json(p_value, p_indent, p_sort_keys);
}

Ref<JSONParseResult> _JSON::parse(const String &p_json) {
Expand Down
2 changes: 1 addition & 1 deletion core/core_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ class _JSON : public Object {
public:
static _JSON *get_singleton() { return singleton; }

String print(const Variant &p_value, const String &p_indent = "", bool p_sort_keys = false);
String to_json(const Variant &p_value, const String &p_indent = "", bool p_sort_keys = false);
Ref<JSONParseResult> parse(const String &p_json);

_JSON() { singleton = this; }
Expand Down
14 changes: 7 additions & 7 deletions core/io/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static String _make_indent(const String &p_indent, int p_size) {
return indent_text;
}

String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys) {
String JSON::_variant_to_json(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys) {
String colon = ":";
String end_statement = "";

Expand Down Expand Up @@ -87,7 +87,7 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_
s += ",";
s += end_statement;
}
s += _make_indent(p_indent, p_cur_indent + 1) + _print_var(a[i], p_indent, p_cur_indent + 1, p_sort_keys);
s += _make_indent(p_indent, p_cur_indent + 1) + _variant_to_json(a[i], p_indent, p_cur_indent + 1, p_sort_keys);
}
s += end_statement + _make_indent(p_indent, p_cur_indent) + "]";
return s;
Expand All @@ -108,9 +108,9 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_
s += ",";
s += end_statement;
}
s += _make_indent(p_indent, p_cur_indent + 1) + _print_var(String(E->get()), p_indent, p_cur_indent + 1, p_sort_keys);
s += _make_indent(p_indent, p_cur_indent + 1) + _variant_to_json(String(E->get()), p_indent, p_cur_indent + 1, p_sort_keys);
s += colon;
s += _print_var(d[E->get()], p_indent, p_cur_indent + 1, p_sort_keys);
s += _variant_to_json(d[E->get()], p_indent, p_cur_indent + 1, p_sort_keys);
}

s += end_statement + _make_indent(p_indent, p_cur_indent) + "}";
Expand All @@ -121,8 +121,8 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_
}
}

String JSON::print(const Variant &p_var, const String &p_indent, bool p_sort_keys) {
return _print_var(p_var, p_indent, 0, p_sort_keys);
String JSON::to_json(const Variant &p_var, const String &p_indent, bool p_sort_keys) {
return _variant_to_json(p_var, p_indent, 0, p_sort_keys);
}

Error JSON::_get_token(const char32_t *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str) {
Expand Down Expand Up @@ -470,7 +470,7 @@ Variant JSONParser::get_data() const {
}

Error JSONParser::decode_data(const Variant &p_data, const String &p_indent, bool p_sort_keys) {
string = JSON::print(p_data, p_indent, p_sort_keys);
string = JSON::to_json(p_data, p_indent, p_sort_keys);
data = p_data;
return OK;
}
Expand Down
4 changes: 2 additions & 2 deletions core/io/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ class JSON {

static const char *tk_name[TK_MAX];

static String _print_var(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys);
static String _variant_to_json(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys);

static Error _get_token(const char32_t *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str);
static Error _parse_value(Variant &value, Token &token, const char32_t *p_str, int &index, int p_len, int &line, String &r_err_str);
static Error _parse_array(Array &array, const char32_t *p_str, int &index, int p_len, int &line, String &r_err_str);
static Error _parse_object(Dictionary &object, const char32_t *p_str, int &index, int p_len, int &line, String &r_err_str);

public:
static String print(const Variant &p_var, const String &p_indent = "", bool p_sort_keys = true);
static String to_json(const Variant &p_var, const String &p_indent = "", bool p_sort_keys = true);
static Error parse(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line);
};

Expand Down
6 changes: 3 additions & 3 deletions doc/classes/JSON.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Parses a JSON-encoded string and returns a [JSONParseResult] containing the result.
</description>
</method>
<method name="print">
<method name="to_json">
<return type="String">
</return>
<argument index="0" name="value" type="Variant">
Expand All @@ -28,9 +28,9 @@
<argument index="2" name="sort_keys" type="bool" default="false">
</argument>
<description>
Converts a [Variant] var to JSON text and returns the result. Useful for serializing data to store or send over the network.
Converts the [Variant] value to JSON text and returns the result as a [String]. Useful for serializing data to store or send over the network.
[b]Note:[/b] The JSON specification does not define integer or float types, but only a [i]number[/i] type. Therefore, converting a Variant to JSON text will convert all numerical values to [float] types.
Use [code]indent[/code] parameter to pretty print the output.
Use the [code]indent[/code] parameter to beautify the output.
[b]Example output:[/b]
[codeblock]
## JSON.print(my_dictionary)
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_feature_profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Error EditorFeatureProfile::save_to_file(const String &p_path) {
FileAccessRef f = FileAccess::open(p_path, FileAccess::WRITE);
ERR_FAIL_COND_V_MSG(!f, ERR_CANT_CREATE, "Cannot create file '" + p_path + "'.");

String text = JSON::print(json, "\t");
String text = JSON::to_json(json, "\t");
f->store_string(text);
f->close();
return OK;
Expand Down
2 changes: 1 addition & 1 deletion modules/gdnative/gdnative/dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ godot_string GDAPI godot_dictionary_to_json(const godot_dictionary *p_self) {
godot_string raw_dest;
String *dest = (String *)&raw_dest;
const Dictionary *self = (const Dictionary *)p_self;
memnew_placement(dest, String(JSON::print(Variant(*self))));
memnew_placement(dest, String(JSON::to_json(Variant(*self))));
return raw_dest;
}

Expand Down
8 changes: 4 additions & 4 deletions modules/gdscript/language_server/gdscript_extend_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p
symbol.detail += ": " + m.get_datatype().to_string();
}
if (m.variable->initializer != nullptr && m.variable->initializer->is_constant) {
symbol.detail += " = " + JSON::print(m.variable->initializer->reduced_value);
symbol.detail += " = " + JSON::to_json(m.variable->initializer->reduced_value);
}

symbol.documentation = parse_documentation(LINE_NUMBER_TO_INDEX(m.variable->start_line));
Expand Down Expand Up @@ -223,10 +223,10 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p
}
}
} else {
value_text = JSON::print(default_value);
value_text = JSON::to_json(default_value);
}
} else {
value_text = JSON::print(default_value);
value_text = JSON::to_json(default_value);
}
if (!value_text.empty()) {
symbol.detail += " = " + value_text;
Expand Down Expand Up @@ -352,7 +352,7 @@ void ExtendGDScriptParser::parse_function_symbol(const GDScriptParser::FunctionN
parameters += ": " + parameter->get_datatype().to_string();
}
if (parameter->default_value != nullptr) {
String value = JSON::print(parameter->default_value->reduced_value);
String value = JSON::to_json(parameter->default_value->reduced_value);
parameters += " = " + value;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ Dictionary GDScriptLanguageProtocol::initialize(const Dictionary &p_params) {
vformat("GDScriptLanguageProtocol: Can't initialize invalid peer '%d'.", latest_client_id));
Ref<LSPeer> peer = clients.get(latest_client_id);
if (peer != nullptr) {
String msg = JSON::print(request);
String msg = JSON::to_json(request);
msg = format_output(msg);
(*peer)->res_queue.push_back(msg.utf8());
}
Expand Down Expand Up @@ -281,7 +281,7 @@ void GDScriptLanguageProtocol::notify_client(const String &p_method, const Varia
ERR_FAIL_COND(peer == nullptr);

Dictionary message = make_notification(p_method, p_params);
String msg = JSON::print(message);
String msg = JSON::to_json(message);
msg = format_output(msg);
peer->res_queue.push_back(msg.utf8());
}
Expand Down
2 changes: 1 addition & 1 deletion modules/jsonrpc/jsonrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ String JSONRPC::process_string(const String &p_input) {
if (ret.get_type() == Variant::NIL) {
return "";
}
return JSON::print(ret);
return JSON::to_json(ret);
}

void JSONRPC::set_scope(const String &p_scope, Object *p_obj) {
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/class_db_api_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ void class_db_api_to_json(const String &p_output_file, ClassDB::APIType p_api) {

FileAccessRef f = FileAccess::open(p_output_file, FileAccess::WRITE);
ERR_FAIL_COND_MSG(!f, "Cannot open file '" + p_output_file + "'.");
f->store_string(JSON::print(classes_dict, /*indent: */ "\t"));
f->store_string(JSON::to_json(classes_dict, /*indent: */ "\t"));
f->close();

print_line(String() + "ClassDB API JSON written to: " + ProjectSettings::get_singleton()->globalize_path(p_output_file));
Expand Down
2 changes: 1 addition & 1 deletion platform/javascript/export/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ void EditorExportPlatformJavaScript::_fix_html(Vector<uint8_t> &p_html, const Re
Vector<String> flags;
String flags_json;
gen_export_flags(flags, p_flags);
flags_json = JSON::print(flags);
flags_json = JSON::to_json(flags);
String libs;
for (int i = 0; i < p_shared_objects.size(); i++) {
libs += "\"" + p_shared_objects[i].path.get_file() + "\",";
Expand Down

0 comments on commit 749e205

Please sign in to comment.