Implement the most basic clear function and all "create node" functions.
This commit is contained in:
parent
e5219da6fe
commit
cf5eefdc7f
|
@ -1 +1,88 @@
|
|||
#include "libregex.h"
|
||||
#include "libregex.h"#include "libregex.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
libregex_result _regex_node_create_clear(regex_node** node){
|
||||
libregex_result result = LIBREGEX_SUCCESS;
|
||||
*node = malloc(sizeof(**node));
|
||||
if(*node){
|
||||
regex_node_clear(*node);
|
||||
} else {
|
||||
result = LIBREGEX_MALLOC;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
libregex_result _regex_node_create_value(regex_node** node, char value, regex_node* next){
|
||||
libregex_result result = _regex_node_create_clear(node);
|
||||
if(result == LIBREGEX_SUCCESS){
|
||||
(*node)->type = REGEX_VALUE;
|
||||
(*node)->data_u.value_s.value = value;
|
||||
(*node)->data_u.value_s.next = next;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
libregex_result _regex_node_create_range(regex_node** node, char from, char to, regex_node* next){
|
||||
libregex_result result = _regex_node_create_clear(node);
|
||||
if(result == LIBREGEX_SUCCESS){
|
||||
(*node)->type = REGEX_RANGE;
|
||||
(*node)->data_u.range_s.from = from;
|
||||
(*node)->data_u.range_s.to = to;
|
||||
(*node)->data_u.range_s.next = next;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
libregex_result _regex_node_create_any(regex_node** node, regex_node* next){
|
||||
libregex_result result = _regex_node_create_clear(node);
|
||||
if(result == LIBREGEX_SUCCESS){
|
||||
(*node)->type = REGEX_ANY;
|
||||
(*node)->data_u.any_s.next = next;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
libregex_result _regex_node_create_connect(regex_node** node, regex_node* next){
|
||||
libregex_result result = _regex_node_create_clear(node);
|
||||
if(result == LIBREGEX_SUCCESS){
|
||||
(*node)->type = REGEX_CONNECT;
|
||||
(*node)->data_u.connect_s.next = next;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
libregex_result _regex_node_create_fork(regex_node** node, regex_node* left, regex_node* right){
|
||||
libregex_result result = _regex_node_create_clear(node);
|
||||
if(result == LIBREGEX_SUCCESS){
|
||||
(*node)->type = REGEX_FORK;
|
||||
(*node)->data_u.fork_s.left = left;
|
||||
(*node)->data_u.fork_s.right = right;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
libregex_result _regex_node_create_group(regex_node** open, regex_node** close, int group_id){
|
||||
libregex_result result = _regex_node_create_clear(open);
|
||||
if(result == LIBREGEX_SUCCESS){
|
||||
result = _regex_node_create_clear(close);
|
||||
}
|
||||
if(result == LIBREGEX_SUCCESS){
|
||||
(*open)->type = (*close)->type = REGEX_GROUP;
|
||||
(*open)->data_u.group_s.id = (*close)->data_u.group_s.id = group_id;
|
||||
(*open)->data_u.group_s.other = (*close);
|
||||
(*close)->data_u.group_s.other = (*open);
|
||||
|
||||
(*open)->data_u.group_s.open = 1;
|
||||
} else {
|
||||
free(*open);
|
||||
free(*close);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void regex_node_clear(regex_node* node){
|
||||
node->type = REGEX_CLEAR;
|
||||
node->list_id = -1;
|
||||
memset(&node->data_u, 0, sizeof(node->data_u));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user