mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-30 15:45:58 +00:00
Fixed #172 XML floating point serialization not using neutral culture
This commit is contained in:
parent
32aed9e995
commit
ffc821f641
2 changed files with 44 additions and 2 deletions
|
@ -232,6 +232,9 @@ private:
|
||||||
|
|
||||||
// If not NULL, binary mode detected, use this stream in serials
|
// If not NULL, binary mode detected, use this stream in serials
|
||||||
IStream *_BinaryStream;
|
IStream *_BinaryStream;
|
||||||
|
|
||||||
|
// System dependant structure for locale
|
||||||
|
void* _Locale;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,11 @@
|
||||||
// Include from libxml2
|
// Include from libxml2
|
||||||
#include <libxml/xmlerror.h>
|
#include <libxml/xmlerror.h>
|
||||||
|
|
||||||
|
#if defined(NL_OS_WINDOWS) && defined(NL_COMP_VC_VERSION) && NL_COMP_VC_VERSION >= 80
|
||||||
|
#define USE_LOCALE_ATOF
|
||||||
|
#include <locale.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#define NLMISC_READ_BUFFER_SIZE 1024
|
#define NLMISC_READ_BUFFER_SIZE 1024
|
||||||
|
@ -46,6 +51,22 @@ const char SEPARATOR = ' ';
|
||||||
serialSeparatedBufferIn( number_as_string ); \
|
serialSeparatedBufferIn( number_as_string ); \
|
||||||
dest = (thetype)convfunc( number_as_string.c_str() );
|
dest = (thetype)convfunc( number_as_string.c_str() );
|
||||||
|
|
||||||
|
#ifdef USE_LOCALE_ATOF
|
||||||
|
|
||||||
|
#define readnumberlocale(dest,thetype,digits,convfunc) \
|
||||||
|
string number_as_string; \
|
||||||
|
serialSeparatedBufferIn( number_as_string ); \
|
||||||
|
dest = (thetype)convfunc( number_as_string.c_str(), (_locale_t)_Locale );
|
||||||
|
|
||||||
|
#define nl_atof _atof_l
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define readnumberlocale(dest,thetype,digits,convfunc) readnumber(dest,thetype,digits,convfunc)
|
||||||
|
#define nl_atof atof
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
|
|
||||||
inline void CIXml::flushContentString ()
|
inline void CIXml::flushContentString ()
|
||||||
|
@ -70,6 +91,13 @@ CIXml::CIXml () : IStream (true /* Input mode */)
|
||||||
_ErrorString = "";
|
_ErrorString = "";
|
||||||
_TryBinaryMode = false;
|
_TryBinaryMode = false;
|
||||||
_BinaryStream = NULL;
|
_BinaryStream = NULL;
|
||||||
|
|
||||||
|
#ifdef USE_LOCALE_ATOF
|
||||||
|
// create C numeric locale
|
||||||
|
_Locale = _create_locale(LC_NUMERIC, "C");
|
||||||
|
#else
|
||||||
|
_Locale = NULL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
|
@ -85,6 +113,13 @@ CIXml::CIXml (bool tryBinaryMode) : IStream (true /* Input mode */)
|
||||||
_ErrorString = "";
|
_ErrorString = "";
|
||||||
_TryBinaryMode = tryBinaryMode;
|
_TryBinaryMode = tryBinaryMode;
|
||||||
_BinaryStream = NULL;
|
_BinaryStream = NULL;
|
||||||
|
|
||||||
|
#ifdef USE_LOCALE_ATOF
|
||||||
|
// create C numeric locale
|
||||||
|
_Locale = _create_locale(LC_NUMERIC, "C");
|
||||||
|
#else
|
||||||
|
_Locale = NULL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
|
@ -119,6 +154,10 @@ void CIXml::release ()
|
||||||
_ErrorString = "";
|
_ErrorString = "";
|
||||||
|
|
||||||
resetPtrTable();
|
resetPtrTable();
|
||||||
|
|
||||||
|
#ifdef USE_LOCALE_ATOF
|
||||||
|
if (_Locale) _free_locale((_locale_t)_Locale);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
|
@ -546,7 +585,7 @@ void CIXml::serial(float &b)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
readnumber( b, float, 128, atof );
|
readnumberlocale( b, float, 128, nl_atof );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -560,7 +599,7 @@ void CIXml::serial(double &b)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
readnumber( b, double, 128, atof );
|
readnumberlocale( b, double, 128, nl_atof );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue