Skip to content

StrZ

Description

Short alias for StrInitFromZstr. Initialises a Str by value from a NUL-terminated Zstr; 1-arg form uses MisraScope, 2-arg form takes an explicit allocator. Intended for terse call sites such as Foo(StrZ("literal")).

Success

Returns a usable Str holding the bytes of zstr.

Failure

Returns an empty Str on allocator OOM. LOG_FATAL if zstr is NULL.

Usage example (Cross-references)

Usage examples (Cross-references)
        Str        *stored_name;
    
        node_id     = GraphAddNodeR(&graph, StrZ("alpha", &alloc));
        node        = GraphGetNode(&graph, node_id);
        stored_name = GraphNodeDataPtr(&graph, node);
    // Test StrZ alias
    bool test_str_z_alias(void) {
        WriteFmt("Testing StrZ\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Zstr test_str = "Alias Test";
        Str  s        = StrZ(test_str, &alloc);
    
        ValidateStr(&s);
Last updated on