Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions ext/json/ext/generator/generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ typedef struct JSON_Generator_StateStruct {
} JSON_Generator_State;

static VALUE mJSON, cState, cFragment, eGeneratorError, eNestingError, Encoding_UTF_8, default_sort_keys_proc,
rfc8785_number_formater_proc, rfc8785_sort_keys_proc;
rfc8785_number_formatter_proc, rfc8785_sort_keys_proc;

static ID i_to_s, i_to_json, i_new, i_encode;
static VALUE sym_indent, sym_space, sym_space_before, sym_object_nl, sym_array_nl, sym_max_nesting, sym_allow_nan, sym_allow_duplicate_key,
Expand Down Expand Up @@ -1171,7 +1171,7 @@ static void generate_json_float(FBuffer *buffer, struct generate_json_data *data
}

if (RB_UNLIKELY(data->state->rfc8785)) {
VALUE str = rb_proc_call_with_block(rfc8785_number_formater_proc, 1, &obj, Qnil);
VALUE str = rb_proc_call_with_block(rfc8785_number_formatter_proc, 1, &obj, Qnil);
Check_Type(str, T_STRING);
fbuffer_append_str(buffer, str);
return;
Expand Down Expand Up @@ -1754,15 +1754,15 @@ static VALUE cState_set_default_sort_keys_proc(VALUE self, VALUE proc)
return default_sort_keys_proc = proc;
}

static VALUE cState_set_rfc8785_number_formater_proc(VALUE self, VALUE proc)
static VALUE cState_set_rfc8785_number_formatter_proc(VALUE self, VALUE proc)
{
if (!rb_obj_is_proc(proc)) {
rb_raise(rb_eTypeError, "rfc8785_number_formater_proc must be a Proc");
rb_raise(rb_eTypeError, "rfc8785_number_formatter_proc must be a Proc");
}
if (rfc8785_number_formater_proc) {
rb_raise(rb_eArgError, "rfc8785_number_formater_proc can only be set once");
if (rfc8785_number_formatter_proc) {
rb_raise(rb_eArgError, "rfc8785_number_formatter_proc can only be set once");
}
return rfc8785_number_formater_proc = proc;
return rfc8785_number_formatter_proc = proc;
}

static VALUE cState_set_rfc8785_sort_keys_proc(VALUE self, VALUE proc)
Expand Down Expand Up @@ -2036,7 +2036,7 @@ void Init_generator(void)
VALUE mGenerator = rb_define_module_under(mExt, "Generator");

rb_global_variable(&default_sort_keys_proc);
rb_global_variable(&rfc8785_number_formater_proc);
rb_global_variable(&rfc8785_number_formatter_proc);
rb_global_variable(&rfc8785_sort_keys_proc);

rb_global_variable(&eGeneratorError);
Expand All @@ -2049,7 +2049,7 @@ void Init_generator(void)
rb_define_alloc_func(cState, cState_s_allocate);
rb_define_singleton_method(cState, "from_state", cState_from_state_s, 1);
rb_define_singleton_method(cState, "default_sort_keys_proc=", cState_set_default_sort_keys_proc, 1);
rb_define_singleton_method(cState, "rfc8785_number_formater_proc=", cState_set_rfc8785_number_formater_proc, 1);
rb_define_singleton_method(cState, "rfc8785_number_formatter_proc=", cState_set_rfc8785_number_formatter_proc, 1);
rb_define_singleton_method(cState, "rfc8785_sort_keys_proc=", cState_set_rfc8785_sort_keys_proc, 1);

rb_define_method(cState, "initialize", cState_initialize, -1);
Expand Down
2 changes: 1 addition & 1 deletion java/src/json/ext/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ static void generateFloat(ThreadContext context, Session session, RubyFloat obje
}

if (state.rfc8785()) {
RubyProc numberProc = (RubyProc)GeneratorState.rfc8785NumberFormaterProc;
RubyProc numberProc = (RubyProc)GeneratorState.rfc8785NumberFormatterProc;
RubyString numberString = (RubyString)Helpers.invoke(context, numberProc, "call", object);
buffer.write(numberString.toString().getBytes(UTF_8));
} else {
Expand Down
8 changes: 4 additions & 4 deletions java/src/json/ext/GeneratorState.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class GeneratorState extends RubyObject {
private boolean allowDuplicateKey = false;

private static IRubyObject defaultSortKeyProc;
public static IRubyObject rfc8785NumberFormaterProc;
public static IRubyObject rfc8785NumberFormatterProc;
public static IRubyObject rfc8785SortKeysProc;

/**
Expand Down Expand Up @@ -176,9 +176,9 @@ public static IRubyObject setDefaultSortKeyProc(IRubyObject klass, IRubyObject p
return proc;
}

@JRubyMethod(meta=true, name="rfc8785_number_formater_proc=")
public static IRubyObject setRfc8785NumberFormaterProc(IRubyObject klass, IRubyObject proc) {
rfc8785NumberFormaterProc = proc;
@JRubyMethod(meta=true, name="rfc8785_number_formatter_proc=")
public static IRubyObject setRfc8785NumberFormatterProc(IRubyObject klass, IRubyObject proc) {
rfc8785NumberFormatterProc = proc;
return proc;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/json/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def shareable_lambda(block) # :nodoc:
})

# Directly lifted from Gregg Kellogg's json-canonicalization
generator::State.rfc8785_number_formater_proc = shareable_lambda(->(num) {
generator::State.rfc8785_number_formatter_proc = shareable_lambda(->(num) {
if num.zero?
"0"
else
Expand Down
4 changes: 2 additions & 2 deletions lib/json/truffle_ruby/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def self.valid_utf8?(string)
# while generating a JSON text from a Ruby data structure.
class State
singleton_class.attr_accessor :default_sort_keys_proc # :nodoc:
singleton_class.attr_accessor :rfc8785_number_formater_proc # :nodoc:
singleton_class.attr_accessor :rfc8785_number_formatter_proc # :nodoc:
singleton_class.attr_accessor :rfc8785_sort_keys_proc # :nodoc:

def self.generate(obj, opts = nil, io = nil)
Expand Down Expand Up @@ -728,7 +728,7 @@ def to_json(state = nil, *args)
raise GeneratorError.new("#{self} not allowed in JSON", self)
end
elsif state.rfc8785?
State.rfc8785_number_formater_proc.call(self)
State.rfc8785_number_formatter_proc.call(self)
else
to_s
end
Expand Down
Loading