Skip to content

Commit 3c13591

Browse files
committed
FIx -if precedence
1 parent 8e89118 commit 3c13591

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

include/data_reader.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class DataReader {
2828
}
2929

3030
public:
31-
DataReader(long long minDate = 0, long long maxDate = 0, int verbosity = 0, const std::string& format = "json", int tailLines = 0)
31+
DataReader(long long minDate = 0, long long maxDate = 0, int verbosity = 0, const std::string& format = "auto", int tailLines = 0)
3232
: minDate(minDate), maxDate(maxDate), verbosity(verbosity), inputFormat(format), tailLines(tailLines) {}
3333

3434
// Internal helper to process a stream (CSV or JSON format)
@@ -88,6 +88,7 @@ class DataReader {
8888
if (verbosity >= 1) {
8989
std::cerr << "Reading from stdin (format: " << inputFormat << ")..." << std::endl;
9090
}
91+
// For stdin: "csv" means CSV, anything else (including "auto" and "json") means JSON
9192
processStream(std::cin, inputFormat == "csv", callback, "stdin");
9293
}
9394

@@ -101,8 +102,16 @@ class DataReader {
101102
}
102103
}
103104

104-
// Determine format: detect from file extension (inputFormat is only for stdin)
105-
bool isCSV = FileUtils::isCsvFile(filename);
105+
// Determine format: explicit "csv"/"json" overrides, "auto" detects from extension
106+
bool isCSV;
107+
if (inputFormat == "csv") {
108+
isCSV = true;
109+
} else if (inputFormat == "json") {
110+
isCSV = false;
111+
} else {
112+
// "auto" or any other value: detect from file extension
113+
isCSV = FileUtils::isCsvFile(filename);
114+
}
106115

107116
if (tailLines > 0) {
108117
// Use tail mode

tests/test_data_reader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void test_process_csv_file_basic() {
4848
".csv"
4949
);
5050

51-
DataReader reader(0, 0, 0, "json"); // inputFormat ignored for files
51+
DataReader reader; // Uses default "auto" format which detects from extension
5252
int count = 0;
5353

5454
reader.processFile(file.path, [&](const std::map<std::string, std::string>& reading, int, const std::string&) {

0 commit comments

Comments
 (0)