From 8a2c8a9ad3f6f0bd8f4c529ba9fb440a7bf39f84 Mon Sep 17 00:00:00 2001 From: Jan Bliznicenko Date: Tue, 9 Jun 2020 15:55:39 +0200 Subject: [PATCH] writing line breaks --- repository/OP-XMI/OPXMIWriterVisitor.class.st | 5 ++-- ...PXMLPrettyPrintingWriterFormatter.class.st | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 repository/OP-XMI/OPXMLPrettyPrintingWriterFormatter.class.st diff --git a/repository/OP-XMI/OPXMIWriterVisitor.class.st b/repository/OP-XMI/OPXMIWriterVisitor.class.st index 7f1367b..18518db 100644 --- a/repository/OP-XMI/OPXMIWriterVisitor.class.st +++ b/repository/OP-XMI/OPXMIWriterVisitor.class.st @@ -4,7 +4,7 @@ Class { #instVars : [ 'writer' ], - #category : 'OP-XMI-Writer' + #category : #'OP-XMI-Writer' } { #category : #accessing } @@ -16,7 +16,8 @@ OPXMIWriterVisitor >> contents [ OPXMIWriterVisitor >> initialize [ super initialize. writer := XMLWriter new. - writer enablePrettyPrinting. + writer formatter: OPXMLPrettyPrintingWriterFormatter new. + writer lineBreak: ' '. writer xml encoding: 'UTF-8' ] diff --git a/repository/OP-XMI/OPXMLPrettyPrintingWriterFormatter.class.st b/repository/OP-XMI/OPXMLPrettyPrintingWriterFormatter.class.st new file mode 100644 index 0000000..ec0ae3f --- /dev/null +++ b/repository/OP-XMI/OPXMLPrettyPrintingWriterFormatter.class.st @@ -0,0 +1,27 @@ +Class { + #name : #OPXMLPrettyPrintingWriterFormatter, + #superclass : #XMLPrettyPrintingWriterFormatter, + #instVars : [ + 'lineBreak' + ], + #category : #'OP-XMI-Writer' +} + +{ #category : #writing } +OPXMLPrettyPrintingWriterFormatter >> lineBreak: aCharacterOrString [ + lineBreak := aCharacterOrString asString +] + +{ #category : #writing } +OPXMLPrettyPrintingWriterFormatter >> writeLineBreak [ + self writer atBeginning + ifFalse: [ self writer nextPutAll: lineBreak. + (self currentIndentLevel > 0 and: [ self indentString size > 0 ]) + ifTrue: [ self writeIndent ] ] +] + +{ #category : #writing } +OPXMLPrettyPrintingWriterFormatter >> writer: aWriter [ + super writer: aWriter. + lineBreak ifNil: [ lineBreak := aWriter lineBreak ] +]