Skip to content

Commit

Permalink
Address formatting and consistency feedback from amazon-ion#310
Browse files Browse the repository at this point in the history
  • Loading branch information
nirosys committed Jan 9, 2023
1 parent c9469ca commit 73added
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions ionc/ion_writer_text.c
Original file line number Diff line number Diff line change
Expand Up @@ -730,11 +730,13 @@ iERR _ion_writer_text_write_timestamp(ION_WRITER *pwriter, iTIMESTAMP value)
temp[output_length] = '\0';

// and our helper does the rest
if (json_downconvert)
if (json_downconvert) {
ION_PUT(pwriter->output, '"');
}
IONCHECK(_ion_writer_text_append_ascii_cstr(pwriter->output, temp));
if (json_downconvert)
if (json_downconvert) {
ION_PUT(pwriter->output, '"');
}
IONCHECK(_ion_writer_text_close_value(pwriter));
}

Expand All @@ -754,7 +756,7 @@ iERR _ion_writer_text_write_symbol_from_string(ION_WRITER *pwriter, ION_STRING *
SUCCEED();
}
else {
char quote = ION_TEXT_WRITER_IS_JSON() ? '"':'\'';
char quote = down_convert ? '"':'\'';
if (pstr->length < 0) FAILWITH(IERR_INVALID_ARG);
poutput = pwriter->output;

Expand Down Expand Up @@ -1208,14 +1210,14 @@ iERR _ion_writer_text_append_symbol_string(ION_WRITER *pwriter, ION_STRING *p_st
{
iENTER;
SIZE written;
char quote_char = (pwriter->options.json_downconvert) ? '"' : '\'';
char quote_char = ION_TEXT_WRITER_IS_JSON() ? '"' : '\'';
ION_STREAM *poutput = pwriter->output;

if (!poutput) FAILWITH(IERR_BAD_HANDLE);
if (!p_str) FAILWITH(IERR_INVALID_ARG);
if (p_str->length < 0) FAILWITH(IERR_INVALID_ARG);

if (_ion_symbol_needs_quotes(p_str, system_identifiers_need_quotes) || pwriter->options.json_downconvert) {
if (_ion_symbol_needs_quotes(p_str, system_identifiers_need_quotes) || ION_TEXT_WRITER_IS_JSON()) {
ION_PUT(poutput, quote_char);
if (pwriter->options.escape_all_non_ascii || ION_TEXT_WRITER_IS_JSON()) {
IONCHECK(_ion_writer_text_append_escaped_string(poutput, p_str, quote_char, ION_TEXT_WRITER_IS_JSON()));
Expand Down Expand Up @@ -1259,10 +1261,12 @@ iERR _ion_writer_text_append_escape_sequence_string(ION_STREAM *poutput, BOOL do

c = *cp;
if (c < 32 || c == '\\' || c == '"' || c == '\'') {
if (!down_convert)
image = _ion_writer_get_control_escape_string(c);
else
if (down_convert) {
image = _ion_writer_get_control_escape_string_json(c);
}
else {
image = _ion_writer_get_control_escape_string(c);
}
IONCHECK(_ion_writer_text_append_ascii_cstr(poutput, image));
cp++;
}
Expand Down

0 comments on commit 73added

Please sign in to comment.