Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for unsigned char builds #247

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
36 changes: 10 additions & 26 deletions include/internal/basic_csv_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,11 @@ namespace csv {
* the CSVReader::ParseFlags enum
*/
HEDLEY_CONST CONSTEXPR_17 ParseFlagMap make_parse_flags(char delimiter) {
std::array<ParseFlags, 256> ret = {};
for (int i = -128; i < 128; i++) {
const int arr_idx = i + 128;
char ch = char(i);

if (ch == delimiter)
ret[arr_idx] = ParseFlags::DELIMITER;
else if (ch == '\r' || ch == '\n')
ret[arr_idx] = ParseFlags::NEWLINE;
else
ret[arr_idx] = ParseFlags::NOT_SPECIAL;
}

std::array<ParseFlags, 384> ret = {};
for (auto& e: ret) { e = ParseFlags::NOT_SPECIAL; }
ret[delimiter + 128] = ParseFlags::DELIMITER;
ret['\r' + 128] = ParseFlags::NEWLINE;
ret['\n' + 128] = ParseFlags::NEWLINE;
return ret;
}

Expand All @@ -49,7 +41,7 @@ namespace csv {
* the CSVReader::ParseFlags enum
*/
HEDLEY_CONST CONSTEXPR_17 ParseFlagMap make_parse_flags(char delimiter, char quote_char) {
std::array<ParseFlags, 256> ret = make_parse_flags(delimiter);
std::array<ParseFlags, 384> ret = make_parse_flags(delimiter);
ret[(size_t)quote_char + 128] = ParseFlags::QUOTE;
return ret;
}
Expand All @@ -59,19 +51,11 @@ namespace csv {
* c is a whitespace character
*/
HEDLEY_CONST CONSTEXPR_17 WhitespaceMap make_ws_flags(const char* ws_chars, size_t n_chars) {
std::array<bool, 256> ret = {};
for (int i = -128; i < 128; i++) {
const int arr_idx = i + 128;
char ch = char(i);
ret[arr_idx] = false;

for (size_t j = 0; j < n_chars; j++) {
if (ws_chars[j] == ch) {
ret[arr_idx] = true;
}
}
std::array<bool, 384> ret = {};
for (auto& e: ret) { e = false; }
for (int i = 0; i < n_chars; i++) {
ret[ws_chars[i] + 128] = true;
}

return ret;
}

Expand Down
4 changes: 2 additions & 2 deletions include/internal/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ namespace csv {
STATIC_ASSERT(quote_escape_flag(ParseFlags::NEWLINE, true) == ParseFlags::NOT_SPECIAL);

/** An array which maps ASCII chars to a parsing flag */
using ParseFlagMap = std::array<ParseFlags, 256>;
using ParseFlagMap = std::array<ParseFlags, 384>;

/** An array which maps ASCII chars to a flag indicating if it is whitespace */
using WhitespaceMap = std::array<bool, 256>;
using WhitespaceMap = std::array<bool, 384>;
}

/** Integer indicating a requested column wasn't found. */
Expand Down
40 changes: 12 additions & 28 deletions single_include/csv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4838,10 +4838,10 @@ namespace csv {
STATIC_ASSERT(quote_escape_flag(ParseFlags::NEWLINE, true) == ParseFlags::NOT_SPECIAL);

/** An array which maps ASCII chars to a parsing flag */
using ParseFlagMap = std::array<ParseFlags, 256>;
using ParseFlagMap = std::array<ParseFlags, 384>;

/** An array which maps ASCII chars to a flag indicating if it is whitespace */
using WhitespaceMap = std::array<bool, 256>;
using WhitespaceMap = std::array<bool, 384>;
}

/** Integer indicating a requested column wasn't found. */
Expand Down Expand Up @@ -5867,19 +5867,11 @@ namespace csv {
* the CSVReader::ParseFlags enum
*/
HEDLEY_CONST CONSTEXPR_17 ParseFlagMap make_parse_flags(char delimiter) {
std::array<ParseFlags, 256> ret = {};
for (int i = -128; i < 128; i++) {
const int arr_idx = i + 128;
char ch = char(i);

if (ch == delimiter)
ret[arr_idx] = ParseFlags::DELIMITER;
else if (ch == '\r' || ch == '\n')
ret[arr_idx] = ParseFlags::NEWLINE;
else
ret[arr_idx] = ParseFlags::NOT_SPECIAL;
}

std::array<ParseFlags, 384> ret = {};
for (auto& e: ret) { e = ParseFlags::NOT_SPECIAL; }
ret[delimiter + 128] = ParseFlags::DELIMITER;
ret['\r' + 128] = ParseFlags::NEWLINE;
ret['\n' + 128] = ParseFlags::NEWLINE;
return ret;
}

Expand All @@ -5888,7 +5880,7 @@ namespace csv {
* the CSVReader::ParseFlags enum
*/
HEDLEY_CONST CONSTEXPR_17 ParseFlagMap make_parse_flags(char delimiter, char quote_char) {
std::array<ParseFlags, 256> ret = make_parse_flags(delimiter);
std::array<ParseFlags, 384> ret = make_parse_flags(delimiter);
ret[(size_t)quote_char + 128] = ParseFlags::QUOTE;
return ret;
}
Expand All @@ -5898,19 +5890,11 @@ namespace csv {
* c is a whitespace character
*/
HEDLEY_CONST CONSTEXPR_17 WhitespaceMap make_ws_flags(const char* ws_chars, size_t n_chars) {
std::array<bool, 256> ret = {};
for (int i = -128; i < 128; i++) {
const int arr_idx = i + 128;
char ch = char(i);
ret[arr_idx] = false;

for (size_t j = 0; j < n_chars; j++) {
if (ws_chars[j] == ch) {
ret[arr_idx] = true;
}
}
std::array<bool, 384> ret = {};
for (auto& e: ret) { e = false; }
for (int i = 0; i < n_chars; i++) {
ret[ws_chars[i] + 128] = true;
}

return ret;
}

Expand Down
40 changes: 12 additions & 28 deletions single_include_test/csv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4838,10 +4838,10 @@ namespace csv {
STATIC_ASSERT(quote_escape_flag(ParseFlags::NEWLINE, true) == ParseFlags::NOT_SPECIAL);

/** An array which maps ASCII chars to a parsing flag */
using ParseFlagMap = std::array<ParseFlags, 256>;
using ParseFlagMap = std::array<ParseFlags, 384>;

/** An array which maps ASCII chars to a flag indicating if it is whitespace */
using WhitespaceMap = std::array<bool, 256>;
using WhitespaceMap = std::array<bool, 384>;
}

/** Integer indicating a requested column wasn't found. */
Expand Down Expand Up @@ -5867,19 +5867,11 @@ namespace csv {
* the CSVReader::ParseFlags enum
*/
HEDLEY_CONST CONSTEXPR_17 ParseFlagMap make_parse_flags(char delimiter) {
std::array<ParseFlags, 256> ret = {};
for (int i = -128; i < 128; i++) {
const int arr_idx = i + 128;
char ch = char(i);

if (ch == delimiter)
ret[arr_idx] = ParseFlags::DELIMITER;
else if (ch == '\r' || ch == '\n')
ret[arr_idx] = ParseFlags::NEWLINE;
else
ret[arr_idx] = ParseFlags::NOT_SPECIAL;
}

std::array<ParseFlags, 384> ret = {};
for (auto& e: ret) { e = ParseFlags::NOT_SPECIAL; }
ret[delimiter + 128] = ParseFlags::DELIMITER;
ret['\r' + 128] = ParseFlags::NEWLINE;
ret['\n' + 128] = ParseFlags::NEWLINE;
return ret;
}

Expand All @@ -5888,7 +5880,7 @@ namespace csv {
* the CSVReader::ParseFlags enum
*/
HEDLEY_CONST CONSTEXPR_17 ParseFlagMap make_parse_flags(char delimiter, char quote_char) {
std::array<ParseFlags, 256> ret = make_parse_flags(delimiter);
std::array<ParseFlags, 384> ret = make_parse_flags(delimiter);
ret[(size_t)quote_char + 128] = ParseFlags::QUOTE;
return ret;
}
Expand All @@ -5898,19 +5890,11 @@ namespace csv {
* c is a whitespace character
*/
HEDLEY_CONST CONSTEXPR_17 WhitespaceMap make_ws_flags(const char* ws_chars, size_t n_chars) {
std::array<bool, 256> ret = {};
for (int i = -128; i < 128; i++) {
const int arr_idx = i + 128;
char ch = char(i);
ret[arr_idx] = false;

for (size_t j = 0; j < n_chars; j++) {
if (ws_chars[j] == ch) {
ret[arr_idx] = true;
}
}
std::array<bool, 384> ret = {};
for (auto& e: ret) { e = false; }
for (int i = 0; i < n_chars; i++) {
ret[ws_chars[i] + 128] = true;
}

return ret;
}

Expand Down