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.
27 lines
989 B
27 lines
989 B
|
|
#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")]] {
|
|
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");
|
|
}
|
|
}
|