diff --git a/src/App/PropertyUnits.cpp b/src/App/PropertyUnits.cpp index 6a4ca6d942..858735c41d 100644 --- a/src/App/PropertyUnits.cpp +++ b/src/App/PropertyUnits.cpp @@ -85,7 +85,7 @@ void PropertyQuantity::setPyObject(PyObject *value) Base::Quantity quant; if (PyString_Check(value)) - quant = Quantity::parse(PyString_AsString(value)); + quant = Quantity::parse(QString::fromLatin1(PyString_AsString(value))); else if (PyFloat_Check(value)) quant = Quantity(PyFloat_AsDouble(value),_Unit); else if (PyInt_Check(value)) diff --git a/src/Base/Quantity.cpp b/src/Base/Quantity.cpp index 7091a3b0e7..8bdc1b5661 100644 --- a/src/Base/Quantity.cpp +++ b/src/Base/Quantity.cpp @@ -284,10 +284,11 @@ int QuantityLexer(void); #endif // DOXYGEN_SHOULD_SKIP_THIS } -Quantity Quantity::parse(const char* buffer) +Quantity Quantity::parse(const QString &string) { + // parse from buffer - QuantityParser::YY_BUFFER_STATE my_string_buffer = QuantityParser::yy_scan_string (buffer); + QuantityParser::YY_BUFFER_STATE my_string_buffer = QuantityParser::yy_scan_string (string.toUtf8().data()); // set the global return variables QuantResult = Quantity(DOUBLE_MIN); // run the parser diff --git a/src/Base/Quantity.h b/src/Base/Quantity.h index a9666206e6..b99abefd78 100644 --- a/src/Base/Quantity.h +++ b/src/Base/Quantity.h @@ -73,7 +73,7 @@ public: //double getUserPrefered(QString &unitString) const; //std::string getUserString(void)const; - static Quantity parse(const char* buffer); + static Quantity parse(const QString &string); /// returns the unit of the quantity const Unit & getUnit(void) const{return _Unit;} diff --git a/src/Base/QuantityParser.l b/src/Base/QuantityParser.l index c67b9fee81..fd1f9b5dd3 100644 --- a/src/Base/QuantityParser.l +++ b/src/Base/QuantityParser.l @@ -39,6 +39,7 @@ ID [a-z][a-z0-9]* "nm" yylval = Quantity::NanoMetre; return UNIT; // nano meter "ym" yylval = Quantity::MicroMetre; return UNIT; // micro meter + "\xC2\xB5m"yylval = Quantity::MicroMetre; return UNIT; // micro meter (greek micro in UTF8) "mm" yylval = Quantity::MilliMetre; return UNIT; // milli meter (internal standard length) "cm" yylval = Quantity::CentiMetre; return UNIT; // centi meter "dm" yylval = Quantity::DeciMetre; return UNIT; // deci meter diff --git a/src/Base/QuantityPyImp.cpp b/src/Base/QuantityPyImp.cpp index 5e5a9f9dae..d848aff1dc 100644 --- a/src/Base/QuantityPyImp.cpp +++ b/src/Base/QuantityPyImp.cpp @@ -65,7 +65,7 @@ int QuantityPy::PyInit(PyObject* args, PyObject* kwd) const char* string; if (PyArg_ParseTuple(args,"s", &string)) { try { - *self = Quantity::parse(string); + *self = Quantity::parse(QString::fromLatin1(string)); }catch(const Base::Exception& e) { PyErr_SetString(PyExc_ImportError, e.what()); return-1; @@ -131,7 +131,7 @@ PyObject* QuantityPy::getValueAs(PyObject *args) const char* string; if (PyArg_ParseTuple(args,"s", &string)) { - quant = Quantity::parse(string); + quant = Quantity::parse(QString::fromLatin1(string)); }else{ PyErr_SetString(PyExc_TypeError, "Either three floats, tuple or Vector expected"); diff --git a/src/Base/UnitPyImp.cpp b/src/Base/UnitPyImp.cpp index ff3b6d7d1a..9567bd3945 100644 --- a/src/Base/UnitPyImp.cpp +++ b/src/Base/UnitPyImp.cpp @@ -75,7 +75,7 @@ int UnitPy::PyInit(PyObject* args, PyObject* kwd) const char* string; if (PyArg_ParseTuple(args,"s", &string)) { - *self = Quantity::parse(string).getUnit(); + *self = Quantity::parse(QString::fromLatin1(string)).getUnit(); return 0; } diff --git a/src/Base/UnitsApiPy.cpp b/src/Base/UnitsApiPy.cpp index da761a5e26..5d1a8b5b92 100644 --- a/src/Base/UnitsApiPy.cpp +++ b/src/Base/UnitsApiPy.cpp @@ -134,7 +134,7 @@ PyObject* UnitsApi::sParseQuantity(PyObject * /*self*/, PyObject *args,PyObject Quantity rtn; try { - rtn = Quantity::parse(pstr); + rtn = Quantity::parse(QString::fromLatin1(pstr)); } catch (const Base::Exception&) { PyErr_Format(PyExc_IOError, "invalid unit expression \n"); diff --git a/src/Gui/InputField.cpp b/src/Gui/InputField.cpp index e74a15efd4..d45429bbe2 100644 --- a/src/Gui/InputField.cpp +++ b/src/Gui/InputField.cpp @@ -108,7 +108,7 @@ void InputField::newInput(const QString & text) { Quantity res; try{ - res = Quantity::parse(text.toAscii()); + res = Quantity::parse(text); }catch(Base::Exception &e){ ErrorText = e.what(); this->setToolTip(QString::fromAscii(ErrorText.c_str())); diff --git a/src/Mod/Sketcher/Gui/TaskSketcherGeneral.cpp b/src/Mod/Sketcher/Gui/TaskSketcherGeneral.cpp index 68caaef6ca..879e4bbe47 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherGeneral.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherGeneral.cpp @@ -112,7 +112,7 @@ void TaskSketcherGeneral::toggleGridView(bool on) void TaskSketcherGeneral::setGridSize(const QString& val) { - float gridSize = (float) Base::Quantity::parse(val.toAscii()).getValue(); + float gridSize = (float) Base::Quantity::parse(val).getValue(); if (gridSize > 0) sketchView->GridSize.setValue(gridSize); }