JSON-DWIW

 view release on metacpan or  search on metacpan

libjsonevt/jsonevt.c  view on Meta::CPAN

jsonevt_get_stats_longest_string_chars(jsonevt_ctx * ctx) {
    return ctx->longest_string_chars;
}

uint
jsonevt_get_stats_number_count(jsonevt_ctx * ctx) {
    return ctx->number_count;
}

uint
jsonevt_get_stats_bool_count(jsonevt_ctx * ctx) {
    return ctx->bool_count;
}

uint
jsonevt_get_stats_null_count(jsonevt_ctx * ctx) {
    return ctx->null_count;
}

uint
jsonevt_get_stats_hash_count(jsonevt_ctx * ctx) {
    return ctx->hash_count;
}

uint
jsonevt_get_stats_array_count(jsonevt_ctx * ctx) {
    return ctx->array_count;
}

uint
jsonevt_get_stats_deepest_level(jsonevt_ctx * ctx) {
    return ctx->deepest_level;
}

uint
jsonevt_get_stats_line_count(jsonevt_ctx * ctx) {
    return ctx->line;
}

uint
jsonevt_get_stats_byte_count(jsonevt_ctx * ctx) {
    return ctx->byte_count;
}

uint
jsonevt_get_stats_char_count(jsonevt_ctx * ctx) {
    return ctx->char_count;
}

/*
JSONEVT_INLINE_FUNC uint
jsonevt_get_line_num(jsonevt_ctx * ctx) {
    return CUR_LINE(ctx);
}
*/

static int
check_bom(json_context * ctx) {
    uint len = ctx->len;
    const char * buf = ctx->buf;
    char * error_fmt = "found BOM for unsupported %s encoding -- this parser requires UTF-8";

    /* check for UTF BOM signature */
    /* The signature, if present, is the U+FEFF character encoded the
       same as the rest of the buffer.
       See <http://www.unicode.org/unicode/faq/utf_bom.html#25>.
    */
    if (len >= 1) {
        switch (*buf) {

          case '\xEF': /* maybe utf-8 */
              if (len >= 3 && MEM_EQ(buf, "\xEF\xBB\xBF", 3)) {
                  /* UTF-8 signature */

                  /* Move our position past the signature and parse as
                     if there were no signature, but this explicitly
                     indicates the buffer is encoded in utf-8
                  */
                  NEXT_CHAR(ctx);
                  NEXT_CHAR(ctx);

              }
              return 1;
              break;


              /* The rest, if present are not supported by this
                 parser, so reject with an error.
              */

          case '\xFE': /* maybe utf-16 big-endian */
              if (len >= 2 && MEM_EQ(buf, "\xFE\xFF", 2)) {
                  /* UTF-16BE */
                  SET_ERROR(ctx, error_fmt, "UTF-16BE");
                  return 0;
              }
              break;

          case '\xFF': /* maybe utf-16 little-endian or utf-32 little-endian */
              if (len >= 2) {
                  if (MEM_EQ(buf, "\xFF\xFE", 2)) {
                      /* UTF-16LE */
                      SET_ERROR(ctx, error_fmt, "UTF-16LE");
                      return 0;
                  }
                  else if (len >= 4) {
                      if (MEM_EQ(buf, "\xFF\xFE\x00\x00", 4)) {
                          /* UTF-32LE */
                          SET_ERROR(ctx, error_fmt, "UTF-32LE");
                          return 0;
                      }
                  }
              }
              break;

          case '\x00': /* maybe utf-32 big-endian */
              if (len >= 4) {
                  if (MEM_EQ(buf, "\x00\x00\xFE\xFF", 4)) {
                      /* UTF-32BE */
                      SET_ERROR(ctx, error_fmt, "UTF-32B");
                      return 0;
                  }
              }



( run in 0.777 second using v1.01-cache-2.11-cpan-39bf76dae61 )