Wed, 02 May 2018 19:16:58 +0200
doc: adds ucx_sprintf() and ucx_bprintf() samples + fixes leftmenu
docs/src/header.html | file | annotate | diff | comparison | revisions | |
docs/src/modules.md | file | annotate | diff | comparison | revisions |
1.1 --- a/docs/src/header.html Wed May 02 18:47:22 2018 +0200 1.2 +++ b/docs/src/header.html Wed May 02 19:16:58 2018 +0200 1.3 @@ -21,17 +21,17 @@ 1.4 <li><a href="modules.html">Modules</a> 1.5 <ul> 1.6 <li><a href="modules.html#allocator">Allocator</a></li> 1.7 - <li><a href="modules.html#avl">AVL Tree</a></li> 1.8 + <li><a href="modules.html#avl-tree">AVL Tree</a></li> 1.9 <li><a href="modules.html#buffer">Buffer</a></li> 1.10 <li><a href="modules.html#list">List</a></li> 1.11 <li><a href="modules.html#logging">Logging</a></li> 1.12 <li><a href="modules.html#map">Map</a></li> 1.13 - <li><a href="modules.html#mempool">Memory Pool</a></li> 1.14 + <li><a href="modules.html#memory-pool">Memory Pool</a></li> 1.15 <li><a href="modules.html#properties">Properties</a></li> 1.16 <li><a href="modules.html#stack">Stack</a></li> 1.17 <li><a href="modules.html#string">String</a></li> 1.18 - <li><a href="modules.html#test">Testing</a></li> 1.19 - <li><a href="modules.html#utils">Utilities</a></li> 1.20 + <li><a href="modules.html#testing">Testing</a></li> 1.21 + <li><a href="modules.html#utilities">Utilities</a></li> 1.22 </ul> 1.23 </li> 1.24 <li><a target="_blank" href="api/index.html">API Reference</a></li>
2.1 --- a/docs/src/modules.md Wed May 02 18:47:22 2018 +0200 2.2 +++ b/docs/src/modules.md Wed May 02 19:16:58 2018 +0200 2.3 @@ -294,4 +294,29 @@ 2.4 } 2.5 ``` 2.6 2.7 +### Automatic allocation for formatted strings 2.8 2.9 +The UCX utility function `ucx_asprintf()` and it's convenient shortcut 2.10 +`ucx_sprintf` allow easy formatting of strings, without ever having to worry 2.11 +about the required space. 2.12 +```C 2.13 +sstr_t mystring = ucx_sprintf("The answer is: %d!", 42); 2.14 +``` 2.15 +Still, you have to pass `mystring.ptr` to `free()` (or the free function of 2.16 +your allocator, if you use `ucx_asprintf`). 2.17 +If you don't have all the information ready to build your string, you can even 2.18 +use a [UcxBuffer](#buffer) as a target with the utility function 2.19 +`ucx_bprintf()`. 2.20 +```C 2.21 +UcxBuffer* strbuffer = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOEXTEND); 2.22 + 2.23 +for (unsigned int i = 2 ; i < 100 ; i++) { 2.24 + ucx_bprintf(strbuffer, "Integer %d is %s\n", 2.25 + i, prime(i) ? "prime" : "not prime"); 2.26 +} 2.27 + 2.28 +// print the result to stdout 2.29 +printf("%s", (char*)strbuffer->space); 2.30 + 2.31 +ucx_buffer_free(strbuffer); 2.32 +```