Text utilities (pocketmage_io)
Text utilities (pocketmage_io)
Text utilities API
pocketmage_io is a set of small string helpers for parsing and formatting. They operate on Arduino String and std::vector<String>.
Reference
std::vector<String> splitString(const String& str, char delimiter);
String joinString(const std::vector<String>& parts, char delimiter);
String removeChar(String str, char character);
int stringToInt(const String& str, int defaultVal = -1);
splitStringsplits ondelimiter, keeping empty tokens:"a||b"with'|'becomes{"a", "", "b"}. Use it for command or CSV-style input where empty fields matter.joinStringis the inverse: joinspartswithdelimiterbetween pairs.removeCharstrips every occurrence ofcharacterand returns the new string (a copy; the argument is taken by value).stringToIntparses a decimal integer and returnsdefaultValwhen the string is empty, contains non-digits, or fails to parse. This is the safe integer reader for user input (neveratoion untrusted text).
Example
#include <pocketmage.h>
int parseDuration(String raw) {
// "play 15" -> 15, anything else -> -1
std::vector<String> parts = splitString(raw, ' ');
if (parts.size() != 2) return -1;
return stringToInt(parts[1], -1);
}