mirror of
https://github.com/eclipse/upm.git
synced 2025-07-02 01:41:12 +03:00
Add string based constructors for UPM sensors
Signed-off-by: Mihai Stefanescu <mihai.stefanescu@rinftech.com> Signed-off-by: Stefan Andritoiu <stefan.andritoiu@gmail.com>
This commit is contained in:
36
include/upm_string_parser.hpp
Normal file
36
include/upm_string_parser.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// NOTE: A Logging mechanism for the whole library should be implemenented.
|
||||
#include <iostream>
|
||||
|
||||
namespace upm {
|
||||
class UpmStringParser {
|
||||
public:
|
||||
static std::vector<std::string> parse(std::string initStr, std::string delim = ",") {
|
||||
if (initStr.empty()) {
|
||||
std::cout << "parse(): NULL or empty string given as argument." << std::endl;
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<std::string> strTokens;
|
||||
size_t start = 0;
|
||||
size_t end = initStr.find(delim);
|
||||
|
||||
while (end != std::string::npos) {
|
||||
strTokens.push_back(initStr.substr(start, end - start));
|
||||
start = end + delim.length();
|
||||
end = initStr.find(delim, start);
|
||||
}
|
||||
strTokens.push_back(initStr.substr(start, end));
|
||||
|
||||
for (auto i : strTokens)
|
||||
std::cout << i << " ";
|
||||
std::cout << std::endl;
|
||||
|
||||
return strTokens;
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user