Files
ternfs-XTXMarkets/cpp/FormatTuple.cpp
Francesco Mazzoli fc0cee0e07 C++ shard
Most operations apart from spans-related ones work. Using this as
a checkpoint -- the Python code is currently not really working,
I'm working to migrate to pretty much a full C++/go world.
2022-12-10 10:55:25 +00:00

47 lines
1.1 KiB
C++

#include "FormatTuple.hpp"
namespace ft_detail {
const char* write_up_to_next_percent_s(std::ostream &os, const char *fmt) {
const char* head = fmt;
for (; *fmt; ++fmt) {
if (*fmt == '%') {
++fmt;
if (*fmt == '\0') {
break;
} else if (*fmt == 's') {
os.write(head, fmt - head - 1);
return fmt + 1;
} else if (*fmt == '%') {
os.write(head, fmt - head - 1);
head = fmt;
}
}
}
os.write(head, fmt - head);
os << " <missing %s> ";
return fmt;
}
void write_fmt_tail(std::ostream &os, const char *fmt) {
const char* head = fmt;
for (; *fmt; ++fmt) {
if (*fmt == '%') {
++fmt;
if (*fmt == '\0') {
break;
} else if (*fmt == 's') {
os.write(head, fmt - head - 1);
os << "<too many %s>";
head = fmt + 1;
} else if (*fmt == '%') {
os.write(head, fmt - head - 1);
head = fmt;
}
}
}
os.write(head, fmt - head);
}
}