source: libyaml/trunk/src/reader.c @ 179

Revision 179, 1.2 KB checked in by xi, 9 years ago (diff)

Implementing Reader: first tries.

RevLine 
[179]1
2#define RAW_BUFFER_SIZE 16384
3#define BUFFER_SIZE (RAW_BUFFER_SIZE*2) /* Should be enough for decoding
4                                           the whole raw buffer. */
5
6/*
7 * Ensure that the buffer contains at least length characters.
8 * Return 1 on success, 0 on failure.
9 */
10
11int
12yaml_parser_update_reader(yaml_parser_t *parser, size_t length)
13{
14    /* If the EOF flag is set, do nothing. */
15
16    if (parser->eof)
17        return 1;
18
19    /* First, let us check that the buffers are allocated. */
20
21    if (!parser->buffer) {
22        parser->buffer = yaml_malloc(BUFFER_SIZE);
23        if (!parser->buffer) {
24            parser->error = YAML_MEMORY_ERROR;
25            return 0;
26        }
27        parser->buffer_size = BUFFER_SIZE;
28        parser->buffer_pointer = parser->buffer;
29        parser->buffer_length = 0;
30    }
31
32    if (!parser->raw_buffer) {
33        parser->raw_buffer = yaml_malloc(RAW_BUFFER_SIZE);
34        if (!parser->raw_buffer) {
35            parser->error = YAML_MEMORY_ERROR;
36            return 0;
37        }
38        parser->raw_buffer_size = RAW_BUFFER_SIZE;
39    }
40
41    /* Next, determine the input encoding. */
42
43    if (!parser->encoding) {
44        if (!yaml_parser_determine_encoding(parser))
45            return 0;
46    }
47
48    /* more... */
49
50}
51
52
53
Note: See TracBrowser for help on using the repository browser.