void gumbo_string_copy(struct GumboInternalParser* parser, GumboStringPiece* dest, const GumboStringPiece* source) { dest->length = source->length; char* buffer = gumbo_parser_allocate(parser, source->length); memcpy(buffer, source->data, source->length); dest->data = buffer; }
GumboError* gumbo_add_error(GumboParser* parser) { int max_errors = parser->_options->max_errors; if (max_errors >= 0 && parser->_output->errors.length >= (unsigned int) max_errors) { return NULL; } GumboError* error = gumbo_parser_allocate(parser, sizeof(GumboError)); gumbo_vector_add(parser, error, &parser->_output->errors); return error; }
static void enlarge_vector_if_full( struct GumboInternalParser* parser, GumboVector* vector) { if (vector->length >= vector->capacity) { if (vector->capacity) { size_t old_num_bytes = sizeof(void*) * vector->capacity; vector->capacity *= 2; size_t num_bytes = sizeof(void*) * vector->capacity; void** temp = (void**)gumbo_parser_allocate(parser, num_bytes); memcpy(temp, vector->data, old_num_bytes); gumbo_parser_deallocate(parser, vector->data); vector->data = temp; } else { // 0-capacity vector; no previous array to deallocate. vector->capacity = 2; vector->data = (void**)gumbo_parser_allocate( parser, sizeof(void*) * vector->capacity); } } }
void gumbo_vector_init( struct GumboInternalParser* parser, size_t initial_capacity, GumboVector* vector) { vector->length = 0; vector->capacity = initial_capacity; if (initial_capacity > 0) { vector->data = (void**)gumbo_parser_allocate( parser, sizeof(void*) * initial_capacity); } else { vector->data = NULL; } }
char* gumbo_copy_stringz(GumboParser* parser, const char* str) { char* buffer = gumbo_parser_allocate(parser, strlen(str) + 1); strcpy(buffer, str); return buffer; }