From bc032de1dfc8ad03ed7d6ab0471140f393c74532 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 9 Sep 2024 04:42:36 -0400 Subject: Add Text$compare_values() --- builtins/text.c | 18 +++++++++++------- builtins/text.h | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'builtins') diff --git a/builtins/text.c b/builtins/text.c index 784da410..6fedd82e 100644 --- a/builtins/text.c +++ b/builtins/text.c @@ -905,22 +905,26 @@ PUREFUNC public int32_t Text$compare(const Text_t *a, const Text_t *b) return 0; } -PUREFUNC public bool Text$equal(const Text_t *a, const Text_t *b) +PUREFUNC public bool Text$equal_values(Text_t a, Text_t b) { - if (a == b) return true; - - if (a->length != b->length || (a->hash != 0 && b->hash != 0 && a->hash != b->hash)) + if (a.length != b.length || (a.hash != 0 && b.hash != 0 && a.hash != b.hash)) return false; - int64_t len = a->length; + int64_t len = a.length; text_iter_t a_state = {0, 0}, b_state = {0, 0}; for (int64_t i = 0; i < len; i++) { - int32_t ai = _get_grapheme(*a, &a_state, i); - int32_t bi = _get_grapheme(*b, &b_state, i); + int32_t ai = _get_grapheme(a, &a_state, i); + int32_t bi = _get_grapheme(b, &b_state, i); if (ai != bi) return false; } return true; } +PUREFUNC public bool Text$equal(const Text_t *a, const Text_t *b) +{ + if (a == b) return true; + return Text$equal_values(*a, *b); +} + PUREFUNC public bool Text$equal_ignoring_case(Text_t a, Text_t b) { if (a.length != b.length) diff --git a/builtins/text.h b/builtins/text.h index a9fbf1a1..7f4861a3 100644 --- a/builtins/text.h +++ b/builtins/text.h @@ -27,6 +27,7 @@ Text_t Text$from_strn(const char *str, size_t len); PUREFUNC uint64_t Text$hash(Text_t *text); PUREFUNC int32_t Text$compare(const Text_t *a, const Text_t *b); PUREFUNC bool Text$equal(const Text_t *a, const Text_t *b); +PUREFUNC bool Text$equal_values(Text_t a, Text_t b); PUREFUNC bool Text$equal_ignoring_case(Text_t a, Text_t b); Text_t Text$upper(Text_t text); Text_t Text$lower(Text_t text); -- cgit v1.2.3