Skip to content

Commit

Permalink
adjust code
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangjipeng committed Feb 24, 2025
1 parent 456699b commit fbc57c4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 33 deletions.
4 changes: 4 additions & 0 deletions ext/common/psx_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@
extern "C" {
#endif

#ifndef mem_calloc
#define mem_calloc calloc
#endif
#ifndef mem_free
#define mem_free free
#endif

#define PSX_ARRAY_DEFAULT_CAPACITY 4

Expand Down
50 changes: 25 additions & 25 deletions ext/svg/psx_xml_token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ typedef struct {
uint32_t flags;
const char* cur;
const char* end;
} xml_token_state_t;
} xml_token_state;

static INLINE void _psx_token_init(psx_xml_token_t* token)
static INLINE void _psx_token_init(psx_xml_token* token)
{
token->flags = 0;
token->start = NULL;
token->end = NULL;
token->type = PSX_XML_CONTENT;
token->cur_attr = NULL;
psx_array_init_type(&token->attrs, psx_xml_token_attr_t);
psx_array_init_type(&token->attrs, psx_xml_token_attr);
}

static INLINE void _psx_token_clear(psx_xml_token_t* token)
static INLINE void _psx_token_clear(psx_xml_token* token)
{
token->flags = 0;
token->start = NULL;
Expand All @@ -105,16 +105,16 @@ static INLINE void _psx_token_clear(psx_xml_token_t* token)
psx_array_clear(&token->attrs);
}

static INLINE psx_xml_token_attr_t* _create_xml_attr(psx_xml_token_t* token)
static INLINE psx_xml_token_attr* _create_xml_attr(psx_xml_token* token)
{
psx_array_append(&token->attrs, NULL);

psx_xml_token_attr_t* attr = psx_array_get_last(&token->attrs, psx_xml_token_attr_t);
memset(attr, 0, sizeof(psx_xml_token_attr_t));
psx_xml_token_attr* attr = psx_array_get_last(&token->attrs, psx_xml_token_attr);
memset(attr, 0, sizeof(psx_xml_token_attr));
return attr;
}

