aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2017-12-28 22:03:59 -0500
committerAlexander Pickering <alexandermpickering@gmail.com>2017-12-28 22:03:59 -0500
commit1d1cb9e3d003f23bddce0a744ffc60a7e82bf23c (patch)
treed4c4c702883402c921a4843ae5a898e44d528f59 /README.md
parent780fcb523eaa2feb3882967e7b2debf21aa569f2 (diff)
downloadlibctemplates-1d1cb9e3d003f23bddce0a744ffc60a7e82bf23c.tar.gz
libctemplates-1d1cb9e3d003f23bddce0a744ffc60a7e82bf23c.tar.bz2
libctemplates-1d1cb9e3d003f23bddce0a744ffc60a7e82bf23c.zip
Changed render function
Render function now returns the length of the string it returns
Diffstat (limited to 'README.md')
-rw-r--r--README.md26
1 files changed, 16 insertions, 10 deletions
diff --git a/README.md b/README.md
index 93029a0..c0deebb 100644
--- a/README.md
+++ b/README.md
@@ -92,9 +92,9 @@ Adds a loop to a varlist
Adds a varlist that should be used one iteration through the loop
- char* TMPL_render(struct TMPL_templates* t, struct TMPL_varlist* vl)
+ char* TMPL_render(struct TMPL_templates* t, struct TMPL_varlist* vl, size_t* length)
-Turns a template and varlist into a string. the returned char\* should NOT be freed. The returned char\* is only valid until TMPL\_render() is called again. If you need it even after TMPL\_render() is called, copy it.
+Turns a template and varlist into a string. the returned char\* should NOT be freed. The returned char\* is only valid until TMPL\_render() is called again. If you need it even after TMPL\_render() is called, copy it. The length of the returned string is put into `length` to help in copying.
<section id="Examples"></section>
## Examples
@@ -119,8 +119,10 @@ For example:
exit(-1);
}
struct TMPL_varlist* vl = TMPL_alloc_varlist();
- char* output = TMPL_render(t,vl);
+ size_t dummy;
+ char* output = TMPL_render(t,vl,&dummy);
printf("Output: %s\n",output);
+ printf("Length: %d\n",(int)dummy);
TMPL_free_varlist(vl);
TMPL_free_template(t);
return 0;
@@ -170,7 +172,8 @@ For example:
*/
t = TMPL_alloc_template(template);
vl = TMPL_alloc_varlist();
- char* without_variable = TMPL_render(t,vl);
+ size_t dummy;
+ char* without_variable = TMPL_render(t,vl,&dummy);
printf("Without variable: %s\n",without_variable);
TMPL_free_template(t);
TMPL_free_varlist(vl);
@@ -183,7 +186,8 @@ For example:
t = TMPL_alloc_template(template);
vl = TMPL_alloc_varlist();
TMPL_add_var_to_varlist(vl,"varname","Hello, world!");
- char* with_variable = TMPL_render(t,vl);
+ size_t dummy;
+ char* with_variable = TMPL_render(t,vl,&dummy);
printf("With variable:%s\n",with_variable);
TMPL_free_template(t);
TMPL_free_varlist(vl);
@@ -248,7 +252,8 @@ If and elseif statements check if strings are the same. They do a strcmp(), so b
the condition is considered false.
*/
vl = TMPL_alloc_varlist();
- char* without_variable = TMPL_render(t,vl);
+ size_t dummy;
+ char* without_variable = TMPL_render(t,vl,&dummy);
printf("Without variable:\n%s\n",without_variable);
/*
@@ -258,8 +263,9 @@ If and elseif statements check if strings are the same. They do a strcmp(), so b
buffer if you still need it.
*/
TMPL_add_var_to_varlist(vl,"var2","pass");
- char* with_one = TMPL_render(t,vl);
- printf("With 1 variable:\n%s\n",TMPL_render(t,vl));
+ size_t dummy;
+ char* with_one = TMPL_render(t,vl,&dummy);
+ printf("With 1 variable:\n%s\n",with_one);
/*
Always be sure to free things!
@@ -354,8 +360,8 @@ only variables that have been added to the namespace are acessable in the loop.
pass to TMPL_render() with the correct name.
*/
TMPL_add_loop_to_varlist(vl,"myloop",loop);
-
- char* output = TMPL_render(t,vl);
+ size_t size;
+ char* output = TMPL_render(t,vl,&size);
printf("Output:\n%s\n",output);
/*