Added copy function
This commit is contained in:
10
README.md
10
README.md
@@ -530,6 +530,16 @@ void mpc_cleanup(int n, ...);
|
||||
|
||||
To ease the task of undefining and then deleting parsers `mpc_cleanup` can be used. It takes `n` parsers as input, and undefines them all, before deleting them all.
|
||||
|
||||
* * *
|
||||
|
||||
```c
|
||||
mpc_parser_t *mpc_copy(mpc_parser_t *a);
|
||||
```
|
||||
|
||||
This function makes a copy of a parser `a`. This can be useful when you want to
|
||||
use a parser as input for some other parsers multiple times without retaining
|
||||
it.
|
||||
|
||||
|
||||
Library Reference
|
||||
=================
|
||||
|
12
mpc.c
12
mpc.c
@@ -1364,6 +1364,18 @@ mpc_parser_t *mpc_new(const char *name) {
|
||||
return p;
|
||||
}
|
||||
|
||||
mpc_parser_t *mpc_copy(mpc_parser_t *a) {
|
||||
mpc_parser_t *p = mpc_undefined();
|
||||
p->retained = a->retained;
|
||||
p->type = a->type;
|
||||
p->data = a->data;
|
||||
if (a->name) {
|
||||
p->name = malloc(strlen(a->name)+1);
|
||||
strcpy(p->name, a->name);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
mpc_parser_t *mpc_undefine(mpc_parser_t *p) {
|
||||
mpc_undefine_unretained(p, 1);
|
||||
p->type = MPC_TYPE_UNDEFINED;
|
||||
|
Reference in New Issue
Block a user