Skip to content

discrepancy between sv_chop_by_delim and sv_chop_by_sv #20

@julianstoerig

Description

@julianstoerig

When the delimeter is placed at the end of the input, sv_chop_by_delim removes it, while sv_chop_by_sv does not.

Example:

#define SV_IMPLEMENTATION
#include "./sv.h"
#include <assert.h>


int main() {
    String_View test_sv1 = SV("12x");
    String_View test_sv2 = SV("12x");
    String_View res1 = sv_chop_by_delim(&test_sv1, 'x');
    String_View res2 = sv_chop_by_sv(&test_sv2, SV("x"));

    assert(sv_eq(test_sv1, SV("")));   // succeeds
    assert(sv_eq(test_sv1, test_sv2)); // succeeds

    assert(sv_eq(res1, SV("12")));     // succeeds
    assert(sv_eq(res2, SV("12x")));    // succeeds
    assert(sv_eq(res1, res2));         // fails
}

As the output confirms:

$ cc test.c && ./a.out
a.out: test.c:16: main: Assertion `sv_eq(res1, res2)' failed.
Aborted                    (core dumped) ./a.out

This is not intentional, is it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions