~octaspire/core

afae38f1f80bda4f9b9d68205606251172080534 — octaspire 1 year, 20 days ago 3fc819f v0.119.0
octaspire_string_t: add two functions and unit tests

* Add functions for checking if 'octaspire_string_t'
  starts or ends with the given C string.
M dev/include/octaspire/core/octaspire_core_config.h => dev/include/octaspire/core/octaspire_core_config.h +1 -1
@@ 18,7 18,7 @@ limitations under the License.
#define OCTASPIRE_CORE_CONFIG_H

#define OCTASPIRE_CORE_CONFIG_VERSION_MAJOR "0"
#define OCTASPIRE_CORE_CONFIG_VERSION_MINOR "118"
#define OCTASPIRE_CORE_CONFIG_VERSION_MINOR "119"
#define OCTASPIRE_CORE_CONFIG_VERSION_PATCH "0"

#define OCTASPIRE_CORE_CONFIG_VERSION_STR "Octaspire Core version " \

M dev/include/octaspire/core/octaspire_string.h => dev/include/octaspire/core/octaspire_string.h +8 -0
@@ 162,10 162,18 @@ bool octaspire_string_starts_with(
    octaspire_string_t const * const self,
    octaspire_string_t const * const other);

bool octaspire_string_starts_with_c_string(
    octaspire_string_t const * const self,
    char const * const str);

bool octaspire_string_ends_with(
    octaspire_string_t const * const self,
    octaspire_string_t const * const other);

bool octaspire_string_ends_with_c_string(
    octaspire_string_t const * const self,
    char const * const str);

uint32_t octaspire_string_get_hash(
    octaspire_string_t const * const self);


M dev/src/octaspire_string.c => dev/src/octaspire_string.c +34 -0
@@ 1148,6 1148,23 @@ bool octaspire_string_starts_with(
    return true;
}

bool octaspire_string_starts_with_c_string(
    octaspire_string_t const * const self,
    char const * const str)
{
    assert(self && str);

    octaspire_string_t * other = octaspire_string_new(str, self->allocator);
    octaspire_helpers_verify_not_null(other);

    bool const result = octaspire_string_starts_with(self, other);

    octaspire_string_release(other);
    other = 0;

    return result;
}

bool octaspire_string_ends_with(
    octaspire_string_t const * const self,
    octaspire_string_t const * const other)


@@ 1180,6 1197,23 @@ bool octaspire_string_ends_with(
    return true;
}

bool octaspire_string_ends_with_c_string(
    octaspire_string_t const * const self,
    char const * const str)
{
    assert(self && str);

    octaspire_string_t * other = octaspire_string_new(str, self->allocator);
    octaspire_helpers_verify_not_null(other);

    bool const result = octaspire_string_ends_with(self, other);

    octaspire_string_release(other);
    other = 0;

    return result;
}

uint32_t octaspire_string_get_hash(
    octaspire_string_t const * const self)
{

M dev/test/test_string.c => dev/test/test_string.c +69 -0
@@ 2784,6 2784,72 @@ TEST octaspire_string_levenshtein_distance_called_with_two_longer_strings_test(v
    PASS();
}

TEST octaspire_string_starts_with_c_string_test(void)
{
    octaspire_string_t *str =
        octaspire_string_new(
            "abcdefghij",
            octaspireContainerUtf8StringTestAllocator);

    ASSERT(str);
    ASSERT(octaspire_string_starts_with_c_string(str, "a"));
    ASSERT(octaspire_string_starts_with_c_string(str, "ab"));
    ASSERT(octaspire_string_starts_with_c_string(str, "abc"));
    ASSERT(octaspire_string_starts_with_c_string(str, "abcd"));
    ASSERT(octaspire_string_starts_with_c_string(str, "abcde"));
    ASSERT(octaspire_string_starts_with_c_string(str, "abcdef"));
    ASSERT(octaspire_string_starts_with_c_string(str, "abcdefg"));
    ASSERT(octaspire_string_starts_with_c_string(str, "abcdefgh"));
    ASSERT(octaspire_string_starts_with_c_string(str, "abcdefghi"));
    ASSERT(octaspire_string_starts_with_c_string(str, "abcdefghij"));

    ASSERT_FALSE(octaspire_string_starts_with_c_string(str, "abcdefghijk"));
    ASSERT_FALSE(octaspire_string_starts_with_c_string(str, "abcdefghix"));
    ASSERT_FALSE(octaspire_string_starts_with_c_string(str, "abcdefghxj"));
    ASSERT_FALSE(octaspire_string_starts_with_c_string(str, "abcdefgxij"));
    ASSERT_FALSE(octaspire_string_starts_with_c_string(str, "b"));

    ASSERT(octaspire_string_starts_with_c_string(str, ""));

    octaspire_string_release(str);
    str = 0;

    PASS();
}

TEST octaspire_string_ends_with_c_string_test(void)
{
    octaspire_string_t *str =
        octaspire_string_new(
            "abcdefghij",
            octaspireContainerUtf8StringTestAllocator);

    ASSERT(str);
    ASSERT(octaspire_string_ends_with_c_string(str, "j"));
    ASSERT(octaspire_string_ends_with_c_string(str, "ij"));
    ASSERT(octaspire_string_ends_with_c_string(str, "hij"));
    ASSERT(octaspire_string_ends_with_c_string(str, "ghij"));
    ASSERT(octaspire_string_ends_with_c_string(str, "fghij"));
    ASSERT(octaspire_string_ends_with_c_string(str, "efghij"));
    ASSERT(octaspire_string_ends_with_c_string(str, "defghij"));
    ASSERT(octaspire_string_ends_with_c_string(str, "cdefghij"));
    ASSERT(octaspire_string_ends_with_c_string(str, "bcdefghij"));
    ASSERT(octaspire_string_ends_with_c_string(str, "abcdefghij"));

    ASSERT_FALSE(octaspire_string_ends_with_c_string(str, "abcdefghijk"));
    ASSERT_FALSE(octaspire_string_ends_with_c_string(str, "abcdefghix"));
    ASSERT_FALSE(octaspire_string_ends_with_c_string(str, "abcdefghxj"));
    ASSERT_FALSE(octaspire_string_ends_with_c_string(str, "abcdefgxij"));
    ASSERT_FALSE(octaspire_string_ends_with_c_string(str, "i"));

    ASSERT(octaspire_string_ends_with_c_string(str, ""));

    octaspire_string_release(str);
    str = 0;

    PASS();
}

TEST octaspire_string_is_index_valid_test(void)
{
    octaspire_string_t *str1 =


@@ 2986,6 3052,9 @@ GREATEST_SUITE(octaspire_string_suite)
    RUN_TEST(octaspire_string_levenshtein_distance_called_with_rosettacode_and_raisethysword_test);
    RUN_TEST(octaspire_string_levenshtein_distance_called_with_two_longer_strings_test);

    RUN_TEST(octaspire_string_starts_with_c_string_test);
    RUN_TEST(octaspire_string_ends_with_c_string_test);

    RUN_TEST(octaspire_string_is_index_valid_test);

    RUN_TEST(octaspire_string_set_from_c_string_test);

M release/octaspire-core-amalgamated.c => release/octaspire-core-amalgamated.c +112 -1
@@ 144,7 144,7 @@ limitations under the License.
#define OCTASPIRE_CORE_CONFIG_H

#define OCTASPIRE_CORE_CONFIG_VERSION_MAJOR "0"
#define OCTASPIRE_CORE_CONFIG_VERSION_MINOR "118"
#define OCTASPIRE_CORE_CONFIG_VERSION_MINOR "119"
#define OCTASPIRE_CORE_CONFIG_VERSION_PATCH "0"

#define OCTASPIRE_CORE_CONFIG_VERSION_STR "Octaspire Core version " \


@@ 972,10 972,18 @@ bool octaspire_string_starts_with(
    octaspire_string_t const * const self,
    octaspire_string_t const * const other);

bool octaspire_string_starts_with_c_string(
    octaspire_string_t const * const self,
    char const * const str);

bool octaspire_string_ends_with(
    octaspire_string_t const * const self,
    octaspire_string_t const * const other);

bool octaspire_string_ends_with_c_string(
    octaspire_string_t const * const self,
    char const * const str);

uint32_t octaspire_string_get_hash(
    octaspire_string_t const * const self);



@@ 6175,6 6183,23 @@ bool octaspire_string_starts_with(
    return true;
}

bool octaspire_string_starts_with_c_string(
    octaspire_string_t const * const self,
    char const * const str)
{
    assert(self && str);

    octaspire_string_t * other = octaspire_string_new(str, self->allocator);
    octaspire_helpers_verify_not_null(other);

    bool const result = octaspire_string_starts_with(self, other);

    octaspire_string_release(other);
    other = 0;

    return result;
}

bool octaspire_string_ends_with(
    octaspire_string_t const * const self,
    octaspire_string_t const * const other)


@@ 6207,6 6232,23 @@ bool octaspire_string_ends_with(
    return true;
}

bool octaspire_string_ends_with_c_string(
    octaspire_string_t const * const self,
    char const * const str)
{
    assert(self && str);

    octaspire_string_t * other = octaspire_string_new(str, self->allocator);
    octaspire_helpers_verify_not_null(other);

    bool const result = octaspire_string_ends_with(self, other);

    octaspire_string_release(other);
    other = 0;

    return result;
}

uint32_t octaspire_string_get_hash(
    octaspire_string_t const * const self)
{


@@ 21814,6 21856,72 @@ TEST octaspire_string_levenshtein_distance_called_with_two_longer_strings_test(v
    PASS();
}

TEST octaspire_string_starts_with_c_string_test(void)
{
    octaspire_string_t *str =
        octaspire_string_new(
            "abcdefghij",
            octaspireContainerUtf8StringTestAllocator);

    ASSERT(str);
    ASSERT(octaspire_string_starts_with_c_string(str, "a"));
    ASSERT(octaspire_string_starts_with_c_string(str, "ab"));
    ASSERT(octaspire_string_starts_with_c_string(str, "abc"));
    ASSERT(octaspire_string_starts_with_c_string(str, "abcd"));
    ASSERT(octaspire_string_starts_with_c_string(str, "abcde"));
    ASSERT(octaspire_string_starts_with_c_string(str, "abcdef"));
    ASSERT(octaspire_string_starts_with_c_string(str, "abcdefg"));
    ASSERT(octaspire_string_starts_with_c_string(str, "abcdefgh"));
    ASSERT(octaspire_string_starts_with_c_string(str, "abcdefghi"));
    ASSERT(octaspire_string_starts_with_c_string(str, "abcdefghij"));

    ASSERT_FALSE(octaspire_string_starts_with_c_string(str, "abcdefghijk"));
    ASSERT_FALSE(octaspire_string_starts_with_c_string(str, "abcdefghix"));
    ASSERT_FALSE(octaspire_string_starts_with_c_string(str, "abcdefghxj"));
    ASSERT_FALSE(octaspire_string_starts_with_c_string(str, "abcdefgxij"));
    ASSERT_FALSE(octaspire_string_starts_with_c_string(str, "b"));

    ASSERT(octaspire_string_starts_with_c_string(str, ""));

    octaspire_string_release(str);
    str = 0;

    PASS();
}

TEST octaspire_string_ends_with_c_string_test(void)
{
    octaspire_string_t *str =
        octaspire_string_new(
            "abcdefghij",
            octaspireContainerUtf8StringTestAllocator);

    ASSERT(str);
    ASSERT(octaspire_string_ends_with_c_string(str, "j"));
    ASSERT(octaspire_string_ends_with_c_string(str, "ij"));
    ASSERT(octaspire_string_ends_with_c_string(str, "hij"));
    ASSERT(octaspire_string_ends_with_c_string(str, "ghij"));
    ASSERT(octaspire_string_ends_with_c_string(str, "fghij"));
    ASSERT(octaspire_string_ends_with_c_string(str, "efghij"));
    ASSERT(octaspire_string_ends_with_c_string(str, "defghij"));
    ASSERT(octaspire_string_ends_with_c_string(str, "cdefghij"));
    ASSERT(octaspire_string_ends_with_c_string(str, "bcdefghij"));
    ASSERT(octaspire_string_ends_with_c_string(str, "abcdefghij"));

    ASSERT_FALSE(octaspire_string_ends_with_c_string(str, "abcdefghijk"));
    ASSERT_FALSE(octaspire_string_ends_with_c_string(str, "abcdefghix"));
    ASSERT_FALSE(octaspire_string_ends_with_c_string(str, "abcdefghxj"));
    ASSERT_FALSE(octaspire_string_ends_with_c_string(str, "abcdefgxij"));
    ASSERT_FALSE(octaspire_string_ends_with_c_string(str, "i"));

    ASSERT(octaspire_string_ends_with_c_string(str, ""));

    octaspire_string_release(str);
    str = 0;

    PASS();
}

TEST octaspire_string_is_index_valid_test(void)
{
    octaspire_string_t *str1 =


@@ 22016,6 22124,9 @@ GREATEST_SUITE(octaspire_string_suite)
    RUN_TEST(octaspire_string_levenshtein_distance_called_with_rosettacode_and_raisethysword_test);
    RUN_TEST(octaspire_string_levenshtein_distance_called_with_two_longer_strings_test);

    RUN_TEST(octaspire_string_starts_with_c_string_test);
    RUN_TEST(octaspire_string_ends_with_c_string_test);

    RUN_TEST(octaspire_string_is_index_valid_test);

    RUN_TEST(octaspire_string_set_from_c_string_test);