jbeder / yaml-cpp

A YAML parser and emitter in C++
MIT License
4.91k stars 1.77k forks source link

Numbers are emitted wrongly under non-C locales. #1282

Open Botje opened 1 month ago

Botje commented 1 month ago

From a question on StackOverflow:

int main(){
  std::locale::global(std::locale(""));
  YAML::Emitter out;
  out << 2112;
  std::cout << "Emitter for 2112 = " << out.c_str() << '\n';
}

When run under LC_ALL=en_US.UTF-8 this produces 2,112 which parses as a string "2,112". Under LC_ALL=nl_BE.UTF-8 this becomes 2.112, which is interpreted by other parsers as a floating point number.

tibyo commented 1 month ago

In my case, the line std::locale::global(std::locale("")); is not required to produce this behaviour. I am not setting the global locale anywhere in my project*, the only reference to locale I make is the use of std::format("{:L} ... but still the integer 2024 is being rendered as "2,024" by yaml-cpp.