From 12de194a28448ead84ffd76118f34903f99ba029 Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 3 Jun 2014 18:17:18 +0800 Subject: [PATCH] update sample code --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index f90deac..7bfa4de 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,18 @@ r3_tree_insert_pathl(n ,"/post/{id}", strlen("/post/{id}") , &route_data ); r3_tree_insert_pathl(n, "/user/{id:\\d+}", strlen("/user/{id:\\d+}"), &route_data ); + +// if you want to cache error, you may call the extended path function for insertion +int data = 10; +char *errstr = NULL; +node *ret = r3_tree_insert_pathl_ex(n, "/foo/{name:\\d{5}", strlen("/foo/{name:\\d{5}"), NULL, &data, &errstr); +if (ret == NULL) { + // failed insertion + printf("error: %s\n", errstr); + free(errstr); // errstr is created from `asprintf`, so you have to free it manually. +} + + // let's compile the tree! char *errstr = NULL; int err = r3_tree_compile(n, &errstr);