diff options
Diffstat (limited to 'zap/include/zap/mem.h')
-rw-r--r-- | zap/include/zap/mem.h | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/zap/include/zap/mem.h b/zap/include/zap/mem.h index 8110a85..36f06b9 100644 --- a/zap/include/zap/mem.h +++ b/zap/include/zap/mem.h @@ -11,22 +11,42 @@ zap_priv_cdecl -void zap_cp( void * zap_priv_restr dest,void const * zap_priv_restr src, zap_sz num); -zap_i8 zap_eq( void const * lbuf,void const * rbuf,zap_sz num); -void zap_fill(void * dest,zap_i8 val, zap_sz num); -void * zap_srch(void const * buf, zap_i8 val, zap_sz num); +zap_priv_nothrw void zap_cp( void * zap_priv_restr dest,void const * zap_priv_restr src, zap_sz num); +zap_priv_nothrw zap_i8 zap_eq( void const * lbuf,void const * rbuf,zap_sz num); +zap_priv_nothrw void zap_fill(void * dest,unsigned char val, zap_sz num); +zap_priv_nothrw void * zap_srch(void const * buf, unsigned char val, zap_sz num); -zap_i8 zap_streq( char const * lstr,char const * rstr); -zap_sz zap_strlen(char const * str); - -zap_sz zap_utf8declen(zap_i8 const * buf); -zap_sz zap_utf8enclen(zap_i02 const * buf); +zap_priv_cdeclend -void zap_utf8dec( zap_i02 * zap_priv_restr dest,zap_i8 const * zap_priv_restr src); -void zap_utf8enc( zap_i8 * zap_priv_restr dest,zap_i02 const * zap_priv_restr src); -void zap_win1252dec(zap_i02 * zap_priv_restr dest,zap_i8 const * zap_priv_restr src); -void zap_win1252enc(zap_i8 * zap_priv_restr dest,zap_i02 const * zap_priv_restr src); +#if __cplusplus + +namespace zap { + template<typename typ> constexpr auto cp(typ * zap_priv_restr dest,typ const * zap_priv_restr src,::zap::sz const num) noexcept -> void { + typ * const zap_priv_restr stop = dest + num; + while (dest != stop) *dest++ = *src++; + } + + template<typename typ> constexpr auto eq(typ const * lbuf,typ const * rbuf,::zap::sz const num) noexcept -> bool { + typ const * const stop = lbuf + num; + while (lbuf != stop) if (*lbuf++ != *rbuf++) return false; + return true; + } + + template<typename typ> constexpr auto fill(typ * dest,typ const val,::zap::sz const num) noexcept -> void { + typ * const stop = dest + num; + while (dest != stop) *dest++ = val; + } + + template<typename typ> constexpr auto srch(typ const * const buf,::zap::i8 const val,::zap::sz const num) noexcept -> typ * { + typ const * const stop = buf + num; + while (buf != stop) { + typ const * addr = buf++; + if (*addr == val) return (void *)addr; + } + return nullptr; + } +} -zap_priv_cdeclend +#endif #endif |