diff --git a/relational/relation.py b/relational/relation.py index 8344566..2a9b4b7 100644 --- a/relational/relation.py +++ b/relational/relation.py @@ -97,7 +97,7 @@ class relation (object): '''Depending on the regexp matched by the string, it will perform automatic casting''' tmpstring=rstring(string) - if len(tmpstring)>0 and tmpstring.isdigit(): + if len(tmpstring)>0 and tmpstring.isInt(): return int(tmpstring) elif len(tmpstring)>0 and tmpstring.isFloat(): return float(tmpstring) diff --git a/relational/rtypes.py b/relational/rtypes.py index d3207fe..6a449e3 100644 --- a/relational/rtypes.py +++ b/relational/rtypes.py @@ -26,13 +26,23 @@ import re class rstring (str): '''String subclass with some custom methods''' + def isInt(self): + '''Returns true if the string represents an int number + it only considers as int numbers the strings matching + the following regexp: + r'^[\+\-]{0,1}[0-9]+$' + ''' + if re.match(r'^[\+\-]{0,1}[0-9]+$',self)==None: + return False + else: + return True def isFloat(self): '''Returns true if the string represents a float number it only considers as float numbers, the strings matching the following regexp: - r'^[0-9]+(\.([0-9])+)?$' + r'^[\+\-]{0,1}[0-9]+(\.([0-9])+)?$' ''' - if re.match(r'^[0-9]+(\.([0-9])+)?$',self)==None: + if re.match(r'^[\+\-]{0,1}[0-9]+(\.([0-9])+)?$',self)==None: return False else: return True