dev: added some string helper functions, updated gitignore
This commit is contained in:
parent
31499ed6e1
commit
7fad5e53af
3 changed files with 40 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -39,3 +39,4 @@ chessmcu_default/
|
|||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/mplabx
|
||||
|
||||
localTest/
|
||||
23
inc/strFuncs.hpp
Normal file
23
inc/strFuncs.hpp
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* File: strFuncs.hpp
|
||||
* Author: amr
|
||||
*
|
||||
* Created on August 27, 2025, 12:58 PM
|
||||
*/
|
||||
|
||||
#ifndef STRFUNCS_HPP
|
||||
#define STRFUNCS_HPP
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <iterator>
|
||||
|
||||
template <typename Out>
|
||||
void split(const std::string &s, char delim, Out result);
|
||||
|
||||
std::vector<std::string> split(const std::string &s, char delim);
|
||||
|
||||
|
||||
#endif /* STRFUNCS_HPP */
|
||||
|
||||
16
strFuncs.cpp
Normal file
16
strFuncs.cpp
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#include "inc/strFuncs.hpp"
|
||||
|
||||
template <typename Out>
|
||||
void split(const std::string &s, char delim, Out result) {
|
||||
std::istringstream iss(s);
|
||||
std::string item;
|
||||
while (std::getline(iss, item, delim)) {
|
||||
*result++ = item;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue