Skip to content

StrStartsWith

Description

Check whether a Str starts with a prefix.

Three call shapes via OVERLOAD + _Generic on prefix: StrStartsWith(s, prefix)prefix is Str * or Zstr. StrStartsWith(s, prefix, prefix_len)prefix is a fixed-length view (Zstr, size).

Parameters

Name Direction Description
s in Str to check.
prefix in Candidate prefix (Str * / Zstr).
prefix_len in Length of prefix when using the 3-arg fixed-length form.

Success

Returns true when s starts with prefix. The string is not modified.

Failure

Returns false. The string is not modified.

Usage example (Cross-references)

Usage examples (Cross-references)
    // Test string starts/ends with functions
    bool test_str_starts_ends_with(void) {
        WriteFmt("Testing StrStartsWith and StrEndsWith variants\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        // Test Str-form
        bool result = StrStartsWith(&s, &prefix);
    
        // Test Str-form
    
        // Test Zstr-form (string literal)
        result = result && StrStartsWith(&s, "Hello");
        result = result && !StrStartsWith(&s, "World");
        // Test Zstr-form (string literal)
        result = result && StrStartsWith(&s, "Hello");
        result = result && !StrStartsWith(&s, "World");
    
        // Test Zstr-form (string literal)
    
        // Test Cstr-form (fixed-length view)
        result = result && StrStartsWith(&s, "Hell", 4);
        result = result && !StrStartsWith(&s, "Worl", 4);
        // Test Cstr-form (fixed-length view)
        result = result && StrStartsWith(&s, "Hell", 4);
        result = result && !StrStartsWith(&s, "Worl", 4);
    
        // Test Cstr-form (fixed-length view)
Last updated on