Skip to content

StrAppendf

StrAppendf

Description

Print and append into given string object with given format.

Parameters

Name Direction Description
str in,out Str to print into.
fmt in Format string, followed by variadic arguments.

Success

str

Failure

NULL

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    Str *StrAppendf(Str *str, const char *fmt, ...) {
        ValidateStr(str);
    // Test StrAppendf function
    bool test_str_appendf(void) {
        WriteFmt("Testing StrAppendf\n");
    
        Str s = StrInitFromZstr("Hello");
    
        // Append formatted string
        StrAppendf(&s, " %s %d", "World", 2023);
    
        // Check that the string was appended correctly
                StrPushBack(&(j), ',');                                                                                    \
            }                                                                                                              \
            StrAppendf(&(j), "\"%s\":", k);                                                                                \
            JW_OBJ(j, writer);                                                                                             \
        } while (0)
                StrPushBack(&(j), ',');                                                                                    \
            }                                                                                                              \
            StrAppendf(&(j), "\"%s\":", k);                                                                                \
            JW_ARR(j, arr, item, writer);                                                                                  \
        } while (0)
        do {                                                                                                               \
            i64 my_int = (i);                                                                                              \
            StrAppendf(&(j), "%lld", my_int);                                                                              \
        } while (0)
                StrPushBack(&(j), ',');                                                                                    \
            }                                                                                                              \
            StrAppendf(&(j), "\"%s\":", k);                                                                                \
            JW_INT(j, i);                                                                                                  \
        } while (0)
        do {                                                                                                               \
            f64 my_flt = (f);                                                                                              \
            StrAppendf(&(j), "%f", my_flt);                                                                                \
        } while (0)
                StrPushBack(&(j), ',');                                                                                    \
            }                                                                                                              \
            StrAppendf(&(j), "\"%s\":", k);                                                                                \
            JW_FLT(j, f);                                                                                                  \
        } while (0)
    #define JW_STR(j, s)                                                                                                   \
        do {                                                                                                               \
            StrAppendf(&(j), "\"%s\"", (s).length ? (s).data : "");                                                        \
        } while (0)
                StrPushBack(&(j), ',');                                                                                    \
            }                                                                                                              \
            StrAppendf(&(j), "\"%s\":", k);                                                                                \
            JW_STR(j, s);                                                                                                  \
        } while (0)
    #define JW_BOOL(j, b)                                                                                                  \
        do {                                                                                                               \
            StrAppendf(&(j), "%s", (b) ? "true" : "false");                                                                \
        } while (0)
                StrPushBack(&(j), ',');                                                                                    \
            }                                                                                                              \
            StrAppendf(&(j), "\"%s\":", k);                                                                                \
            JW_BOOL(j, b);                                                                                                 \
        } while (0)
Last updated on