Add utility function for processing a string buffer by line

desync-debugging
Jonathan G Rennison 5 years ago
parent c79c20b34f
commit 45b95a8323

@ -39,6 +39,7 @@
#include "game/game.hpp"
#include "table/strings.h"
#include <time.h>
#include "string_func.h"
#include "safeguards.h"
@ -1080,15 +1081,9 @@ DEF_CONSOLE_CMD(ConRestart)
*/
static void PrintLineByLine(char *buf)
{
char *p = buf;
/* Print output line by line */
for (char *p2 = buf; *p2 != '\0'; p2++) {
if (*p2 == '\n') {
*p2 = '\0';
IConsolePrintF(CC_DEFAULT, "%s", p);
p = p2 + 1;
}
}
ProcessLineByLine(buf, [&](const char *line) {
IConsolePrintF(CC_DEFAULT, "%s", line);
});
}
DEF_CONSOLE_CMD(ConListAILibs)

@ -268,4 +268,20 @@ char *strcasestr(const char *haystack, const char *needle);
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front = false);
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_H */

Loading…
Cancel
Save