Skip to content

Commit 5200327

Browse files
committed
Switched to using libcatify πŸˆπŸ’•
1 parent a762883 commit 5200327

File tree

1 file changed

+2
-50
lines changed

1 file changed

+2
-50
lines changed

β€Žsrc/catify.cpp

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,8 @@
1-
#include <array>
2-
#include <exception>
3-
#include <filesystem>
4-
#include <fmt/core.h>
5-
#include <fstream>
6-
#include <random>
7-
#include <vector>
1+
#include <catify.hpp>
82

93
namespace fs = std::filesystem;
104

11-
std::string read_all(fs::path const& p, std::fstream& file) {
12-
std::string buffer(fs::file_size(p), '\0');
13-
file.read(buffer.data(), buffer.size());
14-
return buffer;
15-
}
16-
17-
int catify(fs::path const& p) {
18-
std::fstream file(p);
19-
std::string contents = read_all(p, file);
20-
using std::string_view_literals::operator""sv;
21-
22-
constexpr std::array endings = {"🐈"sv, "😌"sv, "πŸ’…"sv, "πŸ’•"sv, "πŸ’–"sv};
23-
24-
std::random_device rd;
25-
26-
std::string_view ending1 = endings[rd() % endings.size()];
27-
std::string_view ending2;
28-
do {
29-
ending2 = endings[rd() % endings.size()];
30-
} while (ending2 == ending1);
31-
32-
std::string_view sv = contents;
33-
34-
for (size_t start = 0; start < sv.size();) {
35-
size_t end = sv.find('\n', start);
36-
auto line = sv.substr(start, end - start);
37-
if (line.size() == 0 || line[0] == '#') {
38-
start = end + 1;
39-
continue;
40-
}
41-
42-
file.seekp(end);
43-
file << ' ' << ending1 << ending2;
44-
file << sv.substr(end);
45-
return 0;
46-
}
47-
48-
fmt::print("Could not find suitable point in file to put the cat.\n");
49-
return 1;
50-
}
515
int main(int argc, char** argv) {
52-
53-
546
if (argc == 1) {
557
fmt::print("Error: no file specified.\n");
568
return 1;
@@ -62,5 +14,5 @@ int main(int argc, char** argv) {
6214
return 1;
6315
}
6416

65-
return catify(file);
17+
return catify::catify(file);
6618
}

0 commit comments

Comments
Β (0)