changeset 166:e7642715d575

Handle newlines and carriage returns in JSON decoder
author Mike Pavone <pavone@retrodev.com>
date Sun, 11 Aug 2013 02:31:33 -0700
parents fe816637fcc4
children 5a6a55592c45
files modules/json.tp
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/modules/json.tp	Sun Aug 11 00:58:50 2013 -0700
+++ b/modules/json.tp	Sun Aug 11 02:31:33 2013 -0700
@@ -11,6 +11,8 @@
 	space <- " " byte: 0
 	comma <- "," byte: 0
 	tab <- "\t" byte: 0
+	nl <- "\n" byte: 0
+	cr <- "\r" byte: 0
 	colon <- ":" byte: 0
 	t <- "t" byte: 0
 	f <- "f" byte: 0
@@ -75,7 +77,7 @@
 							aft <- cur + 1
 							cur <- len
 						} else: {
-							if: b = comma || b = space || b = tab {
+							if: b = comma || b = space || b = tab || b = nl || b = cr {
 								cur <- cur + 1
 							} else: {
 								el <- _decode: text at: cur
@@ -98,7 +100,7 @@
 						key <- ""
 						while: { cur < len } do: {
 							b <- text byte: cur
-							if: b = comma || b = space || b = tab || b = colon {
+							if: b = comma || b = space || b = tab || b = colon || b = nl || b = cr {
 								cur <- cur + 1
 							} else: {
 								if: expectKey {