Skip to content

Commit c7b75ac

Browse files
committed
Enable moo-dern C++
1 parent 2046612 commit c7b75ac

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

include/fmt/format-inl.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# include <climits>
1515
# include <cmath>
1616
# include <exception>
17+
# include <vector>
1718
#endif
1819

1920
#if defined(_WIN32) && !defined(FMT_USE_WRITE_CONSOLE)
@@ -1944,6 +1945,41 @@ FMT_FUNC auto is_printable(uint32_t cp) -> bool {
19441945

19451946
} // namespace detail
19461947

1948+
FMT_FUNC void vcowsay(string_view fmt, format_args args) {
1949+
std::string message = vformat(fmt, args);
1950+
std::vector<std::string> lines;
1951+
size_t max_length = 0;
1952+
size_t width = 40;
1953+
size_t start = 0;
1954+
1955+
while (start < message.size()) {
1956+
size_t end = start + width;
1957+
if (end >= message.size()) {
1958+
lines.push_back(message.substr(start));
1959+
max_length = std::max(max_length, message.size() - start);
1960+
break;
1961+
}
1962+
1963+
size_t space_pos = message.rfind(' ', end);
1964+
if (space_pos == std::string::npos || space_pos < start) space_pos = end;
1965+
1966+
lines.push_back(message.substr(start, space_pos - start));
1967+
max_length = std::max(max_length, space_pos - start);
1968+
start = space_pos + 1;
1969+
}
1970+
1971+
print(" /{:-<{}}\\\n", "", max_length + 2);
1972+
for (const auto& line : lines) print(" | {:<{}} |\n", line, max_length);
1973+
print(" \\{:-<{}}/\n", "", max_length + 2);
1974+
1975+
println(R"(
1976+
\ ^__^
1977+
\ (oo)\_______
1978+
(__)\ )\/\
1979+
||----w |
1980+
|| ||)");
1981+
}
1982+
19471983
FMT_END_NAMESPACE
19481984

19491985
#endif // FMT_FORMAT_INL_H_

include/fmt/format.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4228,6 +4228,13 @@ FMT_NODISCARD auto to_string(const T& value) -> std::string {
42284228
return {buffer.data(), buffer.size()};
42294229
}
42304230

4231+
FMT_API void vcowsay(string_view fmt, format_args args);
4232+
4233+
template <typename... T> void cowsay(format_string<T...> fmt, T&&... args) {
4234+
vargs<T...> va = {{args...}};
4235+
vcowsay(fmt, va);
4236+
}
4237+
42314238
FMT_END_EXPORT
42324239
FMT_END_NAMESPACE
42334240

0 commit comments

Comments
 (0)