Exemplo n.º 1
0
yajl_gen_status
yajl_gen_string(yajl_gen g, const unsigned char * str,
                unsigned int len)
{
    ENSURE_VALID_STATE; INSERT_SEP; INSERT_WHITESPACE;
    g->print(g->ctx, "\"", 1);
    yajl_string_encode2(g->print, g->ctx, str, len, g->htmlSafe);
    g->print(g->ctx, "\"", 1);
    APPENDED_ATOM;
    FINAL_NEWLINE;
    return yajl_gen_status_ok;
}
Exemplo n.º 2
0
/* Json encode the string binary into the ctx.bin,
  with surrounding quotes and all */
static int
encode_string(void* vctx, ERL_NIF_TERM binary)
{
    encode_ctx* ctx = (encode_ctx*)vctx;
    ErlNifBinary bin;

    if(!enif_inspect_binary(ctx->env, binary, &bin)) {
        return NOMEM;
    }
    fill_buffer(ctx, "\"", 1);
    if (ctx->error) {
        return ctx->error;
    }
    yajl_string_encode2(fill_buffer, ctx, bin.data, bin.size);
    fill_buffer(ctx, "\"", 1);

    return ctx->error;
}