Hubbub
entities.c
Go to the documentation of this file.
1 /*
2  * This file is part of Hubbub.
3  * Licensed under the MIT License,
4  * http://www.opensource.org/licenses/mit-license.php
5  * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
6  */
7 
8 #include "utils/utils.h"
9 #include "tokeniser/entities.h"
10 
12 typedef struct hubbub_entity_node {
13  /* Do not reorder this without fixing make-entities.pl */
14  uint8_t split;
15  int32_t lt;
16  int32_t eq;
17  int32_t gt;
18  uint32_t value;
20 
21 #include "entities.inc"
22 
41  uint32_t *result, int32_t *context)
42 {
43  bool match = false;
44  int32_t p;
45 
46  if (result == NULL || context == NULL)
47  return HUBBUB_BADPARM;
48 
49  if (*context == -1) {
50  p = dict_root;
51  } else {
52  p = *context;
53  }
54 
55  while (p != -1) {
56  if (c < dict[p].split) {
57  p = dict[p].lt;
58  } else if (c == dict[p].split) {
59  if (dict[p].split == '\0') {
60  match = true;
61  p = -1;
62  } else if (dict[p].eq != -1 && dict[dict[p].eq].split == '\0') {
63  match = true;
64  *result = dict[dict[p].eq].value;
65  p = dict[p].eq;
66  } else if (dict[p].value != 0) {
67  match = true;
68  *result = dict[p].value;
69  p = dict[p].eq;
70  } else {
71  p = dict[p].eq;
72  }
73 
74  break;
75  } else {
76  p = dict[p].gt;
77  }
78  }
79 
80  *context = p;
81 
82  return (match) ? HUBBUB_OK :
83  (p == -1) ? HUBBUB_INVALID : HUBBUB_NEEDDATA;
84 }
85 
103 hubbub_error hubbub_entities_search_step(uint8_t c, uint32_t *result,
104  int32_t *context)
105 {
106  if (result == NULL)
107  return HUBBUB_BADPARM;
108 
109  *result = 0xFFFD;
110 
111  return hubbub_entity_tree_search_step(c, result, context);
112 }
uint32_t value
Data for this node.
Definition: entities.c:18
hubbub_error hubbub_entities_search_step(uint8_t c, uint32_t *result, int32_t *context)
Step-wise search for an entity in the dictionary.
Definition: entities.c:103
struct hubbub_entity_node hubbub_entity_node
Node in our entity tree.
int32_t gt
Subtree for data greater than split.
Definition: entities.c:17
hubbub_error
Definition: errors.h:18
int32_t eq
Subtree for data equal to split.
Definition: entities.c:16
uint8_t split
Data to split on.
Definition: entities.c:14
static hubbub_error hubbub_entity_tree_search_step(uint8_t c, uint32_t *result, int32_t *context)
Step-wise search for a key in our entity tree.
Definition: entities.c:40
No error.
Definition: errors.h:19
Node in our entity tree.
Definition: entities.c:12
int32_t lt
Subtree for data less than split.
Definition: entities.c:15