Fixed implementation of JSON_PARSER.is_valid_number (STRING): BOOLEAN
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
note
|
note
|
||||||
description: "Parse serialized JSON data"
|
description: "Parse serialized JSON data"
|
||||||
author: "$Author: jfiat $"
|
author: "$Author$"
|
||||||
date: "$Date: 2014-11-17 11:54:05 +0100 (lun., 17 nov. 2014) $"
|
date: "$Date$"
|
||||||
revision: "$Revision: 96099 $"
|
revision: "$Revision$"
|
||||||
|
|
||||||
class
|
class
|
||||||
JSON_PARSER
|
JSON_PARSER
|
||||||
@@ -509,88 +509,111 @@ feature {NONE} -- Implementation
|
|||||||
if c = token_minus then
|
if c = token_minus then
|
||||||
s.extend (c)
|
s.extend (c)
|
||||||
i := i + 1
|
i := i + 1
|
||||||
c := a_number [i]
|
if i > n then
|
||||||
|
Result := False
|
||||||
|
else
|
||||||
|
c := a_number [i]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
--| "0|[1-9]\d*
|
--| "0|[1-9]\d*
|
||||||
if c.is_digit then
|
if Result and c.is_digit then
|
||||||
if c = '0' then
|
if c = '0' then
|
||||||
--| "0"
|
--| "0"
|
||||||
s.extend (c)
|
s.extend (c)
|
||||||
i := i + 1
|
i := i + 1
|
||||||
c := a_number [i]
|
if i <= n then
|
||||||
|
c := a_number [i]
|
||||||
|
end
|
||||||
else
|
else
|
||||||
--| "[1-9]"
|
--| "[1-9]"
|
||||||
s.extend (c)
|
s.extend (c)
|
||||||
i := i + 1
|
|
||||||
c := a_number [i]
|
|
||||||
--| "\d*"
|
--| "\d*"
|
||||||
from
|
i := i + 1
|
||||||
until
|
if i <= n then
|
||||||
i > n or not c.is_digit
|
|
||||||
loop
|
|
||||||
s.extend (c)
|
|
||||||
i := i + 1
|
|
||||||
c := a_number [i]
|
c := a_number [i]
|
||||||
|
from
|
||||||
|
until
|
||||||
|
i > n or not c.is_digit
|
||||||
|
loop
|
||||||
|
s.extend (c)
|
||||||
|
i := i + 1
|
||||||
|
if i <= n then
|
||||||
|
c := a_number [i]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if Result then
|
if i > n then
|
||||||
--| "(\.\d+)?"
|
-- Exit
|
||||||
if c = token_dot then
|
else
|
||||||
--| "\.\d+" = "\.\d\d*"
|
if Result then
|
||||||
s.extend (c)
|
--| "(\.\d+)?"
|
||||||
i := i + 1
|
if c = token_dot then
|
||||||
c := a_number [i]
|
--| "\.\d+" = "\.\d\d*"
|
||||||
if c.is_digit then
|
|
||||||
from
|
|
||||||
until
|
|
||||||
i > n or not c.is_digit
|
|
||||||
loop
|
|
||||||
s.extend (c)
|
|
||||||
i := i + 1
|
|
||||||
c := a_number [i]
|
|
||||||
end
|
|
||||||
else
|
|
||||||
Result := False --| expecting digit
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if Result then --| "(?:[eE][+-]?\d+)?\b"
|
|
||||||
if is_exp_token (c) then
|
|
||||||
--| "[eE][+-]?\d+"
|
|
||||||
s.extend (c)
|
|
||||||
i := i + 1
|
|
||||||
c := a_number [i]
|
|
||||||
if c = token_plus or c = token_minus then
|
|
||||||
s.extend (c)
|
s.extend (c)
|
||||||
i := i + 1
|
i := i + 1
|
||||||
c := a_number [i]
|
c := a_number [i]
|
||||||
|
if c.is_digit then
|
||||||
|
from
|
||||||
|
until
|
||||||
|
i > n or not c.is_digit
|
||||||
|
loop
|
||||||
|
s.extend (c)
|
||||||
|
i := i + 1
|
||||||
|
if i <= n then
|
||||||
|
c := a_number [i]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Result := False --| expecting digit
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if c.is_digit then
|
end
|
||||||
from
|
if Result then --| "(?:[eE][+-]?\d+)?\b"
|
||||||
until
|
if is_exp_token (c) then
|
||||||
i > n or not c.is_digit
|
--| "[eE][+-]?\d+"
|
||||||
loop
|
s.extend (c)
|
||||||
|
i := i + 1
|
||||||
|
c := a_number [i]
|
||||||
|
if c = token_plus or c = token_minus then
|
||||||
s.extend (c)
|
s.extend (c)
|
||||||
i := i + 1
|
i := i + 1
|
||||||
c := a_number [i]
|
if i <= n then
|
||||||
|
c := a_number [i]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if c.is_digit then
|
||||||
|
from
|
||||||
|
until
|
||||||
|
i > n or not c.is_digit
|
||||||
|
loop
|
||||||
|
s.extend (c)
|
||||||
|
i := i + 1
|
||||||
|
if i <= n then
|
||||||
|
c := a_number [i]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Result := False --| expecting digit
|
||||||
end
|
end
|
||||||
else
|
|
||||||
Result := False --| expecting digit
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
if Result then --| "\b"
|
||||||
if Result then --| "\b"
|
from
|
||||||
from
|
until
|
||||||
until
|
i > n or not c.is_space
|
||||||
i > n or not c.is_space
|
loop
|
||||||
loop
|
s.extend (c)
|
||||||
s.extend (c)
|
i := i + 1
|
||||||
i := i + 1
|
if i <= n then
|
||||||
c := a_number [i]
|
c := a_number [i]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Result := i > n and then s.same_string (a_number)
|
||||||
end
|
end
|
||||||
Result := i > n and then s.same_string (a_number)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -651,6 +674,6 @@ feature {NONE} -- Constants
|
|||||||
null_id: STRING = "null"
|
null_id: STRING = "null"
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
|
copyright: "2010-2015, Javier Velilla and others https://github.com/eiffelhub/json."
|
||||||
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
|
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user