StrWriteFmtInternal

Table of Contents

StrWriteFmtInternal

Description

Print out a formatted string with rust-style placeholders to given string o.

Warning

Directly passing literals like 1337 is not supported, especially const char* literals. For constants like integers, booleans, you can use LVAL(r-value) to convert an l-value to an r-value an then use in FMT like LVAL(false)

Parameters

NameDirectionDescription
ooutContents appended to this string.
fmtstrinFormat string with placeholders.
argvinArguments that placeholders will be replaced with.
argcinNumber of arguments.

Success

Placeholders in fmtstr are replaced by passed arguments.

Failure

Does not return, displays log messages.

Usage example (Cross-references)

    }
    
    bool StrWriteFmtInternal(Str *o, const char *fmt, TypeSpecificIO *args, u64 argc) {
    if (!o || !fmt) {
    LOG_FATAL("Invalid arguments");
    TypeSpecificIO *argv_ = &(varr)[0];                                                                            \
    u64             argc_ = sizeof(varr) / sizeof(TypeSpecificIO);                                                 \
    StrWriteFmtInternal((input), (fmtstr), argv_, argc_ - 1);                                                      \
    } while (0)
    u64             argc_ = sizeof(varr) / sizeof(TypeSpecificIO) - 1;                                             \
    Str             out_  = StrInit();                                                                             \
    StrWriteFmtInternal(&out_, (fmtstr), argv_, argc_);                                                            \
    fwrite(out_.data, 1, out_.length, (stream));                                                                   \
    fflush(stream);                                                                                                \
    u64             argc_ = sizeof(varr) / sizeof(TypeSpecificIO) - 1;                                             \
    Str             out_  = StrInit();                                                                             \
    StrWriteFmtInternal(&out_, (fmtstr), argv_, argc_);                                                            \
    fwrite(out_.data, 1, out_.length, (stream));                                                                   \
    fputc('\n', (stream));                                                                                         \

Share :

Related Posts

void

void Description Type-specific write callback signature

Read More

ReadCompleteFile

ReadCompleteFile Description Read complete contents of file at once. Pointer returned is malloc’d and hence must be freed after use. The returned pointer can also be reused by providing pointer to it in data parameter. realloc is called on *data in order to expand it’s size. If *capacity exceeds the size of file to be loaded, then no reallocation is performed. This means the provided buffer will automatically be expanded if required. The returned buffer is null-terminated just-in-case. The implementation and API is designed in such a way that it can be used with containers like Vec and Str.

Read More