From f1d8ff7de1abdc69c1276d8f09f3af3d29a0d8cd Mon Sep 17 00:00:00 2001 From: Ruben Carlo Benante Date: Fri, 22 May 2026 19:40:51 -0300 Subject: [PATCH] IMPROVES-i12 split cmp11sht.c into lib11sht.{c,h} --- lib11sht.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lib11sht.h diff --git a/lib11sht.h b/lib11sht.h new file mode 100644 index 0000000..c40c1d7 --- /dev/null +++ b/lib11sht.h @@ -0,0 +1,39 @@ +/* ************************************************************************ * + * lib11sht.h, v1.0 * + * Fuzzy comparison library: public API * + * * + * Copyright (C) 2025 by Ruben Carlo Benante * + * GNU GPL version 2 or later. * + * ************************************************************************ */ + +#ifndef LIB11SHT_H +#define LIB11SHT_H + +#define LEVN_SBUFF 256 /* min size for s1/s2 buffers and bounded input */ + +/* Compare similarity between two strings (after asciify + trim + lowercase). + * Returns: + * 0 if equal or similar above the given threshold ratio + * -1 if a < b alphabetically (after normalization) + * +1 if a > b alphabetically (after normalization) + * On error: sets errno = EINVAL and returns 0; comparison result is undefined. + * Caller must reset errno = 0 before the call to detect errors. + * + * Parameters: + * a, b input strings (NUL-terminated, may contain UTF-8 accented Latin chars) + * thr Levenshtein similarity threshold 0.0..1.0; matches above this count as equal + * ratio out: Levenshtein similarity 0.0..1.0 (1.0 on exact-after-normalize) + * s1, s2 out: caller-provided buffers (>= LEVN_SBUFF) filled with the + * normalized inputs (useful for diagnostics; can be ignored) + */ +int sequal(char *a, char *b, float thr, float *ratio, char *s1, char *s2); + +/* Compare two floats within ±delta. + * Returns: + * 0 if |a - b| <= delta + * -1 if a < b - delta + * +1 if a > b + delta + */ +int fequal(float a, float b, float delta); + +#endif /* LIB11SHT_H */