static INLINE bool _xml_token_process(psx_xml_token_t* token, xml_token_process cb, void* data)
static INLINE bool _xml_token_process(psx_xml_token* token, xml_token_process cb, void* data)
{
if (!token->start || TOKEN_LEN(token) == 0) {
return true;
Expand All @@ -125,57 +125,57 @@ static INLINE bool _xml_token_process(psx_xml_token_t* token, xml_token_process
return ret;
}

static INLINE void _psx_set_state(xml_token_state_t* state, uint32_t bit)
static INLINE void _psx_set_state(xml_token_state* state, uint32_t bit)
{
state->flags |= bit;
}

static INLINE void _psx_clear_state(xml_token_state_t* state, uint32_t bit)
static INLINE void _psx_clear_state(xml_token_state* state, uint32_t bit)
{
state->flags &= ~bit;
}

static INLINE bool _psx_is_state(xml_token_state_t* state, uint32_t bit)
static INLINE bool _psx_is_state(xml_token_state* state, uint32_t bit)
{
return state->flags & bit;
}

static INLINE void _psx_set_tag_state(xml_token_state_t* state, uint32_t bit)
static INLINE void _psx_set_tag_state(xml_token_state* state, uint32_t bit)
{
state->flags = (state->flags & ~IN_TAG_MASK) | bit;
}

static INLINE uint32_t _psx_get_tag_state(xml_token_state_t* state)
static INLINE uint32_t _psx_get_tag_state(xml_token_state* state)
{
return state->flags & IN_TAG_MASK;
}

static INLINE void _psx_set_quote_state(xml_token_state_t* state, uint32_t bit)
static INLINE void _psx_set_quote_state(xml_token_state* state, uint32_t bit)
{
state->flags = (state->flags & ~IN_QUOTE_MASK) | (bit << 6);
}

static INLINE uint32_t _psx_get_quote_state(xml_token_state_t* state)
static INLINE uint32_t _psx_get_quote_state(xml_token_state* state)
{
return (state->flags & IN_QUOTE_MASK) >> 6;
}

static INLINE void _psx_set_entity_state(xml_token_state_t* state, uint32_t bit)
static INLINE void _psx_set_entity_state(xml_token_state* state, uint32_t bit)
{
state->flags = (state->flags & ~IN_ENTITY_MASK) | (bit << 3);
}

static INLINE uint32_t _psx_get_entity_state(xml_token_state_t* state)
static INLINE uint32_t _psx_get_entity_state(xml_token_state* state)
{
return (state->flags & IN_ENTITY_MASK) >> 3;
}

static INLINE bool _psx_special_handles(xml_token_state_t* state)
static INLINE bool _psx_special_handles(xml_token_state* state)
{
return state->flags & (IN_START_TAG | IN_SEARCH | IN_TAG_MASK | IN_ENTITY_MASK | IN_COMMENT | IN_SERVER_SIDE | IN_DOCTYPE | IN_XMLINST | IN_SCRIPT);
}

static INLINE void _psx_proc_xml_inst(xml_token_state_t* state, psx_xml_token_t* token)
static INLINE void _psx_proc_xml_inst(xml_token_state* state, psx_xml_token* token)
{
// ignore xml inst
while (state->cur <= state->end) {
Expand All @@ -189,7 +189,7 @@ static INLINE void _psx_proc_xml_inst(xml_token_state_t* state, psx_xml_token_t*
}
}

static INLINE void _psx_proc_comment(xml_token_state_t* state, psx_xml_token_t* token)
static INLINE void _psx_proc_comment(xml_token_state* state, psx_xml_token* token)
{
// ignore comment
while (state->cur <= state->end) {
Expand All @@ -203,7 +203,7 @@ static INLINE void _psx_proc_comment(xml_token_state_t* state, psx_xml_token_t*
}
}

static INLINE void _psx_proc_doctype(xml_token_state_t* state, psx_xml_token_t* token)
static INLINE void _psx_proc_doctype(xml_token_state* state, psx_xml_token* token)
{
// ignore doctype
while (state->cur <= state->end) {
Expand All @@ -217,7 +217,7 @@ static INLINE void _psx_proc_doctype(xml_token_state_t* state, psx_xml_token_t*
}
}

static INLINE bool _psx_proc_entity(xml_token_state_t* state, psx_xml_token_t* token, xml_token_process cb, void* data)
static INLINE bool _psx_proc_entity(xml_token_state* state, psx_xml_token* token, xml_token_process cb, void* data)
{
while (state->cur <= state->end) {
switch (_psx_get_entity_state(state)) {
Expand Down Expand Up @@ -298,7 +298,7 @@ static INLINE bool _psx_proc_entity(xml_token_state_t* state, psx_xml_token_t* t
return true;
}

static INLINE bool _psx_proc_tag(xml_token_state_t* state, psx_xml_token_t* token, xml_token_process cb, void* data)
static INLINE bool _psx_proc_tag(xml_token_state* state, psx_xml_token* token, xml_token_process cb, void* data)
{
while (state->cur <= state->end) {
switch (_psx_get_tag_state(state)) {
Expand Down Expand Up @@ -446,10 +446,10 @@ static INLINE bool _psx_proc_tag(xml_token_state_t* state, psx_xml_token_t* toke

bool psx_xml_tokenizer(const char* xml_data, uint32_t data_len, xml_token_process cb, void* data)
{
psx_xml_token_t token;
psx_xml_token token;
_psx_token_init(&token);

xml_token_state_t state;
xml_token_state state;
state.flags = 0;
state.cur = xml_data;
state.end = xml_data + data_len;
Expand Down
12 changes: 6 additions & 6 deletions ext/svg/psx_xml_token.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ typedef enum {
PSX_XML_END = 2,
PSX_XML_CONTENT = 3,
PSX_XML_ENTITY = 4,
} psx_xml_token_type_t;
} psx_xml_token_type;

typedef struct {
const char* name_start;
const char* name_end;
const char* value_start;
const char* value_end;
} psx_xml_token_attr_t;
} psx_xml_token_attr;

enum {
PSX_XML_TOKEN_FLAT = 1,
Expand All @@ -56,12 +56,12 @@ typedef struct {
uint32_t flags;
const char* start;
const char* end;
psx_xml_token_type_t type;
psx_xml_token_attr_t* cur_attr;
psx_xml_token_type type;
psx_xml_token_attr* cur_attr;
psx_array_t attrs;
} psx_xml_token_t;
} psx_xml_token;

typedef bool (*xml_token_process)(void* context, const psx_xml_token_t* token);
typedef bool (*xml_token_process)(void* context, const psx_xml_token* token);

bool psx_xml_tokenizer(const char* xml_data, uint32_t data_len, xml_token_process cb, void* data);

Expand Down
4 changes: 2 additions & 2 deletions unit_tests/ext_xml_token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#include "psx_xml_token.h"

static bool _token_process(void* data, const psx_xml_token_t* token)
static bool _token_process(void* data, const psx_xml_token* token)
{
// success
if (token->type == PSX_XML_BEGIN) {
Expand All @@ -45,7 +45,7 @@ static bool _token_process(void* data, const psx_xml_token_t* token)
return true;
}

static bool _token_process_fail(void* data, const psx_xml_token_t* token)
static bool _token_process_fail(void* data, const psx_xml_token* token)
{
return false;
}
Expand Down

0 comments on commit fbc57c4

Please sign in to comment.