mirror of
https://github.com/XTXMarkets/ternfs.git
synced 2026-01-06 19:09:59 -06:00
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.
47 lines
1.1 KiB
C++
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);
|
|
}
|
|
|
|
}
|