Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ if(RAPIDCSV_BUILD_TESTS)
add_unit_test(test104)
add_unit_test(test105)
add_unit_test(test106)
add_unit_test(test107)

# perf tests
add_perf_test(ptest001)
Expand Down
11 changes: 7 additions & 4 deletions src/rapidcsv.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* rapidcsv.h
*
* URL: https://github.com/d99kris/rapidcsv
* Version: 8.95
* Version: 8.96
*
* Copyright (C) 2017-2026 Kristofer Berggren
* All rights reserved.
Expand Down Expand Up @@ -1473,9 +1473,12 @@ namespace rapidcsv
{
if (mLabelParams.mColumnNameIdx >= 0)
{
return std::vector<std::string>(mData.at(static_cast<size_t>(mLabelParams.mColumnNameIdx)).begin() +
(mLabelParams.mRowNameIdx + 1),
mData.at(static_cast<size_t>(mLabelParams.mColumnNameIdx)).end());
const std::vector<std::string>& labelRow = mData.at(static_cast<size_t>(mLabelParams.mColumnNameIdx));
const size_t offset = static_cast<size_t>(mLabelParams.mRowNameIdx + 1);
if (offset <= labelRow.size())
{
return std::vector<std::string>(labelRow.begin() + static_cast<int>(offset), labelRow.end());
}
}

return std::vector<std::string>();
Expand Down
31 changes: 31 additions & 0 deletions tests/test107.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// test107.cpp - get column labels of empty label row

#include <rapidcsv.h>
#include "unittest.h"

int main()
{
int rv = 0;

try
{
// Empty document, specify column and row labels available
std::string csv = "";
std::istringstream s(csv);
rapidcsv::Document doc(s, rapidcsv::LabelParams(0, 0));

// InsertRow create a row with 0 columns
doc.InsertRow<std::string>(0);

// Get column names
std::vector<std::string> names = doc.GetColumnNames();
unittest::ExpectEqual(size_t, names.size(), size_t(0));
}
catch (const std::exception& ex)
{
std::cout << "exception: " << ex.what() << std::endl;
rv = 1;
}

return rv;
}
Loading