]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorJoe Groff <arcata@gmail.com>
Wed, 3 Dec 2008 17:51:47 +0000 (09:51 -0800)
committerJoe Groff <arcata@gmail.com>
Wed, 3 Dec 2008 17:51:47 +0000 (09:51 -0800)
1  2 
basis/json/writer/writer.factor

index a7efe7ad0f37524bbffbf541addda45bf37ab8fb,e374919039aedeb2bb0ab078552df33597b822a7..79c7542dbb4f47d063b5abc11a55590b3c9c64b7
@@@ -9,23 -9,29 +9,32 @@@ IN: json.write
  GENERIC: json-print ( obj -- )
  
  : >json ( obj -- string )
-   #! Returns a string representing the factor object in JSON format
-   [ json-print ] with-string-writer ;
+     #! Returns a string representing the factor object in JSON format
+     [ json-print ] with-string-writer ;
  
 +M: t json-print ( f -- )
 +  drop "true" write ;
 +
  M: f json-print ( f -- )
-   drop "false" write ;
+     drop "false" write ;
+ M: t json-print ( t -- )
+     drop "true" write ;
+ M: json-null json-print ( null -- )
+     drop "null" write ;
  
  M: string json-print ( obj -- )
-   CHAR: " write1 "\"" split "\\\"" join CHAR: \r swap remove "\n" split "\\r\\n" join write CHAR: " write1 ;
+     CHAR: " write1 "\"" split "\\\"" join CHAR: \r swap remove "\n" split "\\r\\n" join write CHAR: " write1 ;
+ M: integer json-print ( num -- )
+     number>string write ;
  
- M: number json-print ( num -- )  
-   number>string write ;
+ M: real json-print ( num -- )
+     >float number>string write ;
  
  M: sequence json-print ( array -- ) 
-   CHAR: [ write1 [ >json ] map "," join write CHAR: ] write1 ;
+     CHAR: [ write1 [ >json ] map "," join write CHAR: ] write1 ;
  
  TR: jsvar-encode "-" "_" ;