Switching Quantity parser to UTF8
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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()));
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user