-
Notifications
You must be signed in to change notification settings - Fork 59
Description
if number is not natural, example :
.001
23.
-.01
1e+2
-1E-2
....
then decode function is error, example :
k = json_decode( [{"number":1E+1}] )
My solution is :
#define df_begin_number '+-.'
function parseNumber()
local m.tk
m.tk = this.getToken()
&& if it not begin digit
if not ( isdigit( m.tk) or m.tk $ df_begin_number )
this.setError( 'number is missing')
return 0
endif
local nStartPos, c, isInt, cNumero
m.nStartPos = this.nPos
&& scan digits
m.c = this.nextChar()
do while isdigit( m.c) or m.c $ 'Ee' + df_begin_number
m.c = this.nextChar()
enddo
&& get digits
m.cNumero = substr( this.cJson, m.nStartPos, this.nPos - m.nStartPos)
&& is valid number
if type( m.cNumero) = 'N'
return Evalu( m.cNumero)
else
&& error
this.setError( 'Invalid number: ' + m.cNumero)
return 0
endif