| 201 | } |
| 202 | |
| 203 | static int |
| 204 | cbor_content (xo_handle_t *xop, cbor_private_t *cbor, xo_buffer_t *xbp, |
| 205 | const char *value) |
| 206 | { |
| 207 | int rc = 0; |
| 208 | |
| 209 | unsigned offset = xo_buf_offset(xbp); |
| 210 | |
| 211 | if (value == NULL || *value == '\0' || xo_streq(value, "true")) |
| 212 | cbor_append(xop, cbor, &cbor->c_data, CBOR_TRUE, 0, NULL); |
| 213 | else if (xo_streq(value, "false")) |
| 214 | cbor_append(xop, cbor, &cbor->c_data, CBOR_FALSE, 0, NULL); |
| 215 | else { |
| 216 | int negative = 0; |
| 217 | if (*value == '-') { |
| 218 | value += 1; |
| 219 | negative = 1; |
| 220 | } |
| 221 | |
| 222 | char *ep; |
| 223 | unsigned long long ival; |
| 224 | ival = strtoull(value, &ep, 0); |
| 225 | if (ival == ULLONG_MAX) /* Sometimes a string is just a string */ |
| 226 | cbor_append(xop, cbor, xbp, CBOR_STRING, strlen(value), value); |
| 227 | else { |
| 228 | *xbp->xb_curp = negative ? CBOR_NEGATIVE : CBOR_UNSIGNED; |
| 229 | if (negative) |
| 230 | ival -= 1; /* Don't waste a negative zero */ |
| 231 | cbor_encode_uint(xbp, ival, negative ? CBOR_NLIMIT : CBOR_ULIMIT); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | if (xo_get_flags(xop) & XOF_PRETTY) |
| 236 | cbor_memdump(stdout, "content", xo_buf_data(xbp, offset), |
| 237 | xbp->xb_curp - xbp->xb_bufp - offset, "", |
| 238 | cbor->c_indent * 2); |
| 239 | |
| 240 | return rc; |
| 241 | } |
| 242 | |
| 243 | static int |
| 244 | cbor_handler (XO_ENCODER_HANDLER_ARGS) |
no test coverage detected