From 2e91e08ec27bf6ea9065e181f09c9de6ca986d6f Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 8 Aug 2021 17:41:43 +0000 Subject: [PATCH] migrated hio_comp_ucstr_limited()/hio_comp_bcstr_limited() --- hio/lib/utl-str.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ hio/lib/utl-str.c.m4 | 32 +++++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/hio/lib/utl-str.c b/hio/lib/utl-str.c index a5d5316..59daffa 100644 --- a/hio/lib/utl-str.c +++ b/hio/lib/utl-str.c @@ -226,6 +226,63 @@ int hio_comp_bcstr (const hio_bch_t* str1, const hio_bch_t* str2, int ignorecase + +int hio_comp_ucstr_limited (const hio_uch_t* str1, const hio_uch_t* str2, hio_oow_t maxlen, int ignorecase) +{ + if (maxlen == 0) return 0; + + if (ignorecase) + { + while (hio_to_uch_lower(*str1) == hio_to_uch_lower(*str2)) + { + if (*str1 == '\0' || maxlen == 1) return 0; + str1++; str2++; maxlen--; + } + + return ((hio_uchu_t)hio_to_uch_lower(*str1) > (hio_uchu_t)hio_to_uch_lower(*str2))? 1: -1; + } + else + { + while (*str1 == *str2) + { + if (*str1 == '\0' || maxlen == 1) return 0; + str1++; str2++; maxlen--; + } + + return ((hio_uchu_t)*str1 > (hio_uchu_t)*str2)? 1: -1; + } +} + + +int hio_comp_bcstr_limited (const hio_bch_t* str1, const hio_bch_t* str2, hio_oow_t maxlen, int ignorecase) +{ + if (maxlen == 0) return 0; + + if (ignorecase) + { + while (hio_to_bch_lower(*str1) == hio_to_bch_lower(*str2)) + { + if (*str1 == '\0' || maxlen == 1) return 0; + str1++; str2++; maxlen--; + } + + return ((hio_bchu_t)hio_to_bch_lower(*str1) > (hio_bchu_t)hio_to_bch_lower(*str2))? 1: -1; + } + else + { + while (*str1 == *str2) + { + if (*str1 == '\0' || maxlen == 1) return 0; + str1++; str2++; maxlen--; + } + + return ((hio_bchu_t)*str1 > (hio_bchu_t)*str2)? 1: -1; + } +} + + + + hio_oow_t hio_concat_uchars_to_ucstr (hio_uch_t* buf, hio_oow_t bsz, const hio_uch_t* str, hio_oow_t len) { hio_uch_t* p, * p2; diff --git a/hio/lib/utl-str.c.m4 b/hio/lib/utl-str.c.m4 index 581640b..b14f512 100644 --- a/hio/lib/utl-str.c.m4 +++ b/hio/lib/utl-str.c.m4 @@ -144,6 +144,38 @@ int fn_name (const char_type* str1, const char_type* str2, int ignorecase) fn_comp_cstr(hio_comp_ucstr, hio_uch_t, hio_uchu_t, hio_to_uch_lower) fn_comp_cstr(hio_comp_bcstr, hio_bch_t, hio_bchu_t, hio_to_bch_lower) +dnl --------------------------------------------------------------------------- +define([[fn_comp_cstr_limited]], [[ define([[fn_name]], $1) define([[char_type]], $2) define([[chau_type]], $3) +int fn_name (const char_type* str1, const char_type* str2, hio_oow_t maxlen, int ignorecase) +{ + if (maxlen == 0) return 0; + + if (ignorecase) + { + while ($4(*str1) == $4(*str2)) + { + if (*str1 == '\0' || maxlen == 1) return 0; + str1++; str2++; maxlen--; + } + + return ((chau_type)$4(*str1) > (chau_type)$4(*str2))? 1: -1; + } + else + { + while (*str1 == *str2) + { + if (*str1 == '\0' || maxlen == 1) return 0; + str1++; str2++; maxlen--; + } + + return ((chau_type)*str1 > (chau_type)*str2)? 1: -1; + } +} +]]) +fn_comp_cstr_limited(hio_comp_ucstr_limited, hio_uch_t, hio_uchu_t, hio_to_uch_lower) +fn_comp_cstr_limited(hio_comp_bcstr_limited, hio_bch_t, hio_bchu_t, hio_to_bch_lower) + + dnl --------------------------------------------------------------------------- define([[fn_concat_chars_to_cstr]], [[ define([[fn_name]], $1) define([[char_type]], $2) dnl: $3 count_str hio_oow_t fn_name (char_type* buf, hio_oow_t bsz, const char_type* str, hio_oow_t len)