Skip to content

Make parse_csv_float locale-independent (replace strtof with istringstream + C locale)#30

Merged
lmangani merged 2 commits into
fix-macos-build-failurefrom
copilot/fix-parse-csv-float-issue
May 16, 2026
Merged

Make parse_csv_float locale-independent (replace strtof with istringstream + C locale)#30
lmangani merged 2 commits into
fix-macos-build-failurefrom
copilot/fix-parse-csv-float-issue

Conversation

Copy link
Copy Markdown

Copilot AI commented May 16, 2026

parse_csv_float used std::strtof, which is LC_NUMERIC-dependent and can misparse decimal separators in non-C locales.

Changes

  • Locale-safe parsing: replaced std::strtof with std::istringstream imbued with std::locale::classic(), ensuring . is always the decimal separator regardless of the process locale
  • Reuse stream/buffer across iterations: istringstream and the token std::string are hoisted outside the loop; reused via ss.clear() + ss.str() + token.assign() to avoid per-iteration reconstruction
  • Strict token validation: added !ss.eof() check after extraction — tokens like 3.14abc now break the loop rather than silently accepting the numeric prefix
  • Includes: removed <cerrno> and <cstdlib> (no longer needed); added <locale> and <sstream>
std::istringstream ss;
ss.imbue(std::locale::classic());
std::string token;
// ...per iteration:
token.assign(first, token_end);
ss.clear();
ss.str(token);
float v{};
if (!(ss >> v) || !ss.eof()) { break; }

Copilot AI and others added 2 commits May 16, 2026 12:19
@lmangani lmangani marked this pull request as ready for review May 16, 2026 12:31
@lmangani lmangani merged commit 2f5635f into fix-macos-build-failure May 16, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants