Last active
December 22, 2015 08:39
-
-
Save SaitoAtsushi/6446127 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -r dc3cb8ca8a4d sitelib/json.scm | |
--- a/sitelib/json.scm Wed Sep 04 22:14:31 2013 +0200 | |
+++ b/sitelib/json.scm Thu Sep 05 13:33:27 2013 +0900 | |
@@ -128,16 +128,35 @@ | |
(if (char=? (parse-results-token-value results) (string-ref str pos)) | |
(loop (+ pos 1) (parse-results-next results)) | |
(make-expected-result (parse-results-position starting-results) str)))))) | |
+ (define (interpret-string-unicode-escape results k) | |
+ (let loop ((i 0) | |
+ (acc '()) | |
+ (results results)) | |
+ (let ((ch (parse-results-token-value results))) | |
+ (cond ((= i 4) | |
+ (k | |
+ (integer->char (string->number (list->string (reverse acc)) 16)) | |
+ results)) | |
+ ((memv ch '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 #\a #\b #\c #\d #\e #\f #\A #\B #\C #\D #\E #\F)) | |
+ (loop (+ i 1) | |
+ (cons ch acc) | |
+ (parse-results-next results))) | |
+ (else (error 'json-read "JSON Parse Error")))))) | |
(define (interpret-string-escape results k) | |
(let ((ch (parse-results-token-value results))) | |
- (k (cond | |
- ((assv ch '((#\b . #\backspace) | |
- (#\n . #\newline) | |
- (#\f . #\page) | |
- (#\r . #\return) | |
- (#\t . #\tab))) => cdr) ;; we don't support the "u" escape for unicode | |
- (else ch)) | |
- (parse-results-next results)))) | |
+ (cond | |
+ ((assv ch '((#\b . #\backspace) | |
+ (#\n . #\newline) | |
+ (#\f . #\page) | |
+ (#\r . #\return) | |
+ (#\t . #\tab))) => | |
+ (lambda(x)(k (cdr x) | |
+ (parse-results-next results)))) ;; we don't support the "u" escape for unicode | |
+ ((eqv? #\u ch) | |
+ (interpret-string-unicode-escape | |
+ (parse-results-next results) | |
+ k)) | |
+ (else (k ch (parse-results-next results)))))) | |
(define (jstring-body results) | |
(let loop ((acc '()) (results results)) | |
(let ((ch (parse-results-token-value results))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment