Switching Quantity parser to UTF8

This commit is contained in:
jriegel
2013-12-09 23:49:42 +01:00
parent df363e94f3
commit 401cb13035
9 changed files with 12 additions and 10 deletions

View File

@@ -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))

View File

@@ -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

View File

@@ -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;}

View File

@@ -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

View File

@@ -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");

View File

@@ -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;
}

View File

@@ -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");

View File

@@ -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()));

View File

@@ -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);
}