This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch main in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=4471092c0dda1320424ab60692960c6b2a61dfaf commit 4471092c0dda1320424ab60692960c6b2a61dfaf Author: Guillem Jover <[email protected]> AuthorDate: Thu Aug 8 04:20:33 2024 +0200 libdpkg: Add new varbuf C++ methods for all functions This should make using varbuf from a C++ codebase more ergonomic. --- lib/dpkg/varbuf.h | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) diff --git a/lib/dpkg/varbuf.h b/lib/dpkg/varbuf.h index 44e1e35d6..87be2641f 100644 --- a/lib/dpkg/varbuf.h +++ b/lib/dpkg/varbuf.h @@ -60,15 +60,44 @@ struct varbuf { #ifdef __cplusplus explicit varbuf(size_t _size = 0); ~varbuf(); + void init(size_t _size = 0); + void grow(size_t need_size); + void trunc(size_t used_size); + char *detach(); void reset(); void destroy(); + void set_buf(const void *buf, size_t _size); + void set(varbuf &other); + void set(const char *str); + void set(const char *str, size_t len); + + int set_vfmt(const char *fmt, va_list args) + DPKG_ATTR_VPRINTF(2); + int set_fmt(const char *fmt, ...) + DPKG_ATTR_PRINTF(2); + + void add_buf(const void *str, size_t _size); + void add(const varbuf &other); + void add(int c); + void add(const char *str); + void add(const char *str, size_t len); + void add_dir(const char *dirname); + int add_vfmt(const char *fmt, va_list args) DPKG_ATTR_VPRINTF(2); int add_fmt(const char *fmt, ...) DPKG_ATTR_PRINTF(2); + void dup(int c, size_t n); + void map(int c_src, int c_dst); + + bool has_prefix(varbuf &prefix); + bool has_suffix(varbuf &suffix); + void trim_prefix(varbuf &prefix); + void trim_prefix(int prefix); + void operator()(int c); void operator()(const char *s); const char *str(); @@ -150,6 +179,24 @@ varbuf::init(size_t _size) varbuf_init(this, _size); } +inline void +varbuf::grow(size_t need_size) +{ + varbuf_grow(this, need_size); +} + +inline void +varbuf::trunc(size_t used_size) +{ + varbuf_trunc(this, used_size); +} + +inline char * +varbuf::detach() +{ + return varbuf_detach(this); +} + inline void varbuf::reset() { @@ -162,6 +209,85 @@ varbuf::destroy() varbuf_destroy(this); } +inline void +varbuf::set_buf(const void *_buf, size_t _size) +{ + varbuf_set_buf(this, _buf, _size); +} + +inline void +varbuf::set(varbuf &other) +{ + varbuf_set_varbuf(this, &other); +} + +inline void +varbuf::set(const char *str) +{ + varbuf_set_str(this, str); +} + +inline void +varbuf::set(const char *str, size_t len) +{ + varbuf_set_strn(this, str, len); +} + +inline int +varbuf::set_vfmt(const char *fmt, va_list args) +{ + return varbuf_set_vfmt(this, fmt, args); +} + +inline int +varbuf::set_fmt(const char *fmt, ...) +{ + va_list args; + int rc; + + va_start(args, fmt); + rc = varbuf_set_vfmt(this, fmt, args); + va_end(args); + + return rc; +} + +inline void +varbuf::add_buf(const void *str, size_t _size) +{ + varbuf_add_buf(this, str, _size); +} + +inline void +varbuf::add(const varbuf &other) +{ + varbuf_add_varbuf(this, &other); +} + +inline void +varbuf::add(int c) +{ + varbuf_add_char(this, c); +} + +inline void +varbuf::add(const char *str) +{ + varbuf_add_str(this, str); +} + +inline void +varbuf::add(const char *str, size_t len) +{ + varbuf_add_strn(this, str, len); +} + +inline void +varbuf::add_dir(const char *dirname) +{ + varbuf_add_dir(this, dirname); +} + inline int varbuf::add_vfmt(const char *fmt, va_list args) { @@ -181,6 +307,42 @@ varbuf::add_fmt(const char *fmt, ...) return rc; } +inline void +varbuf::dup(int c, size_t n) +{ + varbuf_dup_char(this, c, n); +} + +inline void +varbuf::map(int c_src, int c_dst) +{ + varbuf_map_char(this, c_src, c_dst); +} + +inline bool +varbuf::has_prefix(varbuf &prefix) +{ + return varbuf_has_prefix(this, &prefix); +} + +inline bool +varbuf::has_suffix(varbuf &suffix) +{ + return varbuf_has_suffix(this, &suffix); +} + +inline void +varbuf::trim_prefix(varbuf &prefix) +{ + varbuf_trim_varbuf_prefix(this, &prefix); +} + +inline void +varbuf::trim_prefix(int prefix) +{ + varbuf_trim_char_prefix(this, prefix); +} + inline void varbuf::operator()(int c) { -- Dpkg.Org's dpkg

