dev: added some string helper functions, updated gitignore

This commit is contained in:
A.M. Rowsell 2025-08-27 14:20:22 -04:00
commit 7fad5e53af
Signed by untrusted user who does not match committer: amr
GPG key ID: E0879EDBDB0CA7B1
3 changed files with 40 additions and 0 deletions

1
.gitignore vendored
View file

@ -39,3 +39,4 @@ chessmcu_default/
# End of https://www.toptal.com/developers/gitignore/api/mplabx
localTest/

23
inc/strFuncs.hpp Normal file
View 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
View 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;
}