mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
Add struct dom_string
In time it should be used for all strings in the DOM engine. For now it is just used for node->string.
This commit is contained in:
parent
f9dea85126
commit
ce3778c3c0
@ -155,13 +155,13 @@ dom_node_cmp(struct dom_node_search *search, struct dom_node *node)
|
||||
}
|
||||
}
|
||||
{
|
||||
int length = int_min(key->length, node->length);
|
||||
int string_diff = strncasecmp(key->string, node->string, length);
|
||||
int length = int_min(key->string.length, node->string.length);
|
||||
int string_diff = strncasecmp(key->string.string, node->string.string, length);
|
||||
|
||||
/* If the lengths or strings don't match strncasecmp() does the
|
||||
* job else return which ever is bigger. */
|
||||
|
||||
return string_diff ? string_diff : key->length - node->length;
|
||||
return string_diff ? string_diff : key->string.length - node->string.length;
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,7 +213,7 @@ struct dom_node *
|
||||
get_dom_node_map_entry(struct dom_node_list *list, enum dom_node_type type,
|
||||
uint16_t subtype, unsigned char *name, int namelen)
|
||||
{
|
||||
struct dom_node node = { type, namelen, name };
|
||||
struct dom_node node = { type, INIT_DOM_STRING(name, namelen) };
|
||||
struct dom_node_search search = INIT_DOM_NODE_SEARCH(&node, subtype, list);
|
||||
|
||||
return dom_node_list_bsearch(&search, list);
|
||||
@ -235,9 +235,8 @@ init_dom_node_(unsigned char *file, int line,
|
||||
if (!node) return NULL;
|
||||
|
||||
node->type = type;
|
||||
node->string = string;
|
||||
node->length = length;
|
||||
node->parent = parent;
|
||||
set_dom_string(&node->string, string, length);
|
||||
|
||||
if (parent) {
|
||||
struct dom_node_list **list = get_dom_node_list(parent, node);
|
||||
@ -272,7 +271,7 @@ done_dom_node_data(struct dom_node *node)
|
||||
switch (node->type) {
|
||||
case DOM_NODE_ATTRIBUTE:
|
||||
if (data->attribute.allocated)
|
||||
mem_free(node->string);
|
||||
done_dom_string(&node->string);
|
||||
break;
|
||||
|
||||
case DOM_NODE_DOCUMENT:
|
||||
@ -296,7 +295,7 @@ done_dom_node_data(struct dom_node *node)
|
||||
|
||||
case DOM_NODE_TEXT:
|
||||
if (data->text.allocated)
|
||||
mem_free(node->string);
|
||||
done_dom_string(&node->string);
|
||||
break;
|
||||
|
||||
case DOM_NODE_PROCESSING_INSTRUCTION:
|
||||
@ -383,8 +382,8 @@ get_dom_node_name(struct dom_node *node)
|
||||
case DOM_NODE_NOTATION:
|
||||
case DOM_NODE_PROCESSING_INSTRUCTION:
|
||||
default:
|
||||
name = node->string;
|
||||
namelen = node->length;
|
||||
name = node->string.string;
|
||||
namelen = node->string.length;
|
||||
}
|
||||
|
||||
return memacpy(name, namelen);
|
||||
@ -435,12 +434,13 @@ get_dom_node_value(struct dom_node *node, int codepage)
|
||||
case DOM_NODE_CDATA_SECTION:
|
||||
case DOM_NODE_COMMENT:
|
||||
case DOM_NODE_TEXT:
|
||||
value = node->string;
|
||||
valuelen = node->length;
|
||||
value = node->string.string;
|
||||
valuelen = node->string.length;
|
||||
break;
|
||||
|
||||
case DOM_NODE_ENTITY_REFERENCE:
|
||||
value = get_entity_string(node->string, node->length,
|
||||
value = get_entity_string(node->string.string,
|
||||
node->string.length,
|
||||
codepage);
|
||||
valuelen = value ? strlen(value) : 0;
|
||||
break;
|
||||
|
@ -2,6 +2,7 @@
|
||||
#ifndef EL__DOCUMENT_DOM_NODE_H
|
||||
#define EL__DOCUMENT_DOM_NODE_H
|
||||
|
||||
#include "document/dom/string.h"
|
||||
#include "util/hash.h"
|
||||
|
||||
struct dom_node_list;
|
||||
@ -207,8 +208,7 @@ struct dom_node {
|
||||
|
||||
/* Can contain either stuff like element name or for attributes the
|
||||
* attribute name. */
|
||||
uint16_t length;
|
||||
unsigned char *string;
|
||||
struct dom_string string;
|
||||
|
||||
struct dom_node *parent;
|
||||
|
||||
|
@ -517,8 +517,8 @@ static inline void
|
||||
render_dom_node_text(struct dom_renderer *renderer, struct screen_char *template,
|
||||
struct dom_node *node)
|
||||
{
|
||||
unsigned char *string = node->string;
|
||||
int length = node->length;
|
||||
unsigned char *string = node->string.string;
|
||||
int length = node->string.length;
|
||||
|
||||
if (node->type == DOM_NODE_ENTITY_REFERENCE) {
|
||||
string -= 1;
|
||||
@ -565,7 +565,7 @@ render_dom_proc_instr_source(struct dom_stack *stack, struct dom_node *node, voi
|
||||
if (!value || node->data.proc_instruction.map)
|
||||
return node;
|
||||
|
||||
if (check_dom_node_source(renderer, node->string, node->length)) {
|
||||
if (check_dom_node_source(renderer, node->string.string, node->string.length)) {
|
||||
render_dom_flush(renderer, value);
|
||||
renderer->position = value + valuelen;
|
||||
}
|
||||
|
@ -96,8 +96,8 @@ search_dom_stack(struct dom_stack *stack, enum dom_node_type type,
|
||||
struct dom_node *parent = state->node;
|
||||
|
||||
if (parent->type == type
|
||||
&& parent->length == length
|
||||
&& !strncasecmp(parent->string, string, length))
|
||||
&& parent->string.length == length
|
||||
&& !strncasecmp(parent->string.string, string, length))
|
||||
return state;
|
||||
}
|
||||
|
||||
|
21
src/document/dom/string.h
Normal file
21
src/document/dom/string.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef EL__DOCUMENT_DOM_STRING_H
|
||||
#define EL__DOCUMENT_DOM_STRING_H
|
||||
|
||||
struct dom_string {
|
||||
uint16_t length;
|
||||
unsigned char *string;
|
||||
};
|
||||
|
||||
#define INIT_DOM_STRING(strvalue, strlength) \
|
||||
{ (strlength) == -1 ? sizeof(strvalue) - 1 : (strlength), (strvalue) }
|
||||
|
||||
static inline void
|
||||
set_dom_string(struct dom_string *string, unsigned char *value, uint16_t length)
|
||||
{
|
||||
string->string = value;
|
||||
string->length = length;
|
||||
}
|
||||
|
||||
#define done_dom_string(str) mem_free((str)->string);
|
||||
|
||||
#endif
|
@ -20,9 +20,9 @@ sgml_info_strcmp(const void *key_, const void *node_)
|
||||
{
|
||||
struct dom_node *key = (struct dom_node *) key_;
|
||||
struct sgml_node_info *node = (struct sgml_node_info *) node_;
|
||||
int length = int_min(key->length, node->length);
|
||||
int string_diff = strncasecmp(key->string, node->string, length);
|
||||
int length_diff = key->length - node->length;
|
||||
int length = int_min(key->string.length, node->length);
|
||||
int string_diff = strncasecmp(key->string.string, node->string, length);
|
||||
int length_diff = key->string.length - node->length;
|
||||
|
||||
/* If the lengths or strings don't match strncasecmp() does the job
|
||||
* else return which ever is bigger. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user