Skip to content

Commit 33b555f

Browse files
committed
Fixed implementation of JSON_PARSER.is_valid_number (STRING): BOOLEAN
1 parent 0cc0ba0 commit 33b555f

File tree

1 file changed

+82
-59
lines changed

1 file changed

+82
-59
lines changed

library/parser/json_parser.e

Lines changed: 82 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
note
22
description: "Parse serialized JSON data"
3-
author: "$Author: jfiat $"
4-
date: "$Date: 2014-11-17 11:54:05 +0100 (lun., 17 nov. 2014) $"
5-
revision: "$Revision: 96099 $"
3+
author: "$Author$"
4+
date: "$Date$"
5+
revision: "$Revision$"
66

77
class
88
JSON_PARSER
@@ -509,88 +509,111 @@ feature {NONE} -- Implementation
509509
if c = token_minus then
510510
s.extend (c)
511511
i := i + 1
512-
c := a_number [i]
512+
if i > n then
513+
Result := False
514+
else
515+
c := a_number [i]
516+
end
513517
end
514518
--| "0|[1-9]\d*
515-
if c.is_digit then
519+
if Result and c.is_digit then
516520
if c = '0' then
517521
--| "0"
518522
s.extend (c)
519523
i := i + 1
520-
c := a_number [i]
524+
if i <= n then
525+
c := a_number [i]
526+
end
521527
else
522528
--| "[1-9]"
523529
s.extend (c)
524-
i := i + 1
525-
c := a_number [i]
530+
526531
--| "\d*"
527-
from
528-
until
529-
i > n or not c.is_digit
530-
loop
531-
s.extend (c)
532-
i := i + 1
532+
i := i + 1
533+
if i <= n then
533534
c := a_number [i]
535+
from
536+
until
537+
i > n or not c.is_digit
538+
loop
539+
s.extend (c)
540+
i := i + 1
541+
if i <= n then
542+
c := a_number [i]
543+
end
544+
end
534545
end
535546
end
536547
end
537548
end
538-
if Result then
539-
--| "(\.\d+)?"
540-
if c = token_dot then
541-
--| "\.\d+" = "\.\d\d*"
542-
s.extend (c)
543-
i := i + 1
544-
c := a_number [i]
545-
if c.is_digit then
546-
from
547-
until
548-
i > n or not c.is_digit
549-
loop
550-
s.extend (c)
551-
i := i + 1
552-
c := a_number [i]
549+
if i > n then
550+
-- Exit
551+
else
552+
if Result then
553+
--| "(\.\d+)?"
554+
if c = token_dot then
555+
--| "\.\d+" = "\.\d\d*"
556+
s.extend (c)
557+
i := i + 1
558+
c := a_number [i]
559+
if c.is_digit then
560+
from
561+
until
562+
i > n or not c.is_digit
563+
loop
564+
s.extend (c)
565+
i := i + 1
566+
if i <= n then
567+
c := a_number [i]
568+
end
569+
end
570+
else
571+
Result := False --| expecting digit
553572
end
554-
else
555-
Result := False --| expecting digit
556573
end
557574
end
558-
end
559-
if Result then --| "(?:[eE][+-]?\d+)?\b"
560-
if is_exp_token (c) then
561-
--| "[eE][+-]?\d+"
562-
s.extend (c)
563-
i := i + 1
564-
c := a_number [i]
565-
if c = token_plus or c = token_minus then
575+
if Result then --| "(?:[eE][+-]?\d+)?\b"
576+
if is_exp_token (c) then
577+
--| "[eE][+-]?\d+"
566578
s.extend (c)
567579
i := i + 1
568580
c := a_number [i]
569-
end
570-
if c.is_digit then
571-
from
572-
until
573-
i > n or not c.is_digit
574-
loop
581+
if c = token_plus or c = token_minus then
575582
s.extend (c)
576583
i := i + 1
577-
c := a_number [i]
584+
if i <= n then
585+
c := a_number [i]
586+
end
587+
end
588+
if c.is_digit then
589+
from
590+
until
591+
i > n or not c.is_digit
592+
loop
593+
s.extend (c)
594+
i := i + 1
595+
if i <= n then
596+
c := a_number [i]
597+
end
598+
end
599+
else
600+
Result := False --| expecting digit
578601
end
579-
else
580-
Result := False --| expecting digit
581602
end
582603
end
583-
end
584-
if Result then --| "\b"
585-
from
586-
until
587-
i > n or not c.is_space
588-
loop
589-
s.extend (c)
590-
i := i + 1
591-
c := a_number [i]
604+
if Result then --| "\b"
605+
from
606+
until
607+
i > n or not c.is_space
608+
loop
609+
s.extend (c)
610+
i := i + 1
611+
if i <= n then
612+
c := a_number [i]
613+
end
614+
end
615+
Result := i > n and then s.same_string (a_number)
592616
end
593-
Result := i > n and then s.same_string (a_number)
594617
end
595618
end
596619

@@ -651,6 +674,6 @@ feature {NONE} -- Constants
651674
null_id: STRING = "null"
652675

653676
note
654-
copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json."
677+
copyright: "2010-2015, Javier Velilla and others https://github.com/eiffelhub/json."
655678
license: "https://github.com/eiffelhub/json/blob/master/License.txt"
656679
end

0 commit comments

Comments
 (0)