mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-07-04 13:17:08 -04:00
* [EGD-2566] refactored cellular notification recogniton * [EGD-2566] add new conversion to dBm * [EGD-2566] added dBm to bar calculations some minor fixes connected to signal strength put static data in event store * [EGD-2566] removed magic number * [EGD-2566] PR fixes * [EGD-2566] PR fixes * [EGD-2566] missing rebase fix * [EGD-2566] moved Signal Strength to separate file. * [EGD-2566] missing return * [EGD-2566] update signalstrength without message sending * [EGD-2566] reverted USE_DAEFAULT_BAUDRATE to 1 * [EGD-2566][fix] missing change for closing end call window * [EGD-2566] fix for proper checking for CSQ. Verbose setting of singla strength in Store * [EGD-2566] fixed inlude in ScopeDTime. * [EGD-2566] added mutex in GSM store * [EGD-2566] missing change * [EGD-2566] reverted USE_DAEFAULT_BAUDRATE * [EGD-2566] PR fixy
92 lines
2.6 KiB
C++
92 lines
2.6 KiB
C++
#pragma once
|
|
#include "i18/i18.hpp"
|
|
#include <algorithm> // std::find_if_not
|
|
#include <log/log.hpp>
|
|
#include <sstream>
|
|
|
|
namespace utils
|
|
{
|
|
static const std::string WHITESPACE = " \n\r\t\f\v";
|
|
|
|
template <typename Out> void split(const std::string &s, char delim, Out result)
|
|
{
|
|
std::stringstream ss(s);
|
|
std::string item;
|
|
while (std::getline(ss, item, delim))
|
|
{
|
|
*(result++) = item;
|
|
}
|
|
}
|
|
|
|
static inline std::vector<std::string> split(const std::string &s, char delim)
|
|
{
|
|
std::vector<std::string> elems;
|
|
split(s, delim, std::back_inserter(elems));
|
|
return elems;
|
|
}
|
|
|
|
static inline std::vector<std::string> split(const std::string &s, const std::string &delimiter, const bool skipEmptyTokens = true)
|
|
{
|
|
size_t pos_start = 0, pos_end, delim_len = delimiter.length();
|
|
std::string token;
|
|
std::vector<std::string> res;
|
|
uint32_t tokenCount = 0;
|
|
|
|
while (((pos_end = s.find(delimiter, pos_start)) != std::string::npos))
|
|
{
|
|
token = s.substr(pos_start, pos_end - pos_start);
|
|
pos_start = pos_end + delim_len;
|
|
if (!skipEmptyTokens || !token.empty())
|
|
{
|
|
tokenCount++;
|
|
res.push_back(token);
|
|
}
|
|
}
|
|
|
|
token = s.substr(pos_start);
|
|
if (!skipEmptyTokens || !token.empty())
|
|
{
|
|
res.push_back(token);
|
|
}
|
|
return res;
|
|
}
|
|
|
|
static inline std::string removeNewLines(const std::string &s)
|
|
{
|
|
std::string retStr = s;
|
|
retStr.erase(std::remove(retStr.begin(), retStr.end(), '\r'), retStr.end());
|
|
retStr.erase(std::remove(retStr.begin(), retStr.end(), '\n'), retStr.end());
|
|
|
|
return retStr;
|
|
}
|
|
|
|
static inline bool is_number(const std::string &s)
|
|
{
|
|
return !s.empty() && std::find_if(s.begin(), s.end(), [](char c) { return !std::isdigit(c); }) == s.end();
|
|
}
|
|
|
|
static inline std::string ltrim(const std::string &s)
|
|
{
|
|
size_t start = s.find_first_not_of(WHITESPACE);
|
|
return (start == std::string::npos) ? "" : s.substr(start);
|
|
}
|
|
|
|
static inline std::string rtrim(const std::string &s)
|
|
{
|
|
size_t end = s.find_last_not_of(WHITESPACE);
|
|
return (end == std::string::npos) ? "" : s.substr(0, end + 1);
|
|
}
|
|
|
|
static inline std::string trim(const std::string &s)
|
|
{
|
|
return rtrim(ltrim(s));
|
|
}
|
|
|
|
template <typename T> std::string to_string(T Number)
|
|
{
|
|
std::ostringstream ss;
|
|
ss << Number;
|
|
return ss.str();
|
|
}
|
|
} // namespace utils
|