From 541227653ff9937ddb07da7562030afcfa0d9fd7 Mon Sep 17 00:00:00 2001 From: Luca Guerra Date: Mon, 17 Jun 2024 15:20:17 +0000 Subject: [PATCH] cleanup(libsinsp): remove unreachable code in utils.cpp Signed-off-by: Luca Guerra --- userspace/libsinsp/utils.cpp | 15 ----- userspace/libsinsp/utils.h | 106 ----------------------------------- 2 files changed, 121 deletions(-) diff --git a/userspace/libsinsp/utils.cpp b/userspace/libsinsp/utils.cpp index b448160c6a..b14c8209b8 100644 --- a/userspace/libsinsp/utils.cpp +++ b/userspace/libsinsp/utils.cpp @@ -1786,21 +1786,6 @@ bool sinsp_numparser::tryparsed32_fast(const char* str, uint32_t strlen, int32_t return true; } -/////////////////////////////////////////////////////////////////////////////// -// JSON helpers -/////////////////////////////////////////////////////////////////////////////// - -std::string get_json_string(const Json::Value& obj, const std::string& name) -{ - std::string ret; - const Json::Value& json_val = obj[name]; - if(!json_val.isNull() && json_val.isConvertibleTo(Json::stringValue)) - { - ret = json_val.asString(); - } - return ret; -} - /////////////////////////////////////////////////////////////////////////////// // socket helpers /////////////////////////////////////////////////////////////////////////////// diff --git a/userspace/libsinsp/utils.h b/userspace/libsinsp/utils.h index 0285a41953..54ed2e73cd 100644 --- a/userspace/libsinsp/utils.h +++ b/userspace/libsinsp/utils.h @@ -318,112 +318,6 @@ class sinsp_numparser static bool tryparsed32_fast(const char* str, uint32_t strlen, int32_t* res); }; -/////////////////////////////////////////////////////////////////////////////// -// JSON helpers -/////////////////////////////////////////////////////////////////////////////// -namespace Json -{ - class Value; -} - -std::string get_json_string(const Json::Value& obj, const std::string& name); -inline std::string json_as_string(const Json::Value& json) -{ - return Json::FastWriter().write(json); -} - -/////////////////////////////////////////////////////////////////////////////// -// A simple class to manage pre-allocated objects in a LIFO -// fashion and make sure all of them are deleted upon destruction. -/////////////////////////////////////////////////////////////////////////////// -template -class simple_lifo_queue -{ -public: - simple_lifo_queue(uint32_t size) - { - uint32_t j; - for(j = 0; j < size; j++) - { - OBJ* newentry = new OBJ; - m_full_list.push_back(newentry); - m_avail_list.push_back(newentry); - } - } - ~simple_lifo_queue() - { - while(!m_avail_list.empty()) - { - OBJ* head = m_avail_list.front(); - delete head; - m_avail_list.pop_front(); - } - } - - void push(OBJ* newentry) - { - m_avail_list.push_front(newentry); - } - - OBJ* pop() - { - if(m_avail_list.empty()) - { - return NULL; - } - OBJ* head = m_avail_list.front(); - m_avail_list.pop_front(); - return head; - } - - bool empty() const - { - return m_avail_list.empty(); - } - -private: - std::list m_avail_list; - std::list m_full_list; -}; - -/////////////////////////////////////////////////////////////////////////////// -// Case-insensitive string find. -/////////////////////////////////////////////////////////////////////////////// -template -struct ci_equal -{ - ci_equal(const std::locale& loc) : m_loc(loc) {} - bool operator()(charT ch1, charT ch2) - { - return std::toupper(ch1, m_loc) == std::toupper(ch2, m_loc); - } -private: - const std::locale& m_loc; -}; - -template -int ci_find_substr(const T& str1, const T& str2, const std::locale& loc = std::locale()) -{ - auto it = std::search(str1.begin(), str1.end(), - str2.begin(), str2.end(), ci_equal(loc) ); - if(it != str1.end()) { return it - str1.begin(); } - return -1; -} - -struct ci_compare -{ - // less-than, for use in STL containers - bool operator() (const std::string& a, const std::string& b) const - { - return strcasecmp(a.c_str(), b.c_str()) < 0; - } - - static bool is_equal(const std::string& a, const std::string& b) - { - return strcasecmp(a.c_str(), b.c_str()) == 0; - } -}; - /////////////////////////////////////////////////////////////////////////////// // socket helpers ///////////////////////////////////////////////////////////////////////////////