Skip to content

StrStrip

Description

Strip leading and trailing characters from s, returning a new Str. The original s is unmodified. The returned Str owns its storage and must be deinited after use.

Parameters

Name Direction Description
s in Str to strip.
chars_to_strip in Optional Zstr listing characters to strip. NULL strips standard ASCII whitespace.

Success

Returns a new Str with surrounding characters removed. s is not modified.

Failure

Returns a zero-length Str when the whole input strips away or on allocator OOM.

Usage example (Cross-references)

Usage examples (Cross-references)
    
        if (StrLen(value) > 0) {
            Str stripped = StrStrip(value, NULL);
            StrDeinit(value);
            *value = stripped;
    // Test string strip functions
    bool test_str_strip(void) {
        WriteFmt("Testing StrStrip variants\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        // Test StrStrip
        stripped = StrStrip(&s1, NULL);
        result   = result && (ZstrCompare(StrBegin(&stripped), "Hello") == 0);
        StrDeinit(&stripped);
        StrDeinit(&stripped);
    
        stripped = StrStrip(&s1, "*");
        result   = result && (ZstrCompare(StrBegin(&stripped), "Hello") == 0);
        StrDeinit(&stripped);
Last updated on