Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't decode when number is not natural #8

Open
levanquan1969 opened this issue Nov 5, 2020 · 0 comments
Open

Can't decode when number is not natural #8

levanquan1969 opened this issue Nov 5, 2020 · 0 comments

Comments

@levanquan1969
Copy link

levanquan1969 commented Nov 5, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant