Mantis - Squeak
Viewing Issue Advanced Details
7603 XML-Yaxo major always 01-30-11 01:00 02-06-11 23:47
closed 4.1  
none trunk  
0007603: XMLWriter and MultiByteFileStream
XMLWriter in #writeXmlEncoded:
uses #next:putAll:startingAt:
but MultiByteFileStream doesn't implement it.
Instead it's implemented in StandardFileStream, but there it uses
If XMLWriter tried to write some WideString with some national characters part of the output file is written in UTF-8, and part is written in strange way using
null bytes etc. (it uses four bytes for one character, i suppose it's internal coding of squeak).

To reproduce try:
file:=FileStream fileNamed:'test.txt'.
xml:=XMLString string: 'abc
def' asWideString.
xml printOn: file

output file is (in hex): 61 0 0 0 62 0 0 0 63 0 0 0

On the other hand the following code works correctly:
file:=FileStream fileNamed:'test.txt'.
xml:=XMLString string: 'abcdef' asWideString.
xml printOn: file

01-30-11 02:23   
fast patch (not the best one...)

writeXmlEncoded: aString
    | lastIndex nextIndex |
    "Unroll the first search"
    lastIndex := 1.
    nextIndex := String
        findFirstInString: aString
        inSet: SpecialCharacters byteArrayMap
        startingAt: lastIndex.
    nextIndex isZero
        ifTrue: [^ self nextPutAll: aString].

    [nextIndex isZero]
        whileFalse: [| nextChar |
                "next: nextIndex - lastIndex putAll: aString startingAt: lastIndex;"
                nextPutAll: (aString copyFrom: lastIndex to: nextIndex - 1);
                    (((nextChar := aString at: nextIndex) == LineFeed or: [nextChar == CarriageReturn])
                        ifTrue: [self lineBreak]
                        ifFalse: [CharacterEscapes at: nextChar]).
            lastIndex := nextIndex + 1.
            nextIndex := String
                findFirstInString: aString
                inSet: SpecialCharacters byteArrayMap
                startingAt: lastIndex].

    "stream next: aString size - lastIndex + 1 putAll: aString startingAt: lastIndex."
    stream nextPutAll: (aString copyFrom: lastIndex to: aString size).
01-31-11 02:01   
Though I couldn't reproduce the bug with the given example, because there's no XMLString class in Squeak or the XML-Writer package, the issue related to Squeak is fixed in Multilingual-ul.135. The corresponding test is in MultilingualTests-ul.14.
01-31-11 02:22   
Ok. XMLString is in another package afair (also on squeaksource, [^]
But if it's solved it doesn't matter anymore. Thanks. :-D