From 7fad5e53aff5840f44387d727d5857774eac26ec Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Wed, 27 Aug 2025 14:20:22 -0400 Subject: [PATCH] dev: added some string helper functions, updated gitignore --- .gitignore | 1 + inc/strFuncs.hpp | 23 +++++++++++++++++++++++ strFuncs.cpp | 16 ++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 inc/strFuncs.hpp create mode 100644 strFuncs.cpp diff --git a/.gitignore b/.gitignore index f034f68..18a9398 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,4 @@ chessmcu_default/ # End of https://www.toptal.com/developers/gitignore/api/mplabx +localTest/ \ No newline at end of file diff --git a/inc/strFuncs.hpp b/inc/strFuncs.hpp new file mode 100644 index 0000000..2ea4945 --- /dev/null +++ b/inc/strFuncs.hpp @@ -0,0 +1,23 @@ +/* + * File: strFuncs.hpp + * Author: amr + * + * Created on August 27, 2025, 12:58 PM + */ + +#ifndef STRFUNCS_HPP +#define STRFUNCS_HPP + +#include +#include +#include +#include + +template +void split(const std::string &s, char delim, Out result); + +std::vector split(const std::string &s, char delim); + + +#endif /* STRFUNCS_HPP */ + diff --git a/strFuncs.cpp b/strFuncs.cpp new file mode 100644 index 0000000..9e09da6 --- /dev/null +++ b/strFuncs.cpp @@ -0,0 +1,16 @@ +#include "inc/strFuncs.hpp" + +template +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 split(const std::string &s, char delim) { + std::vector elems; + split(s, delim, std::back_inserter(elems)); + return elems; +}