- Handles sign in numeric types
git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@284 014f5005-505e-4b48-8d0a-63407b615a7c
This commit is contained in:
parent
8065f65d2d
commit
4a6f2cc222
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user