#include <xtd/xtd>
auto fill_large_log_file(const string& file) -> void {
if (file::exists(file)) return;
println("Write file {}...", file);
auto noise_strings = array<string> {"ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz", "012345678901234467890123456789"};
using_(
auto sw = stream_writer {file})
for (auto index = 0; index < 10'000'000; ++index)
sw.write_line(string::format("{}", index / 2 % 1'000'000 ? noise_strings[index % 3] : string::format("ERROR {}", index / 2)));
println("Done!\n");
}
[[nodiscard]] auto read_all_lines_generator(const string& file) -> enumerable_generator<string> {
using_(
auto sr = stream_reader {file})
while (!sr.end_of_stream())
co_yield sr.read_line();
}
auto main() -> int {
auto file = path::combine(path::get_temp_path(), "bulky_log.txt");
fill_large_log_file(file);
auto lines = read_all_lines_generator(file)
.where([](auto&& line) {return line.contains("ERROR");})
.
select([](
auto&& line) {
return string::format(
"0x{:X8}", as<int32>(line.replace(
"ERROR ",
"")));})
for (auto line : lines)
}
#define using_(...)
The specified expression is cleared automatically when the scope is ended.
Definition using.hpp:36
constexpr auto select
The xtd::ranges::views::select instance.
Definition select.hpp:40
constexpr auto distinct
The xtd::ranges::views::distinct_view instance.
Definition distinct.hpp:40
auto println(FILE *file) -> void
Writes the current line terminator to the file output stream using the specified format information.
Definition println.hpp:14