Mantis - Squeak
Viewing Issue Advanced Details
7603 XML-Yaxo major always 01-30-11 01:00 02-06-11 23:47
unoduetre  
leves  
normal  
closed 4.1  
fixed  
none    
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
#primWrite:from:startingAt:
So!
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

Notes
(0014035)
unoduetre   
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 |
            stream
                "next: nextIndex - lastIndex putAll: aString startingAt: lastIndex;"
                nextPutAll: (aString copyFrom: lastIndex to: nextIndex - 1);
                nextPutAll:
                    (((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).
(0014038)
leves   
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.
(0014039)
unoduetre   
01-31-11 02:22   
Ok. XMLString is in another package afair (also on squeaksource, http://www.squeaksource.com/XMLSupport) [^]
But if it's solved it doesn't matter anymore. Thanks. :-D