refactor(userspace/engine): re-implement wrap_text() function in falco_utils

The function implementation was removed, however it was still defined in the .h header. Moreover,
this will now be required in order to replace its lua equivalent.

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
This commit is contained in:
Jason Dellaluce 2022-04-06 12:58:57 +00:00 committed by poiana
parent 3201479392
commit cf83a91d4e
2 changed files with 26 additions and 1 deletions

View File

@ -27,6 +27,31 @@ namespace falco
namespace utils
{
std::string wrap_text(const std::string& str, uint32_t indent, uint32_t line_len)
{
std::string ret;
size_t len = str.size();
size_t cur_len = 0;
for(uint32_t l = 0; l < len; l++)
{
if(cur_len > (line_len - indent) && l != 0 && str[l] == ' ')
{
cur_len = 0;
while (l < len && str[l++] == ' ');
l--;
ret += "\n";
for(uint32_t m = 0; m < indent; m++)
{
ret += " ";
}
}
ret += str.at(l);
cur_len++;
}
ret += "\n";
return ret;
}
uint32_t hardware_concurrency()
{
auto hc = std::thread::hardware_concurrency();

View File

@ -40,7 +40,7 @@ namespace falco
namespace utils
{
std::string wrap_text(const std::string& str, uint32_t initial_pos, uint32_t indent, uint32_t line_len);
std::string wrap_text(const std::string& str, uint32_t indent, uint32_t linelen);
void readfile(const std::string& filename, std::string& data);