Skip to content

Commit

Permalink
cleanup(libsinsp): remove unreachable code in utils.cpp
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Guerra <[email protected]>
  • Loading branch information
LucaGuerra authored and poiana committed Jun 19, 2024
1 parent d1d021f commit c1db02a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 121 deletions.
15 changes: 0 additions & 15 deletions userspace/libsinsp/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
///////////////////////////////////////////////////////////////////////////////
Expand Down
106 changes: 0 additions & 106 deletions userspace/libsinsp/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename OBJ>
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<OBJ*> m_avail_list;
std::list<OBJ*> m_full_list;
};

///////////////////////////////////////////////////////////////////////////////
// Case-insensitive string find.
///////////////////////////////////////////////////////////////////////////////
template<typename charT>
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<typename T>
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<typename T::value_type>(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
///////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit c1db02a

Please sign in to comment.