StrZ
Description
Short alias for StrInitFromZstr(...) when an owned temporary string is needed inline.
This is most useful with APIs that consume or store the resulting Str, such as:
GraphAddNodeR(&graph, StrZ(“Alpha”));
If ownership is not transferred, the resulting Str must still be deinited manually.
Parameters
| Name | Direction | Description |
|---|---|---|
zstr |
in | Pointer to a null-terminated C string. |
Success
Returns a newly created owned Str.
Failure
Same as StrInitFromZstr(...).
Usage example (Cross-references)
Usage examples (Cross-references)
static GraphNodeId city_add_intersection(CityGraph *graph, CityIndex *index, const char *name) {
GraphNodeId id = GraphAddNodeR(graph, StrZ(name));
MapInsertR(index, name, id);- In
Str.Init.c:76:
// Test StrZ alias
bool test_str_z_alias(void) {
WriteFmt("Testing StrZ\n");
const char *test_str = "Alias Test";- In
Str.Init.c:79:
const char *test_str = "Alias Test";
Str s = StrZ(test_str);
ValidateStr(&s);- In
Graph.Init.c:92:
Str *stored_name;
node_id = GraphAddNodeR(&graph, StrZ("alpha"));
node = GraphGetNode(&graph, node_id);
stored_name = GraphNodeDataPtr(&graph, node);
Last updated on