Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
github.com/ashaduri/csv-parser
Compile-time and runtime CSV parser written in C++17.
std::string_view
during compilation (using constexpr
).#include "csv_parser.h"
// ...
using namespace std::string_view_literals;
// Data to parse
std::string_view data = "abc,def\n5,6"sv;
// Let "cell_refs" be a vector of columns.
// After parsing, each element will contain a std::string_view referencing
// a part of the original data.
std::vector<std::vector<Csv::CellReference>> cell_refs;
Csv::Parser parser;
try {
// parseTo() throws Csv::ParseError on error.
parser.parseTo(data, cell_refs);
}
catch(Csv::ParseError& ex) {
std::cerr << "CSV parse error: " << ex.what() << std::endl;
return EXIT_FAILURE;
}
assert(cell_refs.size() == 2);
assert(cell_refs[0].size() == 2);
assert(cell_refs[1].size() == 2);
assert(cell_refs[0][0].getType() == Csv::CellType::String);
assert(cell_refs[1][0].getType() == Csv::CellType::String);
assert(cell_refs[0][1].getType() == Csv::CellType::Double);
assert(cell_refs[1][1].getType() == Csv::CellType::Double);
std::cout << "Column 0, row 0: " << cell_refs[0][0].getCleanString().value() << std::endl; // abc
std::cout << "Column 1, row 0: " << cell_refs[1][0].getCleanString().value() << std::endl; // def
std::cout << "Column 0, row 1: " << cell_refs[0][1].getDouble().value() << std::endl; // 5
std::cout << "Column 1, row 1: " << cell_refs[1][1].getDouble().value() << std::endl; // 6
Currently, parsing at compile-time has some restrictions:
One (possibly useful) consequence of compile-time parsing is that a parse error causes compilation error.
#include "csv_parser.h"
// ...
using namespace std::string_view_literals;
constexpr std::string_view data = "\"abc\",def\n5,6"sv;
constexpr std::size_t columns = 2, rows = 2;
constexpr Csv::Parser parser;
// parse into std::array<std::array<CellStringReference, rows>, columns>
constexpr auto matrix = parser.parseTo2DArray<columns, rows>(data);
// Verify the data at compile time.
static_assert(matrix[0][0].getOriginalStringView() == "abc"sv);
static_assert(matrix[1][0].getOriginalStringView() == "def"sv);
static_assert(matrix[0][1].getOriginalStringView() == "5"sv);
static_assert(matrix[1][1].getOriginalStringView() == "6"sv);
Copyright: Alexander Shaduri ashaduri@gmail.com
License: Zlib
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.