Cache type information on strings

During a selection operation, each value is matched against a regular
expression and then casting might be performed, depending on the results.

This commit caches the result of the match so that a value is not matched
multiple times in its lifetime.
This commit is contained in:
Salvo 'LtWorf' Tomaselli
2015-06-01 00:45:49 +02:00
parent cd5c2845e1
commit 19cff69718

View File

@@ -35,10 +35,16 @@ class rstring (str):
the following regexp: the following regexp:
r'^[\+\-]{0,1}[0-9]+$' r'^[\+\-]{0,1}[0-9]+$'
''' '''
try:
return self._isint
except:
pass
if re.match(r'^[\+\-]{0,1}[0-9]+$', self) == None: if re.match(r'^[\+\-]{0,1}[0-9]+$', self) == None:
return False self._isint = False
else: else:
return True self._isint = True
return self._isint
def isFloat(self): def isFloat(self):
'''Returns true if the string represents a float number '''Returns true if the string represents a float number
@@ -46,10 +52,16 @@ class rstring (str):
the following regexp: the following regexp:
r'^[\+\-]{0,1}[0-9]+(\.([0-9])+)?$' r'^[\+\-]{0,1}[0-9]+(\.([0-9])+)?$'
''' '''
try:
return self._isfloat
except:
pass
if re.match(r'^[\+\-]{0,1}[0-9]+(\.([0-9])+)?$', self) == None: if re.match(r'^[\+\-]{0,1}[0-9]+(\.([0-9])+)?$', self) == None:
return False self._isfloat = False
else: else:
return True self._isfloat = True
return self._isfloat
def isDate(self): def isDate(self):
'''Returns true if the string represents a date, '''Returns true if the string represents a date,