You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
2.0 KiB
43 lines
2.0 KiB
|
|
#include <string>
|
|
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
|
|
#include <leven.h>
|
|
#include <util.hh>
|
|
|
|
extern "C" {
|
|
_EO(internal)
|
|
_EO(readonly)
|
|
__attribute__((nonnull(1, 2)))
|
|
size_t _EO(leven_diff)(const char* _EO(restrict) a, const char* _EO(restrict) b, size_t n) {
|
|
return exopt::util::leven_diff(std::string_view{a, n}, std::string_view{b, n});
|
|
}
|
|
}
|
|
|
|
namespace exopt {
|
|
namespace util [[gnu::visibility("internal")]] {
|
|
namespace {
|
|
constexpr string_ord a("hello world");
|
|
constexpr string_ord c{a.view()};
|
|
constexpr string_ord b{""};
|
|
consteval bool check_dynamic() noexcept {
|
|
auto d = make_ordered_string<decltype("hello")>("hello").unique();
|
|
return d->size() == (sizeof("hello") -1);
|
|
}
|
|
static_assert(check_dynamic(), "Levenshtein: Bad dynamic sizing");
|
|
static_assert(a.view()[a.view().size()-1], "Levenshtein distance size mismatch for array literals");
|
|
static_assert(a.difference_from(c) == 0, "Levenshtein distance mismatch when converting from array literal");
|
|
static_assert(a.make_dynamic().view() == c.make_dynamic(), "Levenshtein distance mismatch when converting from array literal to dynamic");
|
|
static_assert(c.make_dynamic().view() == a.make_dynamic(), "Levenshtein distance mismatch when converting from std::string to dynamic");
|
|
static_assert(b.view().empty(), "Levenshtein distance size mismatch for array literals (empty)");
|
|
static_assert(a.difference_from(b) == (sizeof(a) - sizeof(b)), "Levenshtein distance size mismatch for array literals (calculation)");
|
|
}
|
|
static_assert(leven_diff("hello world", "Hello World") == 2, "Levelshtein distance incorrect for non-matching strings");
|
|
static_assert(leven_diff("hello world", "hello world") == 0, "Levelshtein distance incorrect for matching strings");
|
|
static_assert(leven_diff("hello world", std::string_view{"hello world"}) == 0, "Levelshtein distance incorrect for matching string container type 1");
|
|
static_assert(leven_diff(std::string{"llo world"}, std::string_view{"hello world"}) == 2, "Levelshtein distance incorrect for matching string container type 2");
|
|
}
|
|
}
|