Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

changed STONWriter>>#encodeList: and #encodeMap: so that empty lists …

…and maps are pretty printed much more compactly
  • Loading branch information...
commit 6b474e14ed4b8912e151bd401a0592f41a985167 1 parent 4023128
@svenvc authored
View
16 repository/Ston-Core.package/STONWriter.class/instance/encodeList..st
@@ -1,10 +1,14 @@
writing
encodeList: elements
writeStream nextPut: $[.
- self indentedDo: [
- self newlineIndent.
- elements
- do: [ :each | self nextPut: each ]
- separatedBy: [ self listElementSeparator ] ].
- self newlineIndent.
+ elements isEmpty
+ ifTrue: [
+ self prettyPrintSpace ]
+ ifFalse: [
+ self indentedDo: [
+ self newlineIndent.
+ elements
+ do: [ :each | self nextPut: each ]
+ separatedBy: [ self listElementSeparator ] ].
+ self newlineIndent ].
writeStream nextPut: $]
View
20 repository/Ston-Core.package/STONWriter.class/instance/encodeMap..st
@@ -3,12 +3,16 @@ encodeMap: pairs
| first |
first := true.
writeStream nextPut: ${.
- self indentedDo: [
- self newlineIndent.
- pairs keysAndValuesDo: [ :key :value |
- first
- ifTrue: [ first := false ]
- ifFalse: [ self mapElementSeparator ].
- self encodeKey: key value: value ] ].
- self newlineIndent.
+ pairs isEmpty
+ ifTrue: [
+ self prettyPrintSpace ]
+ ifFalse: [
+ self indentedDo: [
+ self newlineIndent.
+ pairs keysAndValuesDo: [ :key :value |
+ first
+ ifTrue: [ first := false ]
+ ifFalse: [ self mapElementSeparator ].
+ self encodeKey: key value: value ] ].
+ self newlineIndent ].
writeStream nextPut: $}
View
2  repository/Ston-Core.package/monticello.meta/version
@@ -1 +1 @@
-(name 'Ston-Core-SvenVanCaekenberghe.31' message 'forced ancestry' id 'a985dbf8-da24-4cef-95d5-d7ede4024b38' date '3 May 2012' time '7:21:07 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.30' message 'update STON class comment for Markdown compatibility' id 'c11b7730-ae99-4b4a-99a9-ba7e5d99e084' date '29 April 2012' time '12:23:33 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.29' message 'added an internal optimalization to STONReader: by tracking unresolved references while parsing, it should be possible to avoid processing all subobjects after parsing' id 'da09472b-ff70-46e4-9896-a661d0c3e7a0' date '27 April 2012' time '8:48:21 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.28' message 'improved JSON backwards compatibility: - STONReader>>parseValue now accepts null as well as nil - STONWriter now has a jsonMode switch as well as referencePolicy' id '30ef0a69-9fcb-4405-bf1e-8896eaad0a92' date '27 April 2012' time '2:24:51 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.27' message 'extended the parser to allow either single or double quotes as String delimiters which gives us JSON backward compatibilty ! (thanks Dale Henrichs for this great idea).' id 'dd7c16b2-950c-4246-bf60-130de447cddf' date '24 April 2012' time '10:13:07 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.26' message 'changed String from being treated as regular shareable objects to primitive non-shareable objecst (like symbols)' id '625ef901-63d3-45e4-aae8-0e6e45d0a17a' date '29 February 2012' time '9:55 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.25' message 'fixed a bug with simple symbol encoding' id '44044c81-1442-4b76-a859-dad8d1a20e89' date '14 February 2012' time '5:54:32 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.24' message 'small patch to #parseReference' id 'b34aa232-b13d-4229-900f-11299f7e4b2f' date '13 February 2012' time '10:19:58 am' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.23' message 'added comments to key methods at Object and Class level introduced STONWriter>>#writeObject:listSingleton:' id 'af63b9b7-b353-4ee5-8051-2b8a9c3c7470' date '12 February 2012' time '8:10:17 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.22' message 'various refactoring & cleanup' id 'dc815ef3-cd2e-4902-997d-b0cff2de3d4e' date '12 February 2012' time '7:32:13 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.21' message 'listening to code critics' id '1f2538e9-bca1-4664-8829-fda4b88d1f13' date '12 February 2012' time '4:02:53 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.20' message 'refactored #fromSton: to accept an STONReader instance as argument and call either #parseListDo: or #parseMapDo: added new shortcut #parseListSingleton moved code from HashedCollection back to Dictionary, implemented map encoding for all Dictionary subclasses, added #fromSton: to Dictionary to accept map now using #streamContents: for all SequenceableCollection subclasses' id '31c9ddcb-7917-4eac-98d7-31a4f565f778' date '12 February 2012' time '3:32:50 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.19' message 'added a mechanism to allow renaming classes, see #stonClass' id 'aea34a58-1174-479c-9db0-fb3310927967' date '12 February 2012' time '10:24:02 am' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.18' message 'first optimizations: faster character classification, reusable string stream while reading strings, symbols and class names' id 'c959398b-8d4c-49e5-a1e0-43b3d158e305' date '10 February 2012' time '8:38:45 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.17' message 'implemented generic Collection serialization' id '7189db52-c5ba-472a-8e74-3b2eb1970d69' date '8 February 2012' time '9:09:15 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.16' message 'added support for Character' id '8ad36126-e4bc-42da-bfa5-520550a3f2d8' date '8 February 2012' time '3:10:24 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.15' message 'fixed Object>>#stonOn: to use #allInstVarNames; refactored STONWriter>>#encodeString: with extracted #encodeCharacter:' id '7f3d2584-b397-411b-9886-1a1ea135a261' date '8 February 2012' time '2:53:23 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.14' message 'implemented generic #stonProcessSubObjects: at the Object level; implemented generic #toSton: and #fromSton: at the Object level; added generic Object class>>#fromSton: and simplified #parseObject' id '077fc63e-e5fe-4645-a40c-564cd5d48f4f' date '8 February 2012' time '9:08:16 am' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.13' message 'introduced STONReaderError' id '51cabecf-e854-4e39-9140-fc9f64b77c61' date '24 January 2012' time '10:49:51 am' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.12' message 'introduction of STON class; renamed array -> list and dictionary -> map' id '09f81db8-0261-4aef-a239-783035e6364b' date '24 January 2012' time '10:13:34 am' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.11' message 'introduced streaming encoding with STONWriter>>#writeObject:stream[ShortArray|Array|Dictionary]:' id 'e2c79a6e-96d5-4038-8e48-da0153a61cfa' date '23 January 2012' time '5:02:15 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.10' message 'moved some methods on STONTestUser from Ston-Core to Ston-Tests' id '37790927-a6b6-4758-80f7-b312b5efd1e7' date '23 January 2012' time '2:32:21 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.9' message 'debugged pretty printed output parsing; added support for OrderedCollection; changed pretty printing to write closing tags on a new line' id '51db4eb5-a0e4-407c-84d7-f1c9077cdc69' date '23 January 2012' time '12:33:48 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.8' message 'added pretty printing to STONWriter; introduced STONWriter>>#encodeShortArray:' id 'fe506e59-3842-4214-ba53-27e58d4d062a' date '23 January 2012' time '11:54 am' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.7' message 'added Time and Date support' id '66bf47c8-270b-4108-9b4f-d4c06245a701' date '23 January 2012' time '9:54:09 am' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.6' message 'all unit tests pass; added ByteArray and DateAndTime/TimeStamp serialization/materialization' id '7622b8d5-65c9-4f70-bbd1-dc747e20b9b0' date '19 January 2012' time '10:52:07 am' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.5' message 'first working version, except ByteArray materialize' id 'fac82cee-be20-4e6f-95fc-40fc92efcc92' date '18 January 2012' time '9:56:11 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.4' message 'tmp checkin; start with STONReference' id '44703435-d1fe-4074-9817-8f6197da073f' date '18 January 2012' time '7:57:26 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.3' message 'first implementation of Objects and shared references; problems with cycle references' id 'f78218b6-334d-4603-9ac9-3d412410ce1c' date '17 January 2012' time '10:17:47 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.2' message 'some minor cleanup' id 'e627ecd0-cb85-4c8e-9558-51ceb8ae7e28' date '17 January 2012' time '7:35:56 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.1' message 'basic code working, except full objects and references' id '2980ed1b-f650-4b9d-b180-9cdee7bbf21a' date '16 January 2012' time '1:46:59 pm' author 'SvenVanCaekenberghe' ancestors () stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())
+(name 'Ston-Core-SvenVanCaekenberghe.32' message 'changed STONWriter>>#encodeList: and #encodeMap: so that empty lists and maps are pretty printed much more compactly' id '9855d58c-0f64-4c7b-855f-c9afcc5bafd0' date '5 May 2012' time '8:36:27 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.31' message 'forced ancestry' id 'a985dbf8-da24-4cef-95d5-d7ede4024b38' date '3 May 2012' time '7:21:07 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.30' message 'update STON class comment for Markdown compatibility' id 'c11b7730-ae99-4b4a-99a9-ba7e5d99e084' date '29 April 2012' time '12:23:33 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.29' message 'added an internal optimalization to STONReader: by tracking unresolved references while parsing, it should be possible to avoid processing all subobjects after parsing' id 'da09472b-ff70-46e4-9896-a661d0c3e7a0' date '27 April 2012' time '8:48:21 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.28' message 'improved JSON backwards compatibility: - STONReader>>parseValue now accepts null as well as nil - STONWriter now has a jsonMode switch as well as referencePolicy' id '30ef0a69-9fcb-4405-bf1e-8896eaad0a92' date '27 April 2012' time '2:24:51 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.27' message 'extended the parser to allow either single or double quotes as String delimiters which gives us JSON backward compatibilty ! (thanks Dale Henrichs for this great idea).' id 'dd7c16b2-950c-4246-bf60-130de447cddf' date '24 April 2012' time '10:13:07 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.26' message 'changed String from being treated as regular shareable objects to primitive non-shareable objecst (like symbols)' id '625ef901-63d3-45e4-aae8-0e6e45d0a17a' date '29 February 2012' time '9:55 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.25' message 'fixed a bug with simple symbol encoding' id '44044c81-1442-4b76-a859-dad8d1a20e89' date '14 February 2012' time '5:54:32 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.24' message 'small patch to #parseReference' id 'b34aa232-b13d-4229-900f-11299f7e4b2f' date '13 February 2012' time '10:19:58 am' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.23' message 'added comments to key methods at Object and Class level introduced STONWriter>>#writeObject:listSingleton:' id 'af63b9b7-b353-4ee5-8051-2b8a9c3c7470' date '12 February 2012' time '8:10:17 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.22' message 'various refactoring & cleanup' id 'dc815ef3-cd2e-4902-997d-b0cff2de3d4e' date '12 February 2012' time '7:32:13 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.21' message 'listening to code critics' id '1f2538e9-bca1-4664-8829-fda4b88d1f13' date '12 February 2012' time '4:02:53 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.20' message 'refactored #fromSton: to accept an STONReader instance as argument and call either #parseListDo: or #parseMapDo: added new shortcut #parseListSingleton moved code from HashedCollection back to Dictionary, implemented map encoding for all Dictionary subclasses, added #fromSton: to Dictionary to accept map now using #streamContents: for all SequenceableCollection subclasses' id '31c9ddcb-7917-4eac-98d7-31a4f565f778' date '12 February 2012' time '3:32:50 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.19' message 'added a mechanism to allow renaming classes, see #stonClass' id 'aea34a58-1174-479c-9db0-fb3310927967' date '12 February 2012' time '10:24:02 am' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.18' message 'first optimizations: faster character classification, reusable string stream while reading strings, symbols and class names' id 'c959398b-8d4c-49e5-a1e0-43b3d158e305' date '10 February 2012' time '8:38:45 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.17' message 'implemented generic Collection serialization' id '7189db52-c5ba-472a-8e74-3b2eb1970d69' date '8 February 2012' time '9:09:15 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.16' message 'added support for Character' id '8ad36126-e4bc-42da-bfa5-520550a3f2d8' date '8 February 2012' time '3:10:24 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.15' message 'fixed Object>>#stonOn: to use #allInstVarNames; refactored STONWriter>>#encodeString: with extracted #encodeCharacter:' id '7f3d2584-b397-411b-9886-1a1ea135a261' date '8 February 2012' time '2:53:23 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.14' message 'implemented generic #stonProcessSubObjects: at the Object level; implemented generic #toSton: and #fromSton: at the Object level; added generic Object class>>#fromSton: and simplified #parseObject' id '077fc63e-e5fe-4645-a40c-564cd5d48f4f' date '8 February 2012' time '9:08:16 am' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.13' message 'introduced STONReaderError' id '51cabecf-e854-4e39-9140-fc9f64b77c61' date '24 January 2012' time '10:49:51 am' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.12' message 'introduction of STON class; renamed array -> list and dictionary -> map' id '09f81db8-0261-4aef-a239-783035e6364b' date '24 January 2012' time '10:13:34 am' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.11' message 'introduced streaming encoding with STONWriter>>#writeObject:stream[ShortArray|Array|Dictionary]:' id 'e2c79a6e-96d5-4038-8e48-da0153a61cfa' date '23 January 2012' time '5:02:15 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.10' message 'moved some methods on STONTestUser from Ston-Core to Ston-Tests' id '37790927-a6b6-4758-80f7-b312b5efd1e7' date '23 January 2012' time '2:32:21 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.9' message 'debugged pretty printed output parsing; added support for OrderedCollection; changed pretty printing to write closing tags on a new line' id '51db4eb5-a0e4-407c-84d7-f1c9077cdc69' date '23 January 2012' time '12:33:48 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.8' message 'added pretty printing to STONWriter; introduced STONWriter>>#encodeShortArray:' id 'fe506e59-3842-4214-ba53-27e58d4d062a' date '23 January 2012' time '11:54 am' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.7' message 'added Time and Date support' id '66bf47c8-270b-4108-9b4f-d4c06245a701' date '23 January 2012' time '9:54:09 am' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.6' message 'all unit tests pass; added ByteArray and DateAndTime/TimeStamp serialization/materialization' id '7622b8d5-65c9-4f70-bbd1-dc747e20b9b0' date '19 January 2012' time '10:52:07 am' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.5' message 'first working version, except ByteArray materialize' id 'fac82cee-be20-4e6f-95fc-40fc92efcc92' date '18 January 2012' time '9:56:11 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.4' message 'tmp checkin; start with STONReference' id '44703435-d1fe-4074-9817-8f6197da073f' date '18 January 2012' time '7:57:26 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.3' message 'first implementation of Objects and shared references; problems with cycle references' id 'f78218b6-334d-4603-9ac9-3d412410ce1c' date '17 January 2012' time '10:17:47 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.2' message 'some minor cleanup' id 'e627ecd0-cb85-4c8e-9558-51ceb8ae7e28' date '17 January 2012' time '7:35:56 pm' author 'SvenVanCaekenberghe' ancestors ((name 'Ston-Core-SvenVanCaekenberghe.1' message 'basic code working, except full objects and references' id '2980ed1b-f650-4b9d-b180-9cdee7bbf21a' date '16 January 2012' time '1:46:59 pm' author 'SvenVanCaekenberghe' ancestors () stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())
Please sign in to comment.
Something went wrong with that request. Please try again.