Exemplo n.º 1
0
SERD_API
SerdStatus
serd_reader_start_stream(SerdReader*    me,
                         FILE*          file,
                         const uint8_t* name,
                         bool           bulk)
{
	const Cursor cur = { name, 1, 1 };
	me->fd        = file;
	me->read_head = 0;
	me->cur       = cur;
	me->from_file = true;
	me->eof       = false;
	me->paging    = bulk;

	if (bulk) {
		me->file_buf = (uint8_t*)serd_bufalloc(SERD_PAGE_SIZE);
		me->read_buf = me->file_buf;
		memset(me->file_buf, '\0', SERD_PAGE_SIZE);
		SerdStatus st = page(me);
		if (st) {
			serd_reader_end_stream(me);
			return st;
		}
		skip_bom(me);
	} else {
		me->read_buf  = &me->read_byte;
		me->read_byte = 0;  // Don't read to avoid potentially blocking
	}

	return SERD_SUCCESS;
}
Exemplo n.º 2
0
int jscoverage_bytes_to_characters(const char * encoding, const uint8_t * bytes, size_t num_bytes, jschar ** characters, size_t * num_characters) {
  assert(encoding != NULL);

  iconv_t state = iconv_open(UTF_16_INTERNAL, encoding);
  if (state == (iconv_t) -1) {
    return JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED;
  }

  ICONV_CONST char * input = (char *) bytes;
  size_t input_bytes_left = num_bytes;

  jschar * c = xnew(jschar, num_bytes);
  char * output = (char *) c;
  size_t output_bytes_left = sizeof(jschar) * num_bytes;

  size_t result = iconv(state, &input, &input_bytes_left, &output, &output_bytes_left);
  iconv_close(state);
  if (result == (size_t) -1) {
    free(c);
    return JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE;
  }

  assert(input_bytes_left == 0);

  size_t nc = ((jschar *) output) - c;

  skip_bom(&c, &nc);

  *characters = c;
  *num_characters = nc;
  return 0;
}
Exemplo n.º 3
0
int jscoverage_bytes_to_characters(const char * encoding, const uint8_t * bytes, size_t num_bytes, jschar ** characters, size_t * num_characters) {
  assert(encoding != NULL);

  if (num_bytes == 0) {
    *characters = xnew(jschar, 0);
    *num_characters = 0;
    return 0;
  }

  UINT code_page;
  if (find_code_page(encoding, &code_page) != 0) {
    return JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED;
  }

  if (num_bytes > INT_MAX) {
    fatal("overflow");
  }

  *characters = xnew(jschar, num_bytes);

  int result = MultiByteToWideChar(code_page, MB_ERR_INVALID_CHARS, bytes, num_bytes, *characters, num_bytes);
  if (result == 0) {
    free(*characters);
    return JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE;
  }

  *num_characters = result;
  skip_bom(characters, num_characters);
  return 0;
}
/* Parse an object - create a new root, and populate. */
cJSON *cJSON_Parse(const char *value)
{
	cJSON *c=cJSON_New_Item();
	ep=0;
	if (!c) return 0;       /* memory fail */

	if (!parse_value(c,skip(skip_bom(value)))) {cJSON_Delete(c);return 0;}
	return c;
}
Exemplo n.º 5
0
void sax_parser<_Handler,_Config>::header()
{
    // we don't handle multi byte encodings so we can just skip bom entry if exists.
    skip_bom();
    blank();
    if (!has_char() || cur_char() != '<')
        throw sax::malformed_xml_error("xml file must begin with '<'.");

    if (config_type::strict_xml_declaration)
    {
        if (next_char_checked() != '?')
            throw sax::malformed_xml_error("xml file must begin with '<?'.");

        declaration("xml");
    }
}
Exemplo n.º 6
0
SERD_API
SerdStatus
serd_reader_read_string(SerdReader* me, const uint8_t* utf8)
{
	const Cursor cur = { (const uint8_t*)"(string)", 1, 1 };

	me->read_buf  = utf8;
	me->read_head = 0;
	me->cur       = cur;
	me->from_file = false;
	me->paging    = false;
	me->eof       = false;

	skip_bom(me);
	const bool ret = read_turtleDoc(me);

	me->read_buf = NULL;
	return ret ? SERD_SUCCESS : SERD_ERR_UNKNOWN;
}
Exemplo n.º 7
0
int git_config_parse(
	git_config_parser *parser,
	git_config_parser_section_cb on_section,
	git_config_parser_variable_cb on_variable,
	git_config_parser_comment_cb on_comment,
	git_config_parser_eof_cb on_eof,
	void *data)
{
	git_parse_ctx *ctx;
	char *current_section = NULL, *var_name, *var_value;
	int result = 0;

	ctx = &parser->ctx;

	skip_bom(ctx);

	for (; ctx->remain_len > 0; git_parse_advance_line(ctx)) {
		const char *line_start = parser->ctx.line;
		size_t line_len = parser->ctx.line_len;
		char c;

		if (git_parse_peek(&c, ctx, GIT_PARSE_PEEK_SKIP_WHITESPACE) < 0 &&
		    git_parse_peek(&c, ctx, 0) < 0)
			continue;

		switch (c) {
		case '[': /* section header, new section begins */
			git__free(current_section);
			current_section = NULL;

			if ((result = parse_section_header(parser, &current_section)) == 0 && on_section) {
				result = on_section(parser, current_section, line_start, line_len, data);
			}
			break;

		case '\n': /* comment or whitespace-only */
		case ' ':
		case '\t':
		case ';':
		case '#':
			if (on_comment) {
				result = on_comment(parser, line_start, line_len, data);
			}
			break;

		default: /* assume variable declaration */
			if ((result = parse_variable(parser, &var_name, &var_value)) == 0 && on_variable) {
				result = on_variable(parser, current_section, var_name, var_value, line_start, line_len, data);
			}
			break;
		}

		if (result < 0)
			goto out;
	}

	if (on_eof)
		result = on_eof(parser, current_section, data);

out:
	git__free(current_section);
	return result;
}