Skip to content

ValidateStr

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)
    
            case STR_VALIDATE : {
                ValidateStr(str);
                break;
            }
        }
    
        ValidateStr(o);
        ValidateStr(s);
    
        ValidateStr(o);
        ValidateStr(s);
    
        // Store original length to calculate content size later
        }
    
        ValidateStr(o);
    
        // Store original length to calculate content size later
        }
    
        ValidateStr(o);
        ValidateFloat(value);
            LOG_FATAL("Invalid arguments");
    
        ValidateStr(s);
    
        // Check for case conversion flags
        }
    
        ValidateStr(o);
        ValidateBitVec(bv);
        }
    
        ValidateStr(o);
        ValidateInt(value);
    
    Str *StrPrintf(Str *str, const char *fmt, ...) {
        ValidateStr(str);
    
        StrClear(str);
    
    Str *StrAppendf(Str *str, const char *fmt, ...) {
        ValidateStr(str);
    
        va_list args;
    
    static Str *string_va_printf(Str *str, const char *fmt, va_list args) {
        ValidateStr(str);
    
        va_list args_copy;
    
    bool StrInitCopy(Str *dst, const Str *src) {
        ValidateStr(src);
    
        MemSet(dst, 0, sizeof(Str));
    
        VecMergeR(dst, src);
        ValidateStr(dst);
    
        return true;
    
    void StrDeinit(Str *copy) {
        ValidateStr(copy);
        if (copy->data) {
            FREE(copy->data);
    
    StrIters StrSplitToIters(Str *s, const char *key) {
        ValidateStr(s);
    
        StrIters sv     = VecInit();
    
    Strs StrSplit(Str *s, const char *key) {
        ValidateStr(s);
    
        Strs sv     = VecInitWithDeepCopy(NULL, StrDeinit);
    //                 = 1 means from right
    Str strip_str(Str *s, const char *chars_to_strip, int split_direction) {
        ValidateStr(s);
    
        const char *strip_chars = chars_to_strip ? chars_to_strip : " \t\n\r\v\f";
    
    bool StrStartsWithZstr(const Str *s, const char *prefix) {
        ValidateStr(s);
        return starts_with(s->data, s->length, prefix, ZstrLen(prefix));
    }
    
    bool StrEndsWithZstr(const Str *s, const char *suffix) {
        ValidateStr(s);
        return ends_with(s->data, s->length, suffix, ZstrLen(suffix));
    }
    
    bool StrStartsWithCstr(const Str *s, const char *prefix, size prefix_len) {
        ValidateStr(s);
        return starts_with(s->data, s->length, prefix, prefix_len);
    }
    
    bool StrEndsWithCstr(const Str *s, const char *suffix, size suffix_len) {
        ValidateStr(s);
        return ends_with(s->data, s->length, suffix, suffix_len);
    }
    
    bool StrStartsWith(const Str *s, const Str *prefix) {
        ValidateStr(s);
        return starts_with(s->data, s->length, prefix->data, prefix->length);
    }
    
    bool StrEndsWith(const Str *s, const Str *suffix) {
        ValidateStr(s);
        return ends_with(s->data, s->length, suffix->data, suffix->length);
    }
    static void
        str_replace(Str *s, const char *match, size match_len, const char *replacement, size replacement_len, size count) {
        ValidateStr(s);
        size i        = 0;
        size replaced = 0;
    
    void StrReplaceZstr(Str *s, const char *match, const char *replacement, size count) {
        ValidateStr(s);
        str_replace(s, match, ZstrLen(match), replacement, ZstrLen(replacement), count);
    }
        size        count
    ) {
        ValidateStr(s);
        str_replace(s, match, match_len, replacement, replacement_len, count);
    }
    
    void StrReplace(Str *s, const Str *match, const Str *replacement, size count) {
        ValidateStr(s);
        str_replace(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);
        }
    }
        size idx = 0;
    
        ValidateStr(value);
    
        while (idx < value->length && zstr[idx]) {
    
        (void)ignored_size;
        ValidateStr(str);
    
        for (idx = 0; idx < str->length; idx++) {
        i32        cmp = 0;
    
        ValidateStr(a);
        ValidateStr(b);
    
        ValidateStr(a);
        ValidateStr(b);
    
        min = a->length < b->length ? a->length : b->length;
    // Test ValidateStr macro
    bool test_validate_str(void) {
        WriteFmt("Testing ValidateStr macro\n");
    
        // Create a valid Str
    
        // 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");
    
        // Create an invalid Str by corrupting its fields
    
        // 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
    
        // 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
    
            // Validate the string
            ValidateStr(&stack_str);
    
            // Check that it works correctly
    
        // Validate both strings
        ValidateStr(&src);
        ValidateStr(&dst);
        // Validate both strings
        ValidateStr(&src);
        ValidateStr(&dst);
    
        // Check that the copy was successful
    
        // Validate the string before deinit
        ValidateStr(&s);
    
        // Deinit the string
Last updated on