From 8ac42950d52a406979ff742eb22f047791c7beca Mon Sep 17 00:00:00 2001 From: heck Date: Sun, 25 Apr 2021 02:20:42 +0200 Subject: [PATCH] utils.cc - add to_cxx() for idenitylist, is_c_str_empty() --- src/utils.cc | 22 ++++++++++++++++++++++ src/utils.hh | 7 +++++++ 2 files changed, 29 insertions(+) diff --git a/src/utils.cc b/src/utils.cc index bf58274..4eaa524 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -17,6 +17,28 @@ using namespace pEp; namespace pEp { namespace Utils { + std::vector<::pEp_identity *> to_cxx(const ::identity_list &idl) + { + vector ret{}; + for (const ::identity_list *curr = &idl; curr != nullptr; curr = curr->next) { + if(curr->ident) { + ret.push_back(curr->ident); + } + } + return ret; + } + + bool is_c_str_empty(const char *str) + { + if (str == nullptr) { + return true; + } + string tmp{ str }; + if (tmp.empty()) { + return true; + } + return false; + } string to_string(const ::pEp_identity *const ident, bool full, int indent) { diff --git a/src/utils.hh b/src/utils.hh index ba02a13..037a327 100644 --- a/src/utils.hh +++ b/src/utils.hh @@ -10,9 +10,16 @@ #include #include #include +#include namespace pEp { namespace Utils { + // C-types to C++ types + std::vector<::pEp_identity *> to_cxx(const ::identity_list &idl); + + // C-types helpers + bool is_c_str_empty(const char *str); + // pEpEngine datatypes to string std::string to_string(const ::pEp_identity *const ident, bool full = true, int indent = 0); std::string to_string(const ::identity_list *const idl, bool full = true, int indent = 0);