From 7201b63412aa7efe19ddbe216142432b62d8b76d Mon Sep 17 00:00:00 2001 From: kevin Date: Tue, 25 Jul 2023 20:19:59 -0400 Subject: [PATCH] cwCsv.h/cpp: Added parse_field( ..., uint8_t ) --- cwCsv.cpp | 12 ++++++++++++ cwCsv.h | 10 +++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cwCsv.cpp b/cwCsv.cpp index ee302d5..646032e 100644 --- a/cwCsv.cpp +++ b/cwCsv.cpp @@ -490,6 +490,12 @@ cw::rc_t cw::csv::field_char_count( handle_t h, unsigned colIdx, unsigned& charC return rc; } +cw::rc_t cw::csv::parse_field( handle_t h, unsigned colIdx, uint8_t& valRef ) +{ + csv_t* p = _handleToPtr(h); + return _parse_number_field( p, colIdx, valRef ) ; +} + cw::rc_t cw::csv::parse_field( handle_t h, unsigned colIdx, unsigned& valRef ) { csv_t* p = _handleToPtr(h); @@ -514,6 +520,12 @@ cw::rc_t cw::csv::parse_field( handle_t h, unsigned colIdx, const char*& valRef return _parse_string_field( p, colIdx, valRef ); } +cw::rc_t cw::csv::parse_field( handle_t h, const char* colLabel, uint8_t& valRef ) +{ + csv_t* p = _handleToPtr(h); + return _parse_number_field(p, colLabel, valRef ); +} + cw::rc_t cw::csv::parse_field( handle_t h, const char* colLabel, unsigned& valRef ) { csv_t* p = _handleToPtr(h); diff --git a/cwCsv.h b/cwCsv.h index 3da8978..f657862 100644 --- a/cwCsv.h +++ b/cwCsv.h @@ -32,20 +32,28 @@ namespace cw // This function return kEofRC when it increments past the last line in the file. rc_t next_line( handle_t h ); - // line index (first line==0) of the line currently being parsed. + // line index (first line==0) of the line currently bei[ng parsed. unsigned cur_line_index( handle_t h ); // Return the count of characters in the field identified by 'colIdx'. rc_t field_char_count( handle_t h, unsigned colIdx, unsigned& charCntRef ); + rc_t parse_field( handle_t h, unsigned colIdx, uint8_t& valRef ); rc_t parse_field( handle_t h, unsigned colIdx, unsigned& valRef ); rc_t parse_field( handle_t h, unsigned colIdx, int& valRef ); rc_t parse_field( handle_t h, unsigned colIdx, double& valRef ); + + // The returned pointer is a pointer into an internal 'line' buffer. + // The reference is therefore only valid until the next call to next_line(). rc_t parse_field( handle_t h, unsigned colIdx, const char*& valRef ); + rc_t parse_field( handle_t h, const char* colLabel, uint8_t& valRef ); rc_t parse_field( handle_t h, const char* colLabel, unsigned& valRef ); rc_t parse_field( handle_t h, const char* colLabel, int& valRef ); rc_t parse_field( handle_t h, const char* colLabel, double& valRef ); + + // The returned pointer is a pointer into an internal 'line' buffer. + // The reference is therefore only valid until the next call to next_line(). rc_t parse_field( handle_t h, const char* colLabel, const char*& valRef ); inline rc_t _getv(handle_t) { return kOkRC; }