Skip to content

Commit 7264129

Browse files
committed
remove csv-parser dependence
1 parent 0e73e55 commit 7264129

File tree

5 files changed

+39
-30
lines changed

5 files changed

+39
-30
lines changed

.gitmodules

-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
[submodule "submodules/CLI11"]
1515
path = submodules/CLI11
1616
url = https://github.com/CLIUtils/CLI11
17-
[submodule "submodules/csv-parser"]
18-
path = submodules/csv-parser
19-
url = https://github.com/vincentlaucsb/csv-parser
2017
[submodule "submodules/nativefiledialog-extended"]
2118
path = submodules/nativefiledialog-extended
2219
url = https://github.com/btzy/nativefiledialog-extended

CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ include_directories(
2727
# Static executable for subtitle generation (CLI)
2828
# ─────────────────────────────────────────────────────────────────
2929
set(CSV_CXX_STANDARD ${CMAKE_CXX_STANDARD})
30-
add_subdirectory("${CMAKE_SOURCE_DIR}/submodules/csv-parser")
3130
add_subdirectory("${CMAKE_SOURCE_DIR}/submodules/CLI11")
3231

3332
add_executable(subtitles_generator
@@ -44,7 +43,6 @@ target_include_directories(subtitles_generator
4443
target_link_options(subtitles_generator PRIVATE -static)
4544
target_link_libraries(subtitles_generator
4645
PRIVATE
47-
csv
4846
CLI11::CLI11
4947
)
5048

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The project has two separate targets:
1919
*Uses Submodules*: GLFW, Dear ImGui, TinyXML2, SimpleIni, Magic Enum, UTFCPP, nativefiledialog-extended.
2020

2121
- **subtitles_generator**: A CLI tool that converts CSV chat logs into subtitle files (YTT/SRV3) using a given config file.
22-
*Uses Submodules*: CSV Parser, CLI11, TinyXML2, SimpleIni, Magic Enum, UTFCPP.
22+
*Uses Submodules*: CLI11, TinyXML2, SimpleIni, Magic Enum, UTFCPP.
2323

2424
---
2525

cli_main.cpp

+38-23
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,54 @@
22
#include <CLI/CLI.hpp>
33
#include <iostream>
44
#include <fstream>
5-
#include "csv.hpp"
65
#include <vector>
76
#include <string>
87

9-
8+
// dumb and simple way to parse CSV
109
std::vector<ChatMessage> parseCSV(const std::string &filename, int timeMultiplier) {
1110
std::vector<ChatMessage> messages;
12-
try {
13-
csv::CSVReader reader(filename);
14-
for (auto &row: reader) {
15-
ChatMessage msg;
16-
msg.time = row["time"].get<int>() * timeMultiplier;
17-
18-
msg.user.name = row["user_name"].get<>();
19-
20-
std::string col = row["user_color"].get<>();
21-
if (col.empty()) {
22-
msg.user.color = getRandomColor(msg.user.name);
23-
} else {
24-
msg.user.color = Color(col);
25-
}
26-
27-
msg.message = row["message"].get<>();
28-
messages.push_back(std::move(msg));
29-
}
30-
} catch (const std::exception &ex) {
31-
std::cerr << "Error parsing CSV \"" << filename << "\": "
32-
<< ex.what() << "\n";
11+
std::ifstream file(filename);
12+
std::string line;
13+
14+
if (!file.is_open()) {
15+
std::cerr << "Error: Could not open file " << filename << "\n";
3316
std::exit(-1);
3417
}
18+
19+
std::getline(file, line);
20+
if (line != "time,user_name,user_color,message") {
21+
std::cerr << "Error: Unexpected CSV header format.\n";
22+
std::exit(-1);
23+
}
24+
25+
while (std::getline(file, line)) {
26+
std::stringstream ss(line);
27+
std::string field;
28+
ChatMessage msg;
29+
30+
std::getline(ss, field, ',');
31+
msg.time = std::stoi(field) * timeMultiplier;
32+
33+
std::getline(ss, msg.user.name, ',');
34+
35+
std::getline(ss, field, ',');
36+
msg.user.color = field.empty() ? getRandomColor(msg.user.name) : Color(field);
37+
38+
std::getline(ss, msg.message);
39+
40+
if (msg.message.size() >= 2 &&
41+
msg.message.front() == '"' &&
42+
msg.message.back() == '"') {
43+
msg.message = msg.message.substr(1, msg.message.size() - 2);
44+
}
45+
46+
messages.emplace_back(std::move(msg));
47+
}
48+
3549
return messages;
3650
}
3751

52+
3853
int main(int argc, char *argv[]) {
3954
CLI::App app{"Chat → YTT/SRV3 subtitle generator"};
4055

submodules/csv-parser

-1
This file was deleted.

0 commit comments

Comments
 (0)