Add utility function for processing a string buffer by line

This commit is contained in:
Jonathan G Rennison
2019-05-18 18:29:22 +01:00
parent 8042150a35
commit 257591a32e
2 changed files with 21 additions and 9 deletions

View File

@@ -20,4 +20,21 @@ static inline void str_validate(std::string &str, StringValidationSettings setti
str.resize(str_validate_intl(buf, buf + str.size(), settings) - buf);
}
template <typename F>
inline void ProcessLineByLine(char *buf, F line_functor)
{
char *p = buf;
char *p2 = buf;
/* Print output line by line */
for (; *p2 != '\0'; p2++) {
if (*p2 == '\n') {
*p2 = '\0';
line_functor(p);
p = p2 + 1;
}
}
if (p < p2) line_functor(p);
}
#endif /* STRING_FUNC_EXTRA_H */