[SG16-Unicode] P1689: Encoding of filenames for interchange

Thiago Macieira thiago at macieira.org
Sun Sep 8 18:28:03 CEST 2019


On Saturday, 7 September 2019 20:31:00 PDT Lyberta wrote:
> Thiago Macieira:
> > Challenge: produce this JSON thread-safely in machine-readable format in
> > C,
> > with setlocale(LC_ALL, ""); at the top of the file, from input double v =
> > 1.1.> 
> >  [ 1.1 ]
> 
> In C, huh? I'd rather write in C++ and in that case it's not that hard
> because of std::mutex, char8_t, std::byte, templates.

Ok, so how would you do this in C++?

> 
> I'm not sure why setlocale was mentioned, why would you ever format JSON
> numbers (or anything JSON) with locale?

Because it isn't about JSON, it's about everything else. Here's a failure mode 
your code should be able to deal with: printing the localised error message of 
why it couldn't open the output file for writing.

I asked for C because my argument was that the C library is deficient in 
handling machine-readable floating point text forms. C++ has the necessary 
forms, but it's also very easy to fall into a trap and write wrong code.

> > Great! Let's drop JSON then.
> 
> JSON requires UTF-8 and specific parsing rules, it far away from plain text.

It's not binary, though. This whole argument is that the moment you need to 
write or parse text forms of numbers and strings, you introduce new failure 
modes because programmers aren't aware of the pitfalls.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel System Software Products





More information about the Unicode mailing list