On Monday 06 July 2009 15:56:20 Gabriel M. Beddingfield wrote:
> On Mon, 6 Jul 2009, Krzysztof Foltman wrote:
> > Jakob Lund wrote:
> >> , but now it can play, hoorah! At least as long as I don't try to load
> >> from a
> >> path that has an `?` (danish letter) in it... sigh...
> >> Indeed, locale seems to be the problem. Then it's a tinyxml problem I
> >> guess!?
> >
> > atof/sprintf(... "%f" ...) problem, I guess. Decimal point, to be
> > precise.
>
> Sounds like stuff related to rev 1183 where the old string conversion stuff
> was replaced by QString stuff. I'm guessing that the QStrings are trying
> to (incorrectly) respect the locale settings with respect to decimal
> points.
>
> That's odd, though.
Yes, quite odd. Can we have the XML reader be aware that the locale of the xml
file itself is something sensible like "C" or "en_US"? That wouldn't solve
the problem with atof though.
There's a solution here, but it's a bit ugly... using the strtod_l conversion
function, and keeping a "C" locale object around for the purpose of passing
to that function _works_, but it seems a bit hacky.
-- Jakob.
Index: libs/hydrogen/include/hydrogen/LocalFileMng.h
===================================================================
--- libs/hydrogen/include/hydrogen/LocalFileMng.h (revision 1222)
+++ libs/hydrogen/include/hydrogen/LocalFileMng.h (working copy)
@@ -27,6 +27,7 @@
#include <fstream>
#include <vector>
#include <string>
+#include <locale.h>
#include <hydrogen/Object.h>
@@ -93,6 +94,8 @@
private:
void fileCopy( const QString& sOrigFilename, const QString& sDestFilename );
std::vector<QString> m_allPatternList;
+ static locale_t __c_locale;
+
};
Index: libs/hydrogen/src/local_file_mgr.cpp
===================================================================
--- libs/hydrogen/src/local_file_mgr.cpp (revision 1222)
+++ libs/hydrogen/src/local_file_mgr.cpp (working copy)
@@ -50,6 +50,7 @@
#include "xml/tinyxml.h"
#include <algorithm>
+#include <locale.h>
//#include <cstdio>
//#include <vector>
@@ -69,6 +70,8 @@
// infoLog("DESTROY");
}
+/// FIXME: this object should be deleted somewhere with `freelocale( __c_locale )`, but I don't know where to put that...
+locale_t LocalFileMng::__c_locale = newlocale( LC_NUMERIC_MASK, "C", NULL );
QString LocalFileMng::getDrumkitNameForPattern( const QString& patternDir )
{
@@ -983,7 +986,7 @@
TiXmlNode* node;
if ( parent && ( node = parent->FirstChild( nodeName.toAscii() ) ) ) {
if ( node->FirstChild() ) {
- float res = atof(node->FirstChild()->Value());
+ float res = strtod_l(node->FirstChild()->Value(), NULL, __c_locale );
return res;
} else {
if ( !bCanBeEmpty ) {
------------------------------------------------------------------------------
_______________________________________________
Hydrogen-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hydrogen-devel