Fixed implementation of JSON_PARSER.is_valid_number (STRING): BOOLEAN

This commit is contained in:
2015-01-08 18:57:31 +01:00
parent 0cc0ba047f
commit 33b555ff27
+30 -7
View File
@@ -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,32 +509,46 @@ 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
if i > n then
Result := False
else
c := a_number [i] 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
if i <= n then
c := a_number [i] 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*"
i := i + 1
if i <= n then
c := a_number [i]
from from
until until
i > n or not c.is_digit i > n or not c.is_digit
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
end end
end end
end end
end
end
if i > n then
-- Exit
else
if Result then if Result then
--| "(\.\d+)?" --| "(\.\d+)?"
if c = token_dot then if c = token_dot then
@@ -549,8 +563,10 @@ feature {NONE} -- Implementation
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
end
else else
Result := False --| expecting digit Result := False --| expecting digit
end end
@@ -565,8 +581,10 @@ feature {NONE} -- Implementation
if c = token_plus or c = token_minus then if c = token_plus or c = token_minus then
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
end
if c.is_digit then if c.is_digit then
from from
until until
@@ -574,8 +592,10 @@ feature {NONE} -- Implementation
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
end
else else
Result := False --| expecting digit Result := False --| expecting digit
end end
@@ -588,11 +608,14 @@ feature {NONE} -- Implementation
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
end
Result := i > n and then s.same_string (a_number) Result := i > n and then s.same_string (a_number)
end end
end end
end
is_valid_unicode (a_unicode: STRING): BOOLEAN is_valid_unicode (a_unicode: STRING): BOOLEAN
-- is 'a_unicode' a valid unicode based on the regular expression "\\u[0-9a-fA-F]{4}" . -- is 'a_unicode' a valid unicode based on the regular expression "\\u[0-9a-fA-F]{4}" .
@@ -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