Skip to content

StrInit

StrInit

Description

Initialize given string.

str : Pointer to string memory that needs to be initialized.

Success

str

Failure

NULL

Usage example (Cross-references)

Usage examples (Cross-references)
    
    void init_str(Str *str) {
        *str = StrInit();
    }
                // Reinitialize the string
                StrDeinit(str);
                *str = StrInit();
                break;
            }
            case STR_DEINIT : {
                StrDeinit(str);
                *str = StrInit(); // Reinitialize for continued fuzzing
                break;
            }
    
        // Create Str with capacity
        Str str = StrInit();
    
        // Fill with data or generate simple pattern if not enough input
        getenv_s(&requiredSize, env_var, requiredSize, name);
    
        *value          = StrInit();
        value->data     = env_var;
        value->length   = requiredSize;
        }
    
        Str buffer = StrInit();
        int fd     = FILENO(file);
    
        {
            Str         result = StrInit();
            const char *body   = canonical.data;
            const char *dot    = NULL;
    static Str FloatFmtToScientificStr(Float *value, u32 precision, bool has_precision, bool uppercase) {
        Str digits = IntToStr(&value->significand);
        Str result = StrInit();
        u64 frac_digits = 0;
        i64 exponent    = 0;
                    }
                    // Create hex string for each character
                    Str hex = StrInit();
                    StrFromU64(&hex, c, &config);
                    // Ensure 2 digits with leading zero
                    }
                    // Create hex string for each character
                    Str          hex    = StrInit();
                    StrIntFormat config = {.base = 16, .uppercase = (fmt_info->flags & FMT_FLAG_CAPS) != 0};
                    StrFromU64(&hex, (u8)xs[i], &config);
    
        // Create temporary buffer for number formatting
        Str temp = StrInit();
    
        // Determine base based on format flags
    
        // Create temporary buffer for number formatting
        Str temp = StrInit();
    
        // Determine base based on format flags
            // Normal case - use StrFromF64
            // Create temporary buffer for number formatting
            Str temp = StrInit();
    
            // Use StrFromF64 directly with the appropriate parameters
    void _write_Float(Str *o, FmtInfo *fmt_info, Float *value) {
        size start_len = 0;
        Str  temp      = StrInit();
    
        if (!o || !fmt_info || !value) {
    
        // For string types, :c has no effect - work like regular string reading
        Str         temp        = StrInit();
        FmtInfo     default_fmt = {.align = ALIGN_RIGHT, .width = 0, .precision = 6, .flags = FMT_FLAG_NONE};
        const char *next        = _read_Str(i, &default_fmt, &temp);
    
        size start_len = o->length;
        Str  temp      = StrInit();
        u8   radix     = IntFmtRadixFromFlags(fmt_info);
        size        token_len = 0;
        const char *start     = NULL;
        Str         temp      = StrInit();
        Float       parsed    = FloatInit();
    
            // Get path to temp directory
            Str log_dir = StrInit();
            if (!SysGetEnv("TMP", &log_dir) && !SysGetEnv("TEMP", &log_dir) && !SysGetEnv("TMPDIR", &log_dir) &&
                !SysGetEnv("TEMPDIR", &log_dir) && !SysGetEnv("PWD", &log_dir)) {
    
            // generate log file name
            Str file_name = StrInit();
            StrWriteFmt(&file_name, "{}/misra-{}-{}", log_dir, SysGetCurrentProcessId(), &time_buffer[0]);
            FWriteFmtLn(stderr, "storing logs in {}", file_name.data);
    
        MemSet(dst, 0, sizeof(Str));
        *dst             = StrInit();
        dst->copy_init   = src->copy_init;
        dst->copy_deinit = src->copy_deinit;
            FREE(copy->data);
        }
        *copy = StrInit();
    }
    
        // Create substring without sign
        Str temp_str      = StrInit();
        temp_str.data     = str->data + pos;
        temp_str.length   = str->length - pos;
    Float FloatFromStr(const char *text) {
        Float result          = FloatInit();
        Str   digits          = StrInit();
        size  pos             = 0;
        bool  negative        = false;
    
    Str FloatToStr(Float *value) {
        Str digits = StrInit();
        Str result = StrInit();
    Str FloatToStr(Float *value) {
        Str digits = StrInit();
        Str result = StrInit();
    
        ValidateFloat(value);
    
        Int current   = IntClone(value);
        Str result    = StrInit();
    
        while (!IntIsZero(&current)) {
        ValidateBitVec(bv);
    
        Str result = StrInit();
        if (bv->length == 0) {
            return result;
    
        while (StrIterRemainingLength(&si)) {
            Str     key   = StrInit();
            Str     value = StrInit();
            StrIter read_si;
        while (StrIterRemainingLength(&si)) {
            Str     key   = StrInit();
            Str     value = StrInit();
            StrIter read_si;
    
        if (!value) {
            return StrInit();
        }
            }
    
            Str key = StrInit();
    
            // key start
        StrIter saved_si = si;
        si               = JSkipWhitespace(si);
        Str ns           = StrInit();
    
        bool is_neg = false;
        if (StrIterPeek(&si) == '"') {
            StrIter before_si = si;
            Str     s         = StrInit();
            si                = JReadString(si, &s);
            StrDeinit(&s);
    
        // Build command line
        Str cmdline = StrInit();
        StrPushBackZstr(&cmdline, filepath);
        for (char **arg = argv + 1; *arg; ++arg) {
                continue;
            } else {
                Str         entry_path = StrInit();
                const char *dir_name   = &entry->d_name[0];
                StrWriteFmt(&entry_path, "{}/{}", path, dir_name);
                    JR_STR_KV(json, "build_dir", p.build_dir);                                                             \
                    JR_ARR_KV(json, "test_directories", {                                                                  \
                        Str s = StrInit();                                                                                 \
                        JR_STR(json, s);                                                                                   \
                        VecPushBack(&p.test_directories, s);                                                               \
                    });                                                                                                    \
                    JR_ARR_KV(json, "source_directories", {                                                                \
                        Str s = StrInit();                                                                                 \
                        JR_STR(json, s);                                                                                   \
                        VecPushBack(&p.source_directories, s);                                                             \
        Scope(&project, ProjectDeinit, {
            // read project config
            Str config = StrInit();
            Scope(&config, StrDeinit, {
                if (!ReadCompleteFile(config_path, &config.data, &config.length, &config.capacity)) {
                    VecForeach(&dir_paths, dir_name) {
                        // keep track of current path we're exploring
                        Str current_path = StrInit();
                        StrMerge(&current_path, &dir_name);
                                if (dir_entry.type == SYS_DIR_ENTRY_TYPE_DIRECTORY) {
                                    // create new directory path relative to current directory search path
                                    Str path = StrInit();
                                    StrMerge(&path, &current_path);
                                    StrPushBack(&path, '/');
                    else if (dir_entry.type == SYS_DIR_ENTRY_TYPE_REGULAR_FILE) {
                        // create complete relative file path
                        Str path = StrInit();
                        StrMerge(&path, &current_path);
                        StrPushBack(&path, '/');
    // go over each file and generate corresponding markdown
    VecForeach(&file_paths, file_path) {
        Str file_contents = StrInit();
        Scope(&file_contents, StrDeinit, {
            if (!ReadCompleteFile(file_path.data, &file_contents.data, &file_contents.length, &file_contents.capacity)) {
            }
    
            Str output_path = StrInit();
            Scope(&output_path, StrDeinit, {
                StrMerge(&output_path, &file_path);
                LOG_INFO("{}", output_path);
    
                Str md_code = StrInit();
                Scope(&md_code, StrDeinit, {
                    // Create template strings for StrWriteFmt with escaped braces
        }
    
        Str code = StrInit();
        ReadCompleteFile(input_filename, &code.data, &code.length, &code.capacity);
    
        StrIter json        = StrIterFromStr(code);
        Str     enum_name   = StrInit();
        bool    to_from_str = false;
    
    int main(void) {
        Str file = StrInit();
        if (ReadCompleteFile("Bin/Demangler/CppNameManglingGrammar", &file.data, &file.length, &file.capacity)) {
            Strs lines = StrSplit(&file, "\n");
            VecForeachPtr(&lines, line) {
                if (StrStartsWithZstr(line, "[.") && StrEndsWithZstr(line, "]")) {
                    Str rule_name = StrInit();
                    StrReadFmt(line->data, "[.{}]", rule_name);
        Str      src         = StrInitFromZstr("host = localhost\n");
        StrIter  input       = StrIterFromStr(src);
        Str      host_copy   = StrInit();
        Str     *stored_host = NULL;
        bool     result      = true;
    bool compare_json_output(const Str *output, const char *expected) {
        Str expected_str   = StrInitFromZstr(expected);
        Str output_clean   = StrInit();
        Str expected_clean = StrInit();
        Str expected_str   = StrInitFromZstr(expected);
        Str output_clean   = StrInit();
        Str expected_clean = StrInit();
    
        // Remove whitespace from both strings for comparison
    
        bool success = true;
        Str  json    = StrInit();
    
        struct {
    
        bool success = true;
        Str  json    = StrInit();
    
        struct {
    
        bool success = true;
        Str  json    = StrInit();
    
        ApiResponse response = {true, StrInitFromZstr("Success"), VecInitWithDeepCopy(NULL, AnnSymbolDeinit)};
            JW_OBJ_KV(json, "data", {
                // Write dynamic key for source function ID
                Str source_key = StrInit();
                u64 source_id  = response.data.length > 0 ? VecAt(&response.data, 0).source_function_id : 0;
                StrWriteFmt(&source_key, "{}", source_id);
                    if (response.data.length > 0) {
                        AnnSymbol *s          = &VecAt(&response.data, 0);
                        Str        target_key = StrInit();
                        StrWriteFmt(&target_key, "{}", s->target_function_id);
    
        bool success = true;
        Str  json    = StrInit();
    
        Vec(FunctionInfo) functions = VecInitWithDeepCopy(NULL, FunctionInfoDeinit);
    
        bool success = true;
        Str  json    = StrInit();
    
        SearchResult result = {0};
    
        bool success = true;
        Str  json    = StrInit();
    
        Vec(AnnSymbol) symbols = VecInitWithDeepCopy(NULL, AnnSymbolDeinit);
            JW_OBJ_KV(json, "functions", {
                VecForeach(&symbols, symbol) {
                    Str source_key = StrInit();
                    StrWriteFmt(&source_key, "{}", symbol.source_function_id);
    
                    JW_OBJ_KV(json, source_key.data, {
                Str target_key = StrInit();
                StrWriteFmt(&target_key, "{}", symbol.target_function_id);
    
        bool success = true;
        Str  json    = StrInit();
    
        // Create strings for the nested structure
    
        bool success = true;
        Str  json    = StrInit();
    
        Vec(u32) numbers = VecInit();
        StrIter si      = StrIterFromStr(json);
    
        Str name = StrInit();
        Str city = StrInit();
    
        Str name = StrInit();
        Str city = StrInit();
    
        JR_OBJ(si, {
    
        Person person = {0};
        person.name   = StrInit();
    
        JR_OBJ(si, {
    
        Config config    = {0};
        config.log_level = StrInit();
    
        JR_OBJ(si, {
        JR_OBJ(si, {
            JR_ARR_KV(si, "languages", {
                Str lang = StrInit();
                JR_STR(si, lang);
                VecPushBack(&languages, lang);
            bool active;
        } data = {
            {StrInit(), StrInit()},
            false
        };
    
        SimpleProduct product = {0};
        product.name          = StrInit();
        product.tags          = VecInitWithDeepCopyT(product.tags, NULL, StrDeinit);
            JR_FLT_KV(si, "price", product.price);
            JR_ARR_KV(si, "tags", {
                Str tag = StrInit();
                JR_STR(si, tag);
                VecPushBack(&product.tags, tag);
            bool active;
            f64  score;
        } data = {0, StrInit(), false, 0.0};
    
        JR_OBJ(si, {
            Str status;
        } data = {
            {0, {StrInit(), 0}},
            StrInit()
        };
        } data = {
            {0, {StrInit(), 0}},
            StrInit()
        };
            } company;
        } data = {
            {{{StrInit(), 0, 0.0}}, StrInit()}
        };
                    // Properly initialize all Str fields
                    AnnSymbol sym             = {0};
                    sym.analysis_name         = StrInit();
                    sym.function_name         = StrInit();
                    sym.sha256                = StrInit();
                    AnnSymbol sym             = {0};
                    sym.analysis_name         = StrInit();
                    sym.function_name         = StrInit();
                    sym.sha256                = StrInit();
                    sym.function_mangled_name = StrInit();
                    sym.analysis_name         = StrInit();
                    sym.function_name         = StrInit();
                    sym.sha256                = StrInit();
                    sym.function_mangled_name = StrInit();
                    sym.source_function_id    = source_function_id;
                    sym.function_name         = StrInit();
                    sym.sha256                = StrInit();
                    sym.function_mangled_name = StrInit();
                    sym.source_function_id    = source_function_id;
                    sym.target_function_id    = target_function_id;
        StrIter si = StrIterFromStr(json);
    
        ApiResponse response = {false, StrInit(), VecInitWithDeepCopy(NULL, AnnSymbolDeinit)};
    
        JR_OBJ(si, {
                        // Properly initialize all Str fields
                        AnnSymbol sym             = {0};
                        sym.analysis_name         = StrInit();
                        sym.function_name         = StrInit();
                        sym.sha256                = StrInit();
                        AnnSymbol sym             = {0};
                        sym.analysis_name         = StrInit();
                        sym.function_name         = StrInit();
                        sym.sha256                = StrInit();
                        sym.function_mangled_name = StrInit();
                        sym.analysis_name         = StrInit();
                        sym.function_name         = StrInit();
                        sym.sha256                = StrInit();
                        sym.function_mangled_name = StrInit();
                        sym.source_function_id    = source_function_id;
                        sym.function_name         = StrInit();
                        sym.sha256                = StrInit();
                        sym.function_mangled_name = StrInit();
                        sym.source_function_id    = source_function_id;
                        sym.target_function_id    = strtoull(key.data, NULL, 10);
    
        FunctionInfo info = {0};
        info.name         = StrInit();
    
        JR_OBJ(si, {
    
        ModelInfo info = {0};
        info.name      = StrInit();
    
        JR_OBJ(si, {
    
        SearchResult result = {0};
        result.binary_name  = StrInit();
        result.sha256       = StrInit();
        result.tags         = VecInitWithDeepCopyT(result.tags, NULL, StrDeinit);
        SearchResult result = {0};
        result.binary_name  = StrInit();
        result.sha256       = StrInit();
        result.tags         = VecInitWithDeepCopyT(result.tags, NULL, StrDeinit);
        result.created_at   = StrInit();
        result.sha256       = StrInit();
        result.tags         = VecInitWithDeepCopyT(result.tags, NULL, StrDeinit);
        result.created_at   = StrInit();
        result.model_name   = StrInit();
        result.owned_by     = StrInit();
        result.tags         = VecInitWithDeepCopyT(result.tags, NULL, StrDeinit);
        result.created_at   = StrInit();
        result.model_name   = StrInit();
        result.owned_by     = StrInit();
        result.created_at   = StrInit();
        result.model_name   = StrInit();
        result.owned_by     = StrInit();
    
        JR_OBJ(si, {
        StrIter si = StrIterFromStr(json);
    
        ApiResponse response = {false, StrInit(), VecInitWithDeepCopy(NULL, AnnSymbolDeinit)};
    
        WriteFmt("[DEBUG] About to parse JSON...\n");
                        // Properly initialize all Str fields
                        AnnSymbol sym             = {0};
                        sym.analysis_name         = StrInit();
                        sym.function_name         = StrInit();
                        sym.sha256                = StrInit();
                        AnnSymbol sym             = {0};
                        sym.analysis_name         = StrInit();
                        sym.function_name         = StrInit();
                        sym.sha256                = StrInit();
                        sym.function_mangled_name = StrInit();
                        sym.analysis_name         = StrInit();
                        sym.function_name         = StrInit();
                        sym.sha256                = StrInit();
                        sym.function_mangled_name = StrInit();
                        sym.source_function_id    = source_function_id;
                        sym.function_name         = StrInit();
                        sym.sha256                = StrInit();
                        sym.function_mangled_name = StrInit();
                        sym.source_function_id    = source_function_id;
                        sym.target_function_id    = strtoull(key.data, NULL, 10);
        StrIter si = StrIterFromStr(json);
    
        ApiResponse response = {false, StrInit(), VecInitWithDeepCopy(NULL, AnnSymbolDeinit)};
    
        WriteFmt("[DEBUG] About to parse JSON...\n");
                        // Properly initialize all Str fields
                        AnnSymbol sym             = {0};
                        sym.analysis_name         = StrInit();
                        sym.function_name         = StrInit();
                        sym.sha256                = StrInit();
                        AnnSymbol sym             = {0};
                        sym.analysis_name         = StrInit();
                        sym.function_name         = StrInit();
                        sym.sha256                = StrInit();
                        sym.function_mangled_name = StrInit();
                        sym.analysis_name         = StrInit();
                        sym.function_name         = StrInit();
                        sym.sha256                = StrInit();
                        sym.function_mangled_name = StrInit();
                        sym.source_function_id    = source_function_id;
                        sym.function_name         = StrInit();
                        sym.sha256                = StrInit();
                        sym.function_mangled_name = StrInit();
                        sym.source_function_id    = source_function_id;
                        sym.target_function_id    = strtoull(key.data, NULL, 10);
        // Create a copy of expected without spaces for comparison
        Str expected_str   = StrInitFromZstr(expected);
        Str output_clean   = StrInit();
        Str expected_clean = StrInit();
        Str expected_str   = StrInitFromZstr(expected);
        Str output_clean   = StrInit();
        Str expected_clean = StrInit();
    
        // Remove spaces and newlines from both strings for comparison
    
        bool success = true;
        Str  json    = StrInit();
    
        // Write completely empty object
    
        bool success = true;
        Str  json    = StrInit();
    
        Vec(i32) empty_numbers = VecInit();
    
        bool success = true;
        Str  json    = StrInit();
    
        Str empty_name = StrInit();
        Str  json    = StrInit();
    
        Str empty_name = StrInit();
        Str empty_desc = StrInit();
    
        Str empty_name = StrInit();
        Str empty_desc = StrInit();
    
        JW_OBJ(json, {
    
        bool success = true;
        Str  json    = StrInit();
    
        i32 temp    = -25;
    
        bool success = true;
        Str  json    = StrInit();
    
        i64 big_int     = 9223372036854775807LL;
    
        bool success = true;
        Str  json    = StrInit();
    
        i32  int_zero   = 0;
    
        bool success = true;
        Str  json    = StrInit();
    
        // Note: These are the actual characters, not escape sequences
    
        bool success = true;
        Str  json    = StrInit();
    
        // These contain actual special characters that should be escaped
    
        bool success = true;
        Str  json    = StrInit();
    
        Vec(i32) empty_list = VecInit();
    
        bool success = true;
        Str  json    = StrInit();
    
        Vec(i32) empty_arr  = VecInit();
    
        bool success = true;
        Str  json    = StrInit();
    
        i64 max_int   = 2147483647LL;
    
        bool success = true;
        Str  json    = StrInit();
    
        f64 tiny          = 0.000001;
    
        bool success = true;
        Str  json1   = StrInit();
        Str  json2   = StrInit();
        Str  json3   = StrInit();
        bool success = true;
        Str  json1   = StrInit();
        Str  json2   = StrInit();
        Str  json3   = StrInit();
        Str  json4   = StrInit();
        Str  json1   = StrInit();
        Str  json2   = StrInit();
        Str  json3   = StrInit();
        Str  json4   = StrInit();
        Str  json2   = StrInit();
        Str  json3   = StrInit();
        Str  json4   = StrInit();
    
        // Single integer
        // Create a copy of expected without spaces for comparison
        Str expected_str   = StrInitFromZstr(expected);
        Str output_clean   = StrInit();
        Str expected_clean = StrInit();
        Str expected_str   = StrInitFromZstr(expected);
        Str output_clean   = StrInit();
        Str expected_clean = StrInit();
    
        // Remove spaces and newlines from both strings for comparison
    
        bool success = true;
        Str  json    = StrInit();
    
        Str name = StrInitFromZstr("Alice");
    
        bool success = true;
        Str  json    = StrInit();
    
        u32 count = 42;
    
        bool success = true;
        Str  json    = StrInit();
    
        bool enabled = true;
    
        bool success = true;
        Str  json    = StrInit();
    
        Person person = {1001, StrInitFromZstr("Bob"), 25, true, 50000.0};
    
        bool success = true;
        Str  json    = StrInit();
    
        Config config = {false, 30, StrInitFromZstr("INFO")};
    
        bool success = true;
        Str  json    = StrInit();
    
        Vec(Str) languages = VecInitWithDeepCopy(NULL, StrDeinit);
    
        bool success = true;
        Str  json    = StrInit();
    
        struct {
    
        bool success = true;
        Str  json    = StrInit();
    
        SimpleProduct product = {0};
    
        // Write to JSON
        Str json = StrInit();
        JW_OBJ(json, {
            JW_INT_KV(json, "count", original.count);
            bool enabled;
            Str  message;
        } parsed = {0, 0.0, false, StrInit()};
    
        StrIter si = StrIterFromStr(json);
    
        // Write to JSON
        Str json = StrInit();
        JW_OBJ(json, {
            JW_INT_KV(json, "big_int", original.big_int);
    
        // Write to JSON
        Str json = StrInit();
        JW_OBJ(json, {
            JW_BOOL_KV(json, "flag1", original.flag1);
            Str with_special;
        } original = {
            StrInit(),
            StrInitFromZstr("hello"),
            StrInitFromZstr("hello world with spaces"),
    
        // Write to JSON
        Str json = StrInit();
        JW_OBJ(json, {
            JW_STR_KV(json, "empty", original.empty);
            Str with_spaces;
            Str with_special;
        } parsed = {StrInit(), StrInit(), StrInit(), StrInit()};
    
        StrIter si = StrIterFromStr(json);
    
        // Write to JSON
        Str json = StrInit();
        JW_OBJ(json, {
            JW_ARR_KV(json, "numbers", original_numbers, num, { JW_INT(json, num); });
            });
            JR_ARR_KV(si, "strings", {
                Str str = StrInit();
                JR_STR(si, str);
                VecPushBack(&parsed_strings, str);
    
        // Write to JSON
        Str json = StrInit();
        JW_OBJ(json, {
            JW_OBJ_KV(json, "user", {
    
        // Read back from JSON
        TestPerson parsed_person = {0, StrInit(), 0, false, 0.0};
    
        StrIter si = StrIterFromStr(json);
    
        // Write to JSON
        Str json = StrInit();
        JW_OBJ(json, {
            JW_OBJ_KV(json, "user", {
        // Read back from JSON
        ComplexData parsed       = {0};
        parsed.user              = (TestPerson) {0, StrInit(), 0, false, 0.0};
        parsed.config.debug_mode = true; // opposite of original
        parsed.config.timeout    = 0;
        parsed.config.debug_mode = true; // opposite of original
        parsed.config.timeout    = 0;
        parsed.config.log_level  = StrInit();
        parsed.config.features   = VecInitWithDeepCopyT(parsed.config.features, NULL, StrDeinit);
        parsed.numbers           = VecInitT(parsed.numbers);
                JR_STR_KV(si, "log_level", parsed.config.log_level);
                JR_ARR_KV(si, "features", {
                    Str feature = StrInit();
                    JR_STR(si, feature);
                    VecPushBack(&parsed.config.features, feature);
        Vec(i32) empty_numbers = VecInit();
        Vec(Str) empty_strings = VecInitWithDeepCopy(NULL, StrDeinit);
        Str empty_str          = StrInit();
    
        // Write to JSON
    
        // Write to JSON
        Str json = StrInit();
        JW_OBJ(json, {
            JW_STR_KV(json, "empty_string", empty_str);
        Vec(i32) parsed_numbers = VecInit();
        Vec(Str) parsed_strings = VecInitWithDeepCopy(NULL, StrDeinit);
        Str  parsed_str         = StrInit();
        bool found_empty_object = false;
            });
            JR_ARR_KV(si, "empty_strings", {
                Str str = StrInit();
                JR_STR(si, str);
                VecPushBack(&parsed_strings, str);
    
        // Write to JSON
        Str json = StrInit();
        JW_OBJ(json, {
            JW_INT_KV(json, "max_int", original.max_int);
        JR_OBJ(si2, {
            JR_ARR_KV(si2, "data", {
                Str value = StrInit();
                JR_STR(si2, value);
                VecPushBack(&data, value);
            Str name;
            Str description;
        } obj = {StrInit(), StrInit()};
    
        JR_OBJ(si, {
            Str message;
            Str data;
        } obj = {StrInit(), StrInit(), StrInit()};
    
        JR_OBJ(si, {
            Str newline;
            Str tab;
        } obj = {StrInit(), StrInit(), StrInit(), StrInit()};
    
        JR_OBJ(si, {
            i32  value;
            bool flag;
        } obj = {StrInit(), 0, false};
    
        JR_OBJ(si, {
    
        Float value = FloatFromStr("12.5");
        Str   text  = StrInit();
    
        FloatNegate(&value);
        Float b            = FloatFromStr("0.03");
        Float result_value = FloatInit();
        Str   text         = StrInit();
    
        FloatAdd(&result_value, &a, &b);
        Float b            = FloatFromStr(FLOAT_TEST_VERY_LARGE_TWOS);
        Float result_value = FloatInit();
        Str   text         = StrInit();
    
        FloatAdd(&result_value, &a, &b);
        Int   whole        = IntFrom(2);
        Float result_value = FloatInit();
        Str   text         = StrInit();
    
        FloatAdd(&result_value, &a, b);
        Float b            = FloatFromStr("2");
        Float result_value = FloatInit();
        Str   text         = StrInit();
    
        FloatSub(&result_value, &a, &b);
        Float b            = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES);
        Float result_value = FloatInit();
        Str   text         = StrInit();
    
        FloatSub(&result_value, &a, &b);
        Int   whole        = IntFrom(2);
        Float result_value = FloatInit();
        Str   text         = StrInit();
    
        FloatSub(&result_value, &a, b);
        Float b            = FloatFromStr("-0.2");
        Float result_value = FloatInit();
        Str   text         = StrInit();
    
        FloatMul(&result_value, &a, &b);
        Float b            = FloatFromStr("2");
        Float result_value = FloatInit();
        Str   text         = StrInit();
    
        FloatMul(&result_value, &a, &b);
        Int   whole        = IntFrom(2);
        Float result_value = FloatInit();
        Str   text         = StrInit();
    
        FloatMul(&result_value, &a, b);
        Float b            = FloatFromStr("8");
        Float result_value = FloatInit();
        Str   text         = StrInit();
    
        FloatDiv(&result_value, &a, &b, 3);
        Float b            = FloatFromStr("2");
        Float result_value = FloatInit();
        Str   text         = StrInit();
    
        FloatDiv(&result_value, &a, &b, 0);
        Int   whole        = IntFrom(3);
        Float result_value = FloatInit();
        Str   text         = StrInit();
    
        FloatDiv(&result_value, &a, b, 1);
    
        // Test basic string reading
        Str s = StrInit();
        z     = "Hello";
        StrReadFmt(z, "{}", s);
    
        i32 num  = 0;
        Str name = StrInit();
        z        = "Count: 42, Name: Alice";
        StrReadFmt(z, "Count: {}, Name: {}", num, name);
        success = success && abc_pass;
    
        Str str_val = StrInit();
        z           = "Hello";
        StrReadFmt(z, "{c}", str_val);
        StrDeinit(&str_val);
    
        str_val = StrInit();
        z       = "\"World\"";
        StrReadFmt(z, "{cs}", str_val);
        // Test 1: :a (lowercase) conversion
        {
            Str         result = StrInit();
            const char *in     = "Hello World";
        // Test 1.1: :a (lowercase) conversion
        {
            Str         result = StrInit();
            const char *in     = "Hello World";
        // Test 2: :A (uppercase) conversion
        {
            Str         result = StrInit();
            const char *in     = "hello world";
        // Test 2.1: :A (uppercase) conversion
        {
            Str         result1 = StrInit();
            Str         result2 = StrInit();
            const char *in      = "hello world";
        {
            Str         result1 = StrInit();
            Str         result2 = StrInit();
            const char *in      = "hello world";
        // Test 2.2: :A (uppercase) conversion
        {
            Str         result1 = StrInit();
            Str         result2 = StrInit();
            const char *in      = "hello world mighty misra";
        {
            Str         result1 = StrInit();
            Str         result2 = StrInit();
            const char *in      = "hello world mighty misra";
        // Test 3: :a with quoted string
        {
            Str         result = StrInit();
            const char *in     = "\"MiXeD CaSe\"";
        // Test 4: :A with quoted string containing special characters
        {
            Str         result = StrInit();
            const char *in     = "\"abc123XYZ\"";
        // Test 5: Regular :c format (no case conversion) for comparison
        {
            Str         result = StrInit();
            const char *in     = "Hello World";
        Int oct = IntInit();
    
        Str dec_text = StrInit();
        Str hex_text = StrInit();
        Str bin_text = StrInit();
    
        Str dec_text = StrInit();
        Str hex_text = StrInit();
        Str bin_text = StrInit();
        Str oct_text = StrInit();
        Str dec_text = StrInit();
        Str hex_text = StrInit();
        Str bin_text = StrInit();
        Str oct_text = StrInit();
        Str hex_text = StrInit();
        Str bin_text = StrInit();
        Str oct_text = StrInit();
    
        z = "123456789012345678901234567890";
        Float neg = FloatInit();
    
        Str dec_text = StrInit();
        Str sci_text = StrInit();
        Str neg_text = StrInit();
    
        Str dec_text = StrInit();
        Str sci_text = StrInit();
        Str neg_text = StrInit();
        Str dec_text = StrInit();
        Str sci_text = StrInit();
        Str neg_text = StrInit();
    
        z = "1234567890.012345";
    
        // Create a Str object
        Str s = StrInit();
    
        // Check that it behaves like a Vec of chars
    
        // Create a valid Str
        Str s = StrInit();
    
        // This should not crash
    
        // Create an invalid Str by corrupting its fields
        Str s = StrInit();
    
        // Corrupt the string to make it invalid
        WriteFmt("Testing basic formatting\n");
    
        Str  output  = StrInit();
        bool success = true;
        WriteFmt("Testing string formatting\n");
    
        Str  output  = StrInit();
        bool success = true;
        WriteFmt("Testing integer decimal formatting\n");
    
        Str  output  = StrInit();
        bool success = true;
        WriteFmt("Testing integer hexadecimal formatting\n");
    
        Str  output  = StrInit();
        bool success = true;
        WriteFmt("Testing integer binary formatting\n");
    
        Str  output  = StrInit();
        bool success = true;
        WriteFmt("Testing integer octal formatting\n");
    
        Str  output  = StrInit();
        bool success = true;
        WriteFmt("Testing basic floating point formatting\n");
    
        Str  output  = StrInit();
        bool success = true;
        WriteFmt("Testing floating point precision formatting\n");
    
        Str  output  = StrInit();
        bool success = true;
        WriteFmt("Testing special floating point values\n");
    
        Str  output  = StrInit();
        bool success = true;
        WriteFmt("Testing width and alignment formatting\n");
    
        Str  output  = StrInit();
        bool success = true;
        WriteFmt("Testing multiple arguments\n");
    
        Str  output  = StrInit();
        bool success = true;
        WriteFmt("Testing character formatting specifiers\n");
    
        Str  output  = StrInit();
        bool success = true;
        WriteFmt("Testing BitVec formatting\n");
    
        Str  output  = StrInit();
        bool success = true;
        WriteFmt("Testing Int formatting\n");
    
        Str  output  = StrInit();
        bool success = true;
        WriteFmt("Testing Float formatting\n");
    
        Str   output  = StrInit();
        bool  success = true;
        Float exact   = FloatFromStr("1234567890.012345");
    
        // Build a new string by iterating through each character with its index
        Str result = StrInit();
        StrForeachIdx(&s, chr, idx) {
            StrWriteFmt(&result, "{c}{}", chr, idx);
    
        // Build a new string by iterating through each character in reverse with its index
        Str result = StrInit();
    
        StrForeachReverseIdx(&s, chr, idx) {
    
        // Build a new string by iterating through each character pointer with its index
        Str result = StrInit();
        StrForeachPtrIdx(&s, chrptr, idx) {
            // Append the character (via pointer) and its index to the result string
    
        // Build a new string by iterating through each character pointer in reverse with its index
        Str result = StrInit();
    
        StrForeachReversePtrIdx(&s, chrptr, idx) {
    
        // Build a new string by iterating through each character
        Str result = StrInit();
        StrForeach(&s, chr) {
            // Append the character to the result string
    
        // Build a new string by iterating through each character in reverse
        Str  result     = StrInit();
        size char_count = 0;
    
        // Build a new string by iterating through each character pointer
        Str result = StrInit();
        StrForeachPtr(&s, chrptr) {
            // Append the character (via pointer) to the result string
    
        // Build a new string by iterating through each character pointer in reverse
        Str  result     = StrInit();
        size char_count = 0;
    
        // Build a new string by iterating through a range of characters with indices
        Str result = StrInit();
        StrForeachInRangeIdx(&s, chr, idx, 6, 11) {
            // Append the character and its index to the result string
    
        // Test with empty range
        Str empty_result = StrInit();
        StrForeachInRangeIdx(&s, chr, idx, 3, 3) {
            // This block should not execute
    
        // Build a new string by iterating through a range of characters
        Str result = StrInit();
        StrForeachInRange(&s, chr, 0, 5) {
            // Append the character to the result string
    
        // Test with range at the end of the string
        Str end_result = StrInit();
        StrForeachInRange(&s, chr, 6, 11) {
            // Append the character to the result string
    
        // Build a new string by iterating through a range of character pointers with indices
        Str result = StrInit();
        StrForeachPtrInRangeIdx(&s, chrptr, idx, 6, 11) {
            // Append the character and its index to the result string
    
        // Build a new string by iterating through a range of character pointers
        Str result = StrInit();
        StrForeachPtrInRange(&s, chrptr, 0, 5) {
            // Append the character to the result string
        WriteFmt("Testing StrFromU64\n");
    
        Str s = StrInit();
    
        // Test decimal conversion
        WriteFmt("Testing StrFromI64\n");
    
        Str s = StrInit();
    
        // Test positive decimal conversion
        WriteFmt("Testing StrFromF64\n");
    
        Str s = StrInit();
    
        // Test integer conversion
    
        for (size_t i = 0; i < sizeof(u64_values) / sizeof(u64_values[0]); i++) {
            Str s = StrInit();
    
            // Test decimal round-trip
    
        for (size_t i = 0; i < sizeof(i64_values) / sizeof(i64_values[0]); i++) {
            Str s = StrInit();
    
            // Test decimal round-trip
        for (size_t i = 0; i < sizeof(f64_values) / sizeof(f64_values[0]); i++) {
            for (u8 precision = 1; precision <= 6; precision++) {
                Str s = StrInit();
    
                StrFloatFormat config = {.precision = precision, .force_sci = false, .uppercase = false};
        // Test base boundary conditions
        for (u8 base = 2; base <= 36; base++) {
            Str s = StrInit();
    
            // Test with base value itself
    
        // Test extreme values
        Str s = StrInit();
    
        // Test maximum u64
    
        for (u8 precision = 1; precision <= 17; precision++) {
            Str s = StrInit();
    
            StrFloatFormat config = {.precision = precision, .force_sci = false, .uppercase = false};
    
        for (size_t i = 0; i < sizeof(sci_values) / sizeof(sci_values[0]); i++) {
            Str s = StrInit();
    
            // Force scientific notation
    
        for (u8 base = 2; base <= 36; base++) {
            Str s = StrInit();
    
            StrIntFormat config = {.base = base, .uppercase = false};
        // Test each base from 2 to 36
        for (u8 base = 2; base <= 36; base++) {
            Str s = StrInit();
    
            // Test StrFromU64
        // Test uppercase digits for bases that use letters (11-36)
        for (u8 base = 11; base <= 36; base++) {
            Str s = StrInit();
    
            StrIntFormat config = {.base = base, .uppercase = true, .use_prefix = false};
        for (size_t i = 0; i < sizeof(test_values) / sizeof(test_values[0]); i++) {
            for (u8 base = 2; base <= 36; base++) {
                Str s = StrInit();
    
                StrIntFormat config = {.base = base, .uppercase = false, .use_prefix = false};
            u64 test_value = i * 1000007; // Large prime multiplier
    
            Str          s      = StrInit();
            StrIntFormat config = {.base = 10, .uppercase = false};
            StrFromU64(&s, test_value, &config);
                f64 test_value = mantissa * pow(10.0, exp);
    
                Str            s      = StrInit();
                StrFloatFormat config = {.precision = 6, .force_sci = false, .uppercase = false};
                StrFromF64(&s, test_value, &config);
        WriteFmt("Testing StrTryReduceSpace\n");
    
        Str s = StrInit();
    
        // Reserve more space than needed
        WriteFmt("Testing StrReserve\n");
    
        Str s = StrInit();
    
        // Reserve more space
        // Test with an empty string
        StrDeinit(&s);
        s = StrInit();
    
        // Reverse the string
        Float value        = FloatFromStr("1234500e-2");
        Int   result_value = IntInit();
        Str   text         = StrInit();
    
        bool result = FloatToInt(&result_value, &value);
        Int b      = IntFrom(1);
        Int result_value = IntInit();
        Str text   = StrInit();
    
        IntAdd(&result_value, &a, &b);
        Int result_value = IntInit();
        Int huge         = IntFromStr("123456789012345678901234567890");
        Str text         = StrInit();
    
        IntAdd(&result_value, &base, rhs);
        Int preserved    = IntFrom(99);
        Int huge         = IntFromStr("12345678901234567890");
        Str text         = StrInit();
    
        bool result = IntSub(&result_value, &base, rhs);
        Int value = IntFromStr("12345678901234567890");
        Int result_value = IntInit();
        Str text = StrInit();
    
        IntMul(&result_value, &value, 25u);
        Int exponent = IntFrom(20);
        Int result_value = IntInit();
        Str text = StrInit();
    
        IntPow(&result_value, &base, 20u);
        Int quotient  = IntInit();
        Int remainder = IntInit();
        Str qtext     = StrInit();
    
        IntDivMod(&quotient, &remainder, &dividend, 97u);
        Int dividend = IntFromStr("12345678901234567890");
        Int result_value = IntInit();
        Str text = StrInit();
    
        bool result = IntDivExact(&result_value, &dividend, 90u);
        Int quotient = IntInit();
        Int remainder = IntInit();
        Str text = StrInit();
    
        IntDivMod(&quotient, &remainder, &dividend, 97);
        Int value = IntFromStr("1000000000");
        Int next = IntInit();
        Str text = StrInit();
    
        IntNextPrime(&next, &value);
    // Test StrInit function
    bool test_str_init(void) {
        WriteFmt("Testing StrInit\n");
    
        Str s = StrInit();
        WriteFmt("Testing StrInit\n");
    
        Str s = StrInit();
    
        // Validate the string
        WriteFmt("Testing StrWriteFmt\n");
    
        Str s = StrInit();
        StrWriteFmt(&s, "Hello, {}!", &"World"[0]);
    
        Str src = StrInitFromZstr("Hello, World!");
        Str dst = StrInit();
    
        // Copy src to dst
            TypeSpecificIO *argv_ = &(varr)[0];                                                                            \
            u64             argc_ = sizeof(varr) / sizeof(TypeSpecificIO) - 1;                                             \
            Str             out_  = StrInit();                                                                             \
            StrWriteFmtInternal(&out_, (fmtstr), argv_, argc_);                                                            \
            fwrite(out_.data, 1, out_.length, (stream));                                                                   \
            TypeSpecificIO *argv_ = &(varr)[0];                                                                            \
            u64             argc_ = sizeof(varr) / sizeof(TypeSpecificIO) - 1;                                             \
            Str             out_  = StrInit();                                                                             \
            StrWriteFmtInternal(&out_, (fmtstr), argv_, argc_);                                                            \
            fwrite(out_.data, 1, out_.length, (stream));                                                                   \
    #define LOG_FATAL(...)                                                                                                 \
        do {                                                                                                               \
            Str m_ = StrInit();                                                                                            \
            StrWriteFmt(&m_, __VA_ARGS__);                                                                                 \
            LogWrite(LOG_MESSAGE_TYPE_FATAL, __func__, __LINE__, m_.data);                                                 \
    #define LOG_ERROR(...)                                                                                                 \
        do {                                                                                                               \
            Str m_ = StrInit();                                                                                            \
            StrWriteFmt(&m_, __VA_ARGS__);                                                                                 \
            LogWrite(LOG_MESSAGE_TYPE_ERROR, __func__, __LINE__, m_.data);                                                 \
    #define LOG_INFO(...)                                                                                                  \
        do {                                                                                                               \
            Str m_ = StrInit();                                                                                            \
            StrWriteFmt(&m_, __VA_ARGS__);                                                                                 \
            LogWrite(LOG_MESSAGE_TYPE_INFO, __func__, __LINE__, m_.data);                                                  \
    #define LOG_SYS_FATAL(...)                                                                                             \
        do {                                                                                                               \
            Str m_ = StrInit();                                                                                            \
            StrWriteFmt(&m_, __VA_ARGS__);                                                                                 \
            Str syserr_;                                                                                                   \
    #define LOG_SYS_ERROR(...)                                                                                             \
        do {                                                                                                               \
            Str m_ = StrInit();                                                                                            \
            StrWriteFmt(&m_, __VA_ARGS__);                                                                                 \
            Str syserr_;                                                                                                   \
    #define LOG_SYS_INFO(...)                                                                                              \
        do {                                                                                                               \
            Str m_ = StrInit();                                                                                            \
            StrWriteFmt(&m_, __VA_ARGS__);                                                                                 \
            Str syserr_;                                                                                                   \
    
    #ifdef __cplusplus
    #    define StrInit() (Str VecInit())
    #else
    ///
    #define JR_STR(si, str)                                                                                                \
        do {                                                                                                               \
            Str my_str = StrInit();                                                                                        \
            si         = JReadString((si), &my_str);                                                                       \
            (str)      = my_str;                                                                                           \
        do {                                                                                                               \
            if (!StrCmpZstr(&key, (k))) {                                                                                  \
                Str my_str = StrInit();                                                                                    \
                si         = JReadString((si), &my_str);                                                                   \
                (str)      = my_str;                                                                                       \
                                                                                                                           \
                                                                                                                           \
                Str key = StrInit();                                                                                       \
                                                                                                                           \
                /* key start */                                                                                            \
    #define SysProcReadFromStdoutFmt(p, ...)                                                                               \
        do {                                                                                                               \
            Str b_ = StrInit();                                                                                            \
            SysProcReadFromStdout((p), &b_);                                                                               \
            const char *in_ = b_.data;                                                                                     \
    #define SysProcReadFromStderrFmt(p, ...)                                                                               \
        do {                                                                                                               \
            Str b_ = StrInit();                                                                                            \
            SysProcReadFromStderr((p), &b_);                                                                               \
            const char *in_ = b_.data;                                                                                     \
    #define SysProcWriteToStdinFmt(p, ...)                                                                                 \
        do {                                                                                                               \
            Str b_ = StrInit();                                                                                            \
            StrWriteFmt(&b_, __VA_ARGS__);                                                                                 \
            SysProcWriteToStdin((p), &b_);                                                                                 \
    #define SysProcWriteToStdinFmtLn(p, ...)                                                                               \
        do {                                                                                                               \
            Str b_ = StrInit();                                                                                            \
            StrWriteFmt(&b_, __VA_ARGS__);                                                                                 \
            StrPushBack(&b_, '\n');                                                                                        \
Last updated on