1 /*
2 * Copyright (C) 2019 Alexander Borisov
3 *
4 * Author: Alexander Borisov <borisov@lexbor.com>
5 */
6
7 #ifndef LEXBOR_HTML_ENCODING_H
8 #define LEXBOR_HTML_ENCODING_H
9
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13
14 #include "lexbor/html/base.h"
15
16 #include "lexbor/core/array_obj.h"
17
18
19 typedef struct {
20 const lxb_char_t *name;
21 const lxb_char_t *end;
22 }
23 lxb_html_encoding_entry_t;
24
25 typedef struct {
26 lexbor_array_obj_t cache;
27 lexbor_array_obj_t result;
28 }
29 lxb_html_encoding_t;
30
31
32 LXB_API lxb_status_t
33 lxb_html_encoding_init(lxb_html_encoding_t *em);
34
35 LXB_API lxb_html_encoding_t *
36 lxb_html_encoding_destroy(lxb_html_encoding_t *em, bool self_destroy);
37
38
39 LXB_API lxb_status_t
40 lxb_html_encoding_determine(lxb_html_encoding_t *em,
41 const lxb_char_t *data, const lxb_char_t *end);
42
43 LXB_API const lxb_char_t *
44 lxb_html_encoding_content(const lxb_char_t *data, const lxb_char_t *end,
45 const lxb_char_t **name_end);
46
47
48 /*
49 * Inline functions
50 */
51 lxb_inline lxb_html_encoding_t *
lxb_html_encoding_create(void)52 lxb_html_encoding_create(void)
53 {
54 return (lxb_html_encoding_t *) lexbor_calloc(1,
55 sizeof(lxb_html_encoding_t));
56 }
57
58 lxb_inline void
lxb_html_encoding_clean(lxb_html_encoding_t * em)59 lxb_html_encoding_clean(lxb_html_encoding_t *em)
60 {
61 lexbor_array_obj_clean(&em->cache);
62 lexbor_array_obj_clean(&em->result);
63 }
64
65 lxb_inline lxb_html_encoding_entry_t *
lxb_html_encoding_meta_entry(lxb_html_encoding_t * em,size_t idx)66 lxb_html_encoding_meta_entry(lxb_html_encoding_t *em, size_t idx)
67 {
68 return (lxb_html_encoding_entry_t *) lexbor_array_obj_get(&em->result, idx);
69 }
70
71 lxb_inline size_t
lxb_html_encoding_meta_length(lxb_html_encoding_t * em)72 lxb_html_encoding_meta_length(lxb_html_encoding_t *em)
73 {
74 return lexbor_array_obj_length(&em->result);
75 }
76
77 lxb_inline lexbor_array_obj_t *
lxb_html_encoding_meta_result(lxb_html_encoding_t * em)78 lxb_html_encoding_meta_result(lxb_html_encoding_t *em)
79 {
80 return &em->result;
81 }
82
83 /*
84 * No inline functions for ABI.
85 */
86 LXB_API lxb_html_encoding_t *
87 lxb_html_encoding_create_noi(void);
88
89 LXB_API void
90 lxb_html_encoding_clean_noi(lxb_html_encoding_t *em);
91
92 LXB_API lxb_html_encoding_entry_t *
93 lxb_html_encoding_meta_entry_noi(lxb_html_encoding_t *em, size_t idx);
94
95 LXB_API size_t
96 lxb_html_encoding_meta_length_noi(lxb_html_encoding_t *em);
97
98 LXB_API lexbor_array_obj_t *
99 lxb_html_encoding_meta_result_noi(lxb_html_encoding_t *em);
100
101
102 #ifdef __cplusplus
103 } /* extern "C" */
104 #endif
105
106 #endif /* LEXBOR_HTML_ENCODING_H */
107