Cogs.Core
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
42#ifndef GUMBO_GUMBO_H_
43#define GUMBO_GUMBO_H_
44
45#ifdef _MSC_VER
46#ifndef _CRT_SECURE_NO_WARNINGS
47#define _CRT_SECURE_NO_WARNINGS
48#endif
49#define fileno _fileno
50#endif
51
52#include <stdbool.h>
53#include <stddef.h>
54
55#ifdef __cplusplus
56extern "C" {
57#endif
58
69typedef struct {
70 unsigned int line;
71 unsigned int column;
72 unsigned int offset;
74
80
90typedef struct {
92 const char* data;
93
95 size_t length;
97
100
106 const GumboStringPiece* str1, const GumboStringPiece* str2);
107
113 const GumboStringPiece* str1, const GumboStringPiece* str2);
114
124typedef struct {
128 void** data;
129
131 unsigned int length;
132
134 unsigned int capacity;
136
138extern const GumboVector kGumboEmptyVector;
139
144int gumbo_vector_index_of(GumboVector* vector, const void* element);
145
158typedef enum {
159// Load all the tags from an external source, generated from tag.in.
160#include "tag_enum.h"
161 // Used for all tags that don't have special handling in HTML. Add new tags
162 // to the end of tag.in so as to preserve backwards-compatibility.
163 GUMBO_TAG_UNKNOWN,
164 // A marker value to indicate the end of the enum, for iterating over it.
165 // Also used as the terminator for varargs functions that take tags.
166 GUMBO_TAG_LAST,
167} GumboTag;
168
175
187
201
206GumboTag gumbo_tag_enum(const char* tagname);
207GumboTag gumbo_tagn_enum(const char* tagname, unsigned int length);
208
214typedef enum {
215 GUMBO_ATTR_NAMESPACE_NONE,
216 GUMBO_ATTR_NAMESPACE_XLINK,
217 GUMBO_ATTR_NAMESPACE_XML,
218 GUMBO_ATTR_NAMESPACE_XMLNS,
220
226typedef struct {
234
239 const char* name;
240
246
253 const char* value;
254
264
267
274
277
281
287GumboAttribute* gumbo_get_attribute(const GumboVector* attrs, const char* name);
288
293typedef enum {
313
319
323typedef enum {
324 GUMBO_DOCTYPE_NO_QUIRKS,
325 GUMBO_DOCTYPE_QUIRKS,
326 GUMBO_DOCTYPE_LIMITED_QUIRKS
328
336typedef enum {
337 GUMBO_NAMESPACE_HTML,
338 GUMBO_NAMESPACE_SVG,
339 GUMBO_NAMESPACE_MATHML
341
350typedef enum {
356
364
377
378 // Value 1 << 2 was for a flag that has since been removed.
379
385
393
396
399
406
409
412
419
423typedef struct {
429 GumboVector /* GumboNode* */ children;
430
431 // True if there was an explicit doctype token as opposed to it being omitted.
432 bool has_doctype;
433
434 // Fields from the doctype token, copied verbatim.
435 const char* name;
436 const char* public_identifier;
437 const char* system_identifier;
438
445
450typedef struct {
455 const char* text;
456
462
468} GumboText;
469
474typedef struct {
479 GumboVector /* GumboNode* */ children;
480
483
486
494
501
504
507
512 GumboVector /* GumboAttribute* */ attributes;
514
522
525
528
535
537 union {
538 GumboDocument document; // For GUMBO_NODE_DOCUMENT.
539 GumboElement element; // For GUMBO_NODE_ELEMENT.
540 GumboText text; // For everything else.
541 } v;
542};
543
550// TODO(jdtang): Add checks throughout the codebase for out-of-memory condition.
551typedef void* (*GumboAllocatorFunction)(void* userdata, size_t size);
552
557typedef void (*GumboDeallocatorFunction)(void* userdata, void* ptr);
558
565typedef struct GumboInternalOptions {
568
571
576 void* userdata;
577
583
589
598
613
622
625
627typedef struct GumboInternalOutput {
633
639
647 GumboVector /* GumboError */ errors;
649
657GumboOutput* gumbo_parse(const char* buffer);
658
664 const GumboOptions* options, const char* buffer, size_t buffer_length);
665
667void gumbo_destroy_output(const GumboOptions* options, GumboOutput* output);
668
669#ifdef __cplusplus
670}
671#endif
672
673#endif // GUMBO_GUMBO_H_
GumboAttributeNamespaceEnum
Definition: gumbo.h:214
void(* GumboDeallocatorFunction)(void *userdata, void *ptr)
Definition: gumbo.h:557
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:336
GumboTag
Definition: gumbo.h:158
void *(* GumboAllocatorFunction)(void *userdata, size_t size)
Definition: gumbo.h:551
bool gumbo_string_equals_ignore_case(const GumboStringPiece *str1, const GumboStringPiece *str2)
GumboNodeType
Definition: gumbo.h:293
@ GUMBO_NODE_CDATA
Definition: gumbo.h:301
@ GUMBO_NODE_TEXT
Definition: gumbo.h:299
@ GUMBO_NODE_DOCUMENT
Definition: gumbo.h:295
@ GUMBO_NODE_WHITESPACE
Definition: gumbo.h:305
@ GUMBO_NODE_COMMENT
Definition: gumbo.h:303
@ GUMBO_NODE_TEMPLATE
Definition: gumbo.h:311
@ GUMBO_NODE_ELEMENT
Definition: gumbo.h:297
GumboParseFlags
Definition: gumbo.h:350
@ GUMBO_INSERTION_ADOPTION_AGENCY_CLONED
Definition: gumbo.h:408
@ GUMBO_INSERTION_NORMAL
Definition: gumbo.h:355
@ GUMBO_INSERTION_CONVERTED_FROM_END_TAG
Definition: gumbo.h:392
@ GUMBO_INSERTION_IMPLICIT_END_TAG
Definition: gumbo.h:376
@ GUMBO_INSERTION_FOSTER_PARENTED
Definition: gumbo.h:417
@ GUMBO_INSERTION_RECONSTRUCTED_FORMATTING_ELEMENT
Definition: gumbo.h:405
@ GUMBO_INSERTION_FROM_ISINDEX
Definition: gumbo.h:395
@ GUMBO_INSERTION_ADOPTION_AGENCY_MOVED
Definition: gumbo.h:411
@ GUMBO_INSERTION_BY_PARSER
Definition: gumbo.h:363
@ GUMBO_INSERTION_IMPLIED
Definition: gumbo.h:384
@ GUMBO_INSERTION_FROM_IMAGE
Definition: gumbo.h:398
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)
const GumboStringPiece kGumboEmptyString
const GumboVector kGumboEmptyVector
GumboQuirksModeEnum
Definition: gumbo.h:323
const GumboSourcePosition kGumboEmptySourcePosition
void gumbo_tag_from_original_text(GumboStringPiece *text)
GumboAttribute * gumbo_get_attribute(const GumboVector *attrs, const char *name)
struct GumboInternalOutput GumboOutput
GumboOutput * gumbo_parse_with_options(const GumboOptions *options, const char *buffer, size_t buffer_length)
const GumboOptions kGumboDefaultOptions
struct GumboInternalOptions GumboOptions
GumboSourcePosition name_start
Definition: gumbo.h:266
GumboSourcePosition name_end
Definition: gumbo.h:273
GumboStringPiece original_value
Definition: gumbo.h:263
GumboSourcePosition value_end
Definition: gumbo.h:279
GumboStringPiece original_name
Definition: gumbo.h:245
GumboAttributeNamespaceEnum attr_namespace
Definition: gumbo.h:233
GumboSourcePosition value_start
Definition: gumbo.h:276
const char * name
Definition: gumbo.h:239
const char * value
Definition: gumbo.h:253
GumboQuirksModeEnum doc_type_quirks_mode
Definition: gumbo.h:443
GumboVector children
Definition: gumbo.h:429
GumboStringPiece original_end_tag
Definition: gumbo.h:500
GumboNamespaceEnum tag_namespace
Definition: gumbo.h:485
GumboSourcePosition start_pos
Definition: gumbo.h:503
GumboVector attributes
Definition: gumbo.h:512
GumboTag tag
Definition: gumbo.h:482
GumboVector children
Definition: gumbo.h:479
GumboStringPiece original_tag
Definition: gumbo.h:493
GumboSourcePosition end_pos
Definition: gumbo.h:506
union GumboInternalNode::@87 v
size_t index_within_parent
Definition: gumbo.h:527
GumboNodeType type
Definition: gumbo.h:521
GumboParseFlags parse_flags
Definition: gumbo.h:534
GumboNode * parent
Definition: gumbo.h:524
GumboDeallocatorFunction deallocator
Definition: gumbo.h:570
GumboTag fragment_context
Definition: gumbo.h:612
bool stop_on_first_error
Definition: gumbo.h:588
GumboNamespaceEnum fragment_namespace
Definition: gumbo.h:620
GumboAllocatorFunction allocator
Definition: gumbo.h:567
GumboNode * root
Definition: gumbo.h:638
GumboVector errors
Definition: gumbo.h:647
GumboNode * document
Definition: gumbo.h:632
const char * data
Definition: gumbo.h:92
size_t length
Definition: gumbo.h:95
GumboStringPiece original_text
Definition: gumbo.h:461
const char * text
Definition: gumbo.h:455
GumboSourcePosition start_pos
Definition: gumbo.h:467
void ** data
Definition: gumbo.h:128
unsigned int capacity
Definition: gumbo.h:134
unsigned int length
Definition: gumbo.h:131