Correctly interpret integer tokens without a leading #. Bug report: https://sourceforge.net/projects/ifcopenshell/forums/forum/1782717/topic/5280357

This commit is contained in:
Thomas Krijnen
2012-06-07 11:56:20 +00:00
parent e3f0a5fafd
commit 82289bf065
+6 -2
View File
@@ -311,9 +311,13 @@ bool TokenFunc::isDatatype(Token t) {
return ! isOperator(t) && startsWith(t, 'I');
}
int TokenFunc::asInt(Token t) {
if ( ! isIdentifier(t) ) throw IfcException("Token is not an identifier");
const std::string str = asString(t);
return atoi(str.c_str()+1);
// In case of an ENTITY_INSTANCE_NAME skip the leading #
const char* start = str.c_str() + (isIdentifier(t) ? 1 : 0);
char* end;
long result = strtol(start,&end,10);
if ( start == end ) throw IfcException("Token is not an integer or identifier");
return (int) result;
}
bool TokenFunc::asBool(Token t) {
const std::string str = asString(t);