From 0b9d29ba728499fca51136a9ec8ebdd7dc213f04 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 16 Apr 2020 15:29:09 +0000 Subject: [PATCH] added hawk_copy_bcstr_to_bchars() and hawk_copy_ucstr_to_uchars() --- hawk/lib/hawk-utl.h | 14 ++++++++++++++ hawk/lib/utl-str.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/hawk/lib/hawk-utl.h b/hawk/lib/hawk-utl.h index af4a757e..0ca10d9d 100644 --- a/hawk/lib/hawk-utl.h +++ b/hawk/lib/hawk-utl.h @@ -479,6 +479,18 @@ HAWK_EXPORT hawk_oow_t hawk_copy_bchars_to_bcstr_unlimited ( hawk_oow_t len ); +HAWK_EXPORT hawk_oow_t hawk_copy_ucstr_to_uchars ( + hawk_uch_t* dst, + hawk_uch_t dlen, + const hawk_uch_t* src +); + +HAWK_EXPORT hawk_oow_t hawk_copy_bcstr_to_bchars ( + hawk_bch_t* dst, + hawk_bch_t dlen, + const hawk_bch_t* src +); + HAWK_EXPORT hawk_oow_t hawk_copy_ucstr ( hawk_uch_t* dst, hawk_oow_t len, @@ -710,6 +722,7 @@ HAWK_EXPORT void hawk_unescape_bcstr ( # define hawk_copy_oochars_to_oocstr hawk_copy_uchars_to_ucstr # define hawk_copy_oochars_to_oocstr_unlimited hawk_copy_uchars_to_ucstr_unlimited +# define hawk_copy_oocstr_to_oochars hawk_copy_ucstr_to_uchars # define hawk_copy_oocstr hawk_copy_ucstr # define hawk_copy_oocstr_unlimited hawk_copy_ucstr_unlimited @@ -749,6 +762,7 @@ HAWK_EXPORT void hawk_unescape_bcstr ( # define hawk_copy_oochars_to_oocstr hawk_copy_bchars_to_bcstr # define hawk_copy_oochars_to_oocstr_unlimited hawk_copy_bchars_to_bcstr_unlimited +# define hawk_copy_oocstr_to_oochars hawk_copy_bcstr_to_bchars # define hawk_copy_oocstr hawk_copy_bcstr # define hawk_copy_oocstr_unlimited hawk_copy_bcstr_unlimited diff --git a/hawk/lib/utl-str.c b/hawk/lib/utl-str.c index c1f7d685..7ac7316b 100644 --- a/hawk/lib/utl-str.c +++ b/hawk/lib/utl-str.c @@ -322,6 +322,7 @@ void hawk_copy_bchars (hawk_bch_t* dst, const hawk_bch_t* src, hawk_oow_t len) for (i = 0; i < len; i++) dst[i] = src[i]; } + void hawk_copy_bchars_to_uchars (hawk_uch_t* dst, const hawk_bch_t* src, hawk_oow_t len) { /* copy without conversions. @@ -374,6 +375,39 @@ hawk_oow_t hawk_copy_bchars_to_bcstr_unlimited (hawk_bch_t* dst, const hawk_bch_ return i; } +hawk_oow_t hawk_copy_ucstr_to_uchars (hawk_uch_t* dst, hawk_uch_t dlen, const hawk_uch_t* src) +{ + /* no null termination */ + hawk_uch_t* p, * p2; + + p = dst; p2 = dst + dlen; + + while (p < p2) + { + if (*src == '\0') break; + *p++ = *src++; + } + + return p - dst; +} + +hawk_oow_t hawk_copy_bcstr_to_bchars (hawk_bch_t* dst, hawk_bch_t dlen, const hawk_bch_t* src) +{ + /* no null termination */ + hawk_bch_t* p, * p2; + + p = dst; p2 = dst + dlen; + + while (p < p2) + { + if (*src == '\0') break; + *p++ = *src++; + } + + return p - dst; +} + + hawk_oow_t hawk_copy_ucstr (hawk_uch_t* dst, hawk_oow_t len, const hawk_uch_t* src) { hawk_uch_t* p, * p2;