0
0
mirror of https://github.com/zeux/pugixml.git synced 2024-12-26 21:04:25 +08:00

XPath: Account for non-English locales during number->string conversion

We use a special number formatting routine to generate the XPath
REC-compliant number representation; it relies on being able to get a
decimal representation of the source number, which we use sprintf for as
a fallback.

This is fairly insensitive to current locale, except for an assertion
that validates the decimal point as a precaution, and this check
triggers when the locale decimal point is not a dot.

Ideally we'd use a locale-insensitive routine here. On some systems we
have ecvt_r (similarly to MSVC's ecvt_s), but it's deprecated so
adopting it might be fraught with peril.

For now let's simply adjust the assertion to account for locales with
comma as a separator. This is probably not fully comprehensive but
probably gets us from a 90% solution to a 99% solution...

Fixes #574.
This commit is contained in:
Arseny Kapoulkine 2023-07-27 09:24:10 -07:00
parent 187cf6b5a5
commit 980cf57ff4

View File

@ -8458,7 +8458,7 @@ PUGI_IMPL_NS_BEGIN
// extract mantissa string: skip sign // extract mantissa string: skip sign
char* mantissa = buffer[0] == '-' ? buffer + 1 : buffer; char* mantissa = buffer[0] == '-' ? buffer + 1 : buffer;
assert(mantissa[0] != '0' && mantissa[1] == '.'); assert(mantissa[0] != '0' && (mantissa[1] == '.' || mantissa[1] == ','));
// divide mantissa by 10 to eliminate integer part // divide mantissa by 10 to eliminate integer part
mantissa[1] = mantissa[0]; mantissa[1] = mantissa[0];