Gumbo 0.14.0
HTML parser library implemented in C99
Loading...
Searching...
No Matches
gumbo.h
Go to the documentation of this file.
1// Copyright 2010 Google Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Author: jdtang@google.com (Jonathan Tang)
16//
17// We use Gumbo as a prefix for types, gumbo_ as a prefix for functions, and
18// GUMBO_ as a prefix for enum constants (static constants get the Google-style
19// kGumbo prefix).
20
41
42#ifndef GUMBO_GUMBO_H_
43#define GUMBO_GUMBO_H_
44
45#ifdef _MSC_VER
46#define _CRT_SECURE_NO_WARNINGS
47#define fileno _fileno
48#endif
49
50#include <stdbool.h>
51#include <stddef.h>
52
53#ifdef __cplusplus
54extern "C" {
55#endif
56
67typedef struct {
68 unsigned int line;
69 unsigned int column;
70 unsigned int offset;
72
78
88typedef struct {
90 const char* data;
91
93 size_t length;
95
98
104 const GumboStringPiece* str1, const GumboStringPiece* str2);
105
111 const GumboStringPiece* str1, const GumboStringPiece* str2);
112
122typedef struct {
126 void** data;
127
129 unsigned int length;
130
132 unsigned int capacity;
134
136extern const GumboVector kGumboEmptyVector;
137
142int gumbo_vector_index_of(GumboVector* vector, const void* element);
143
156typedef enum {
157// Load all the tags from an external source, generated from tag.in.
158#include "tag_enum.h"
159 // Used for all tags that don't have special handling in HTML. Add new tags
160 // to the end of tag.in so as to preserve backwards-compatibility.
161 GUMBO_TAG_UNKNOWN,
162 // A marker value to indicate the end of the enum, for iterating over it.
163 // Also used as the terminator for varargs functions that take tags.
164 GUMBO_TAG_LAST,
165} GumboTag;
166
174
181
193
207
212GumboTag gumbo_tag_enum(const char* tagname);
213GumboTag gumbo_tagn_enum(const char* tagname, unsigned int length);
214
220typedef enum {
221 GUMBO_ATTR_NAMESPACE_NONE,
222 GUMBO_ATTR_NAMESPACE_XLINK,
223 GUMBO_ATTR_NAMESPACE_XML,
224 GUMBO_ATTR_NAMESPACE_XMLNS,
226
287
293GumboAttribute* gumbo_get_attribute(const GumboVector* attrs, const char* name);
294
320
325typedef struct GumboInternalNode GumboNode;
326
330typedef enum {
331 GUMBO_DOCTYPE_NO_QUIRKS,
332 GUMBO_DOCTYPE_QUIRKS,
333 GUMBO_DOCTYPE_LIMITED_QUIRKS
335
343typedef enum {
344 GUMBO_NAMESPACE_HTML,
345 GUMBO_NAMESPACE_SVG,
346 GUMBO_NAMESPACE_MATHML
348
429
433typedef struct {
439 GumboVector /* GumboNode* */ children;
440
441 // True if there was an explicit doctype token as opposed to it being omitted.
442 bool has_doctype;
443
444 // Fields from the doctype token, copied verbatim.
445 const char* name;
446 const char* public_identifier;
447 const char* system_identifier;
448
455
479
524
532
534 GumboNode* parent;
535
538
545
547 union {
548 GumboDocument document; // For GUMBO_NODE_DOCUMENT.
549 GumboElement element; // For GUMBO_NODE_ELEMENT.
550 GumboText text; // For everything else.
551 } v;
552};
553
560// TODO(jdtang): Add checks throughout the codebase for out-of-memory condition.
561typedef void* (*GumboAllocatorFunction)(void* userdata, size_t size);
562
567typedef void (*GumboDeallocatorFunction)(void* userdata, void* ptr);
568
632
635
637typedef struct GumboInternalOutput {
642 GumboNode* document;
643
648 GumboNode* root;
649
657 GumboVector /* GumboError */ errors;
659
667GumboOutput* gumbo_parse(const char* buffer);
668
674 const GumboOptions* options, const char* buffer, size_t buffer_length);
675
677void gumbo_destroy_output(const GumboOptions* options, GumboOutput* output);
678
679#ifdef __cplusplus
680}
681#endif
682
683#endif // GUMBO_GUMBO_H_
GumboAttributeNamespaceEnum
Definition gumbo.h:220
void(* GumboDeallocatorFunction)(void *userdata, void *ptr)
Definition gumbo.h:567
GumboOutput * gumbo_parse(const char *buffer)
int gumbo_vector_index_of(GumboVector *vector, const void *element)
const char * gumbo_normalize_svg_tagname(const GumboStringPiece *tagname)
GumboNamespaceEnum
Definition gumbo.h:343
GumboTag
Definition gumbo.h:156
void *(* GumboAllocatorFunction)(void *userdata, size_t size)
Definition gumbo.h:561
bool gumbo_string_equals_ignore_case(const GumboStringPiece *str1, const GumboStringPiece *str2)
GumboNodeType
Definition gumbo.h:299
@ GUMBO_NODE_CDATA
Definition gumbo.h:307
@ GUMBO_NODE_TEXT
Definition gumbo.h:305
@ GUMBO_NODE_DOCUMENT
Definition gumbo.h:301
@ GUMBO_NODE_WHITESPACE
Definition gumbo.h:311
@ GUMBO_NODE_COMMENT
Definition gumbo.h:309
@ GUMBO_NODE_TEMPLATE
Definition gumbo.h:317
@ GUMBO_NODE_ELEMENT
Definition gumbo.h:303
GumboParseFlags
Definition gumbo.h:357
@ GUMBO_INSERTION_ADOPTION_AGENCY_CLONED
Definition gumbo.h:418
@ GUMBO_INSERTION_NORMAL
Definition gumbo.h:362
@ GUMBO_INSERTION_CONVERTED_FROM_END_TAG
Definition gumbo.h:399
@ GUMBO_INSERTION_IMPLICIT_END_TAG
Definition gumbo.h:383
@ GUMBO_INSERTION_FOSTER_PARENTED
Definition gumbo.h:427
@ GUMBO_INSERTION_RECONSTRUCTED_FORMATTING_ELEMENT
Definition gumbo.h:415
@ GUMBO_INSERTION_FROM_ISINDEX
Definition gumbo.h:405
@ GUMBO_INSERTION_ADOPTION_AGENCY_MOVED
Definition gumbo.h:421
@ GUMBO_INSERTION_BY_PARSER
Definition gumbo.h:370
@ GUMBO_INSERTION_IMPLIED
Definition gumbo.h:391
@ GUMBO_INSERTION_FROM_IMAGE
Definition gumbo.h:408
void gumbo_destroy_output(const GumboOptions *options, GumboOutput *output)
GumboTag gumbo_tag_enum(const char *tagname)
bool gumbo_string_equals(const GumboStringPiece *str1, const GumboStringPiece *str2)
const char * gumbo_normalized_tagname(GumboTag tag)
bool gumbo_tag_is_void(GumboTag tag)
const GumboStringPiece kGumboEmptyString
const GumboVector kGumboEmptyVector
GumboQuirksModeEnum
Definition gumbo.h:330
const GumboSourcePosition kGumboEmptySourcePosition
void gumbo_tag_from_original_text(GumboStringPiece *text)
GumboAttribute * gumbo_get_attribute(const GumboVector *attrs, const char *name)
GumboOutput * gumbo_parse_with_options(const GumboOptions *options, const char *buffer, size_t buffer_length)
const GumboOptions kGumboDefaultOptions
Definition gumbo.h:232
GumboSourcePosition name_start
Definition gumbo.h:272
GumboSourcePosition name_end
Definition gumbo.h:279
GumboStringPiece original_value
Definition gumbo.h:269
GumboSourcePosition value_end
Definition gumbo.h:285
GumboStringPiece original_name
Definition gumbo.h:251
GumboAttributeNamespaceEnum attr_namespace
Definition gumbo.h:239
GumboSourcePosition value_start
Definition gumbo.h:282
const char * name
Definition gumbo.h:245
const char * value
Definition gumbo.h:259
Definition gumbo.h:433
GumboQuirksModeEnum doc_type_quirks_mode
Definition gumbo.h:453
GumboVector children
Definition gumbo.h:439
Definition gumbo.h:484
GumboStringPiece original_end_tag
Definition gumbo.h:510
GumboNamespaceEnum tag_namespace
Definition gumbo.h:495
GumboSourcePosition start_pos
Definition gumbo.h:513
GumboVector attributes
Definition gumbo.h:522
GumboTag tag
Definition gumbo.h:492
GumboVector children
Definition gumbo.h:489
GumboStringPiece original_tag
Definition gumbo.h:503
GumboSourcePosition end_pos
Definition gumbo.h:516
Definition gumbo.h:529
GumboNode * parent
Definition gumbo.h:534
GumboNodeType type
Definition gumbo.h:531
GumboParseFlags parse_flags
Definition gumbo.h:544
size_t index_within_parent
Definition gumbo.h:537
union GumboInternalNode::@044304353357307275111145255336171272367277127234 v
Definition gumbo.h:575
GumboTag fragment_context
Definition gumbo.h:622
bool stop_on_first_error
Definition gumbo.h:598
GumboAllocatorFunction allocator
Definition gumbo.h:577
void * userdata
Definition gumbo.h:586
GumboDeallocatorFunction deallocator
Definition gumbo.h:580
int tab_stop
Definition gumbo.h:592
GumboNamespaceEnum fragment_namespace
Definition gumbo.h:630
int max_errors
Definition gumbo.h:607
Definition gumbo.h:637
GumboNode * root
Definition gumbo.h:648
GumboVector errors
Definition gumbo.h:657
GumboNode * document
Definition gumbo.h:642
Definition gumbo.h:67
Definition gumbo.h:88
const char * data
Definition gumbo.h:90
size_t length
Definition gumbo.h:93
Definition gumbo.h:460
GumboStringPiece original_text
Definition gumbo.h:471
const char * text
Definition gumbo.h:465
GumboSourcePosition start_pos
Definition gumbo.h:477
Definition gumbo.h:122
void ** data
Definition gumbo.h:126
unsigned int capacity
Definition gumbo.h:132
unsigned int length
Definition gumbo.h:129