Skip to content

ValidateStr

Description

Validate whether a given Str object is valid. Not foolproof but will work most of the time. Aborts if provided Str is not valid.

Parameters

Name Direction Description
s in Pointer to Str object to validate.

Success

Continue execution, meaning given Str object is most probably valid.

Failure

abort

Usage example (Cross-references)

Usage examples (Cross-references)
    // `o`'s allocator is NULL), not here.
    Str *StrError(i32 eno, Str *err_str) {
        ValidateStr(err_str);
        Allocator *alloc = StrAllocator(err_str);
        Str        out   = StrInit(alloc);
        }
    
        ValidateStr(o);
        ValidateStr(s);
    
        ValidateStr(o);
        ValidateStr(s);
    
        // Remember the pre-render length so the post-write padding step
        }
    
        ValidateStr(o);
    
        // Snapshot the pre-render length so post-render padding sees the
        }
    
        ValidateStr(o);
        ValidateFloat(value);
            LOG_FATAL("Invalid arguments");
    
        ValidateStr(s);
    
        bool force_case = fmt_info && (fmt_info->flags & FMT_FLAG_FORCE_CASE) != 0;
        }
    
        ValidateStr(o);
        ValidateBitVec(bv);
        }
    
        ValidateStr(o);
        ValidateInt(value);
        Allocator *clone_allocator = NULL;
    
        ValidateStr(src);
        if (!dst) {
            LOG_FATAL("Invalid arguments");
    
    void StrDeinit(Str *copy) {
        ValidateStr(copy);
        deinit_vec(GENERIC_VEC(copy), sizeof(char));
    }
    
        (void)ignored_size;
        ValidateStr(str);
    
        for (idx = 0; idx < StrLen(str); idx++) {
        i32        cmp = 0;
    
        ValidateStr(a);
        ValidateStr(b);
    
        ValidateStr(a);
        ValidateStr(b);
    
        min = StrLen(a) < StrLen(b) ? StrLen(a) : StrLen(b);
    
    i32 str_cmp_str(const Str *s, const Str *other) {
        ValidateStr(s);
        ValidateStr(other);
        return str_compare(s, other);
    i32 str_cmp_str(const Str *s, const Str *other) {
        ValidateStr(s);
        ValidateStr(other);
        return str_compare(s, other);
    }
    
    i32 str_cmp_zstr(const Str *s, Zstr other) {
        ValidateStr(s);
        return ZstrCompare(StrBegin(s), other);
    }
    
    i32 str_cmp_cstr(const Str *s, Zstr other, size other_len) {
        ValidateStr(s);
        return ZstrCompareN(StrBegin(s), other, other_len);
    }
    
    i32 str_cmp_str_ignore_case(const Str *s, const Str *other) {
        ValidateStr(s);
        ValidateStr(other);
        return ZstrCompareIgnoreCase(StrBegin(s), StrBegin(other));
    i32 str_cmp_str_ignore_case(const Str *s, const Str *other) {
        ValidateStr(s);
        ValidateStr(other);
        return ZstrCompareIgnoreCase(StrBegin(s), StrBegin(other));
    }
    
    i32 str_cmp_zstr_ignore_case(const Str *s, Zstr other) {
        ValidateStr(s);
        return ZstrCompareIgnoreCase(StrBegin(s), other);
    }
    
    i32 str_cmp_cstr_ignore_case(const Str *s, Zstr other, size other_len) {
        ValidateStr(s);
        return ZstrCompareNIgnoreCase(StrBegin(s), other, other_len);
    }
    
    Zstr str_find_cstr(const Str *s, Zstr key, size key_len) {
        ValidateStr(s);
        return ZstrFindSubstringN(StrBegin(s), key, key_len);
    }
    
    Zstr str_find_zstr(const Str *s, Zstr key) {
        ValidateStr(s);
        return ZstrFindSubstring(StrBegin(s), key);
    }
    
    Zstr str_find_str(const Str *s, const Str *key) {
        ValidateStr(s);
        ValidateStr(key);
        return ZstrFindSubstringN(StrBegin(s), StrBegin(key), StrLen(key));
    Zstr str_find_str(const Str *s, const Str *key) {
        ValidateStr(s);
        ValidateStr(key);
        return ZstrFindSubstringN(StrBegin(s), StrBegin(key), StrLen(key));
    }
    
    static StrIters str_split_to_iters_impl(Str *s, Zstr key, size keylen) {
        ValidateStr(s);
    
        StrIters sv   = (StrIters)VecInit(s->allocator);
    
    static Strs str_split_impl(Str *s, Zstr key, size keylen) {
        ValidateStr(s);
    
        Strs sv        = (Strs)VecInit(s->allocator);
        Zstr found = NULL;
    
        ValidateStr(s);
    
        if (!key) {
        }
    
        ValidateStr(key);
    
        if (key->length == 0) {
        }
    
        ValidateStr(key);
    
        if (key->length == 0) {
    //                 = 1 means from right
    Str strip_str(Str *s, Zstr chars_to_strip, int split_direction) {
        ValidateStr(s);
    
        // Empty Str: `s->data` may be NULL or unallocated; forming
    
    bool str_starts_with_zstr(const Str *s, Zstr prefix) {
        ValidateStr(s);
        return starts_with(s->data, s->length, prefix, ZstrLen(prefix));
    }
    
    bool str_ends_with_zstr(const Str *s, Zstr suffix) {
        ValidateStr(s);
        return ends_with(s->data, s->length, suffix, ZstrLen(suffix));
    }
    
    bool str_starts_with_cstr(const Str *s, Zstr prefix, size prefix_len) {
        ValidateStr(s);
        return starts_with(s->data, s->length, prefix, prefix_len);
    }
    
    bool str_ends_with_cstr(const Str *s, Zstr suffix, size suffix_len) {
        ValidateStr(s);
        return ends_with(s->data, s->length, suffix, suffix_len);
    }
    
    bool str_starts_with_str(const Str *s, const Str *prefix) {
        ValidateStr(s);
        return starts_with(s->data, s->length, prefix->data, prefix->length);
    }
    
    bool str_ends_with_str(const Str *s, const Str *suffix) {
        ValidateStr(s);
        return ends_with(s->data, s->length, suffix->data, suffix->length);
    }
    
    void str_replace_cstr(Str *s, Zstr match, size match_len, Zstr replacement, size replacement_len, size count) {
        ValidateStr(s);
        size i        = 0;
        size replaced = 0;
    
    void str_replace_zstr(Str *s, Zstr match, Zstr replacement, size count) {
        ValidateStr(s);
        str_replace_cstr(s, match, ZstrLen(match), replacement, ZstrLen(replacement), count);
    }
    
    void str_replace_str(Str *s, const Str *match, const Str *replacement, size count) {
        ValidateStr(s);
        str_replace_cstr(s, match->data, match->length, replacement->data, replacement->length, count);
    }
    
    Str *StrFromU64(Str *str, u64 value, const StrIntFormat *config) {
        ValidateStr(str);
    
        if (!config) {
    
    Str *StrFromI64(Str *str, i64 value, const StrIntFormat *config) {
        ValidateStr(str);
    
        if (!config) {
    
    Str *StrFromF64(Str *str, f64 value, const StrFloatFormat *config) {
        ValidateStr(str);
    
        if (!config) {
    
    bool StrToU64(const Str *str, u64 *value, const StrParseConfig *config) {
        ValidateStr(str);
    
        if (!value) {
    
    bool StrToI64(const Str *str, i64 *value, const StrParseConfig *config) {
        ValidateStr(str);
    
        if (!value) {
    
    bool StrToF64(const Str *str, f64 *value, const StrParseConfig *config) {
        ValidateStr(str);
    
        if (!value) {
    }
    
    void ValidateStr(const Str *s) {
        return ValidateVec(s);
    }
        ValidateVec(vs);
        VecForeachPtr(vs, sp) {
            ValidateStr(sp);
        }
    }
    
    Str *GetCurrentExecutablePath(Str *exe_path) {
        ValidateStr(exe_path);
        Allocator *alloc = StrAllocator(exe_path);
        }
    
        ValidateStr(value);
    
        if (StrCmpIgnoreCase(value, "true") == 0 || StrCmpIgnoreCase(value, "yes") == 0 ||
    // Test ValidateStr macro
    bool test_validate_str(void) {
        WriteFmt("Testing ValidateStr macro\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        // This should not crash
        ValidateStr(&s);
    
        // Note: We can't really test invalid strings here as ValidateStr
    // Deadend test: Test ValidateStr with invalid string (should crash/abort)
    bool test_validate_invalid_str(void) {
        WriteFmt("Testing ValidateStr with invalid string (should abort)\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        // This should abort the program
        ValidateStr(&s);
    
        // Should never reach here
    
        // Validate the string
        ValidateStr(&s);
    
        // Check that it's initialized correctly
    
        // Validate the string
        ValidateStr(&s);
    
        // Check that it's initialized correctly
    
        // Validate the string
        ValidateStr(&s);
    
        // Check that it's initialized correctly
        Str  s        = StrZ(test_str, &alloc);
    
        ValidateStr(&s);
    
        bool result = (StrLen(&s) == ZstrLen(test_str) && ZstrCompare(StrBegin(&s), test_str) == 0);
    
        // Validate both strings
        ValidateStr(&src);
        ValidateStr(&dst);
        // Validate both strings
        ValidateStr(&src);
        ValidateStr(&dst);
    
        // Check that dst is initialized correctly
    
        // Validate both strings
        ValidateStr(&src);
        ValidateStr(&dst);
        // Validate both strings
        ValidateStr(&src);
        ValidateStr(&dst);
    
        // Check that dst is initialized correctly
    
        // Validate the string
        ValidateStr(&s);
    
        // Check that it's initialized correctly
        StrInitStack(stack_str, 20) {
            StrPushBackMany(&stack_str, "Hello, Stack!");
            ValidateStr(&stack_str);
    
            if (ZstrCompare(StrBegin(&stack_str), "Hello, Stack!") != 0) {
    
        // Validate both strings
        ValidateStr(&src);
        ValidateStr(&dst);
        // Validate both strings
        ValidateStr(&src);
        ValidateStr(&dst);
    
        // Check that the copy was successful
        bool copied = StrInitCopy(&dst, &src);
    
        ValidateStr(&src);
        ValidateStr(&dup);
        ValidateStr(&dst);
    
        ValidateStr(&src);
        ValidateStr(&dup);
        ValidateStr(&dst);
        ValidateStr(&src);
        ValidateStr(&dup);
        ValidateStr(&dst);
    
        bool dup_allocator_matches = (StrAllocator(&dup) == StrAllocator(&src));
    
        // Validate the string before deinit
        ValidateStr(&s);
    
        // Deinit the string
Last updated on