Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup(libsinsp): remove unreachable code in utils.cpp #1915

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading