Skip to content

StrEndsWith

Description

Check whether a Str ends with a suffix.

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

Parameters

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

Success

Returns true when s ends with suffix. 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
        result = result && StrEndsWith(&s, &suffix);
    
        // Test Zstr-form (string literal)
    
        // Test Zstr-form (string literal)
        result = result && StrEndsWith(&s, "World");
        result = result && !StrEndsWith(&s, "Hello");
        // Test Zstr-form (string literal)
        result = result && StrEndsWith(&s, "World");
        result = result && !StrEndsWith(&s, "Hello");
    
        // Test Cstr-form (fixed-length view)
    
        // Test Cstr-form (fixed-length view)
        result = result && StrEndsWith(&s, "orld", 4);
        result = result && !StrEndsWith(&s, "ello", 4);
        // Test Cstr-form (fixed-length view)
        result = result && StrEndsWith(&s, "orld", 4);
        result = result && !StrEndsWith(&s, "ello", 4);
    
        StrDeinit(&s);
Last updated on