Yes, I know the usefulness of the encoding parameter.
Meanwhile, I have realized that the encoding parameter affects the reading of the string from the memory.
At first I was confused and thought the encoding parameter is only important for the SaveXML(), because in the following code the output in all the three cases is correct.
Hint: #PB_Unicode uses for each character two bytes and #PB_UTF8 uses one to four bytes for each character.
Code: Select all
CompilerIf Not #PB_Compiler_Unicode
CompilerError "Run it in unicode mode!"
CompilerEndIf
XML$ = "<text>Hello?" + Chr(1000) + Chr(1200) + "</text>"
#XML = 0
CatchXML(#XML, @XML$, StringByteLength(XML$, #PB_Unicode), 0, #PB_Ascii)
Debug "CatchXML(#PB_Ascii): " + ComposeXML(#XML)
FreeXML(#XML)
CatchXML(#XML, @XML$, StringByteLength(XML$, #PB_Unicode), 0, #PB_UTF8)
Debug "CatchXML(#PB_UTF8): " + ComposeXML(#XML)
FreeXML(#XML)
CatchXML(#XML, @XML$, StringByteLength(XML$, #PB_Unicode), 0, #PB_Unicode)
Debug "CatchXML(#PB_Unicode): " + ComposeXML(#XML)
FreeXML(#XML)
Debug "---------------"
Debug "StringByteLength(): " + Str(StringByteLength(XML$))
Debug "StringByteLength(#PB_Ascii): " + Str(StringByteLength(XML$, #PB_Ascii))
Debug "StringByteLength(#PB_UTF8): " + Str(StringByteLength(XML$, #PB_UTF8))
Debug "StringByteLength(#PB_Unicode): " + Str(StringByteLength(XML$, #PB_Unicode))
Debug "----------------"
Debug "PeekS(#PB_Ascii): " + PeekS(@XML$, -1, #PB_Ascii)
Debug "PeekS(#PB_UTF8): " + PeekS(@XML$, -1, #PB_UTF8)
Debug "PeekS(#PB_Unicode): " + PeekS(@XML$, -1, #PB_Unicode)
Code: Select all
[20:18:28] CatchXML(#PB_Ascii): <?xml version="1.0" encoding="UTF-16"?><text>Hello?ϨҰ</text>
[20:18:28] CatchXML(#PB_UTF8): <?xml version="1.0" encoding="UTF-16"?><text>Hello?ϨҰ</text>
[20:18:28] CatchXML(#PB_Unicode): <?xml version="1.0" encoding="UTF-16"?><text>Hello?ϨҰ</text>
[20:18:28] ---------------
[20:18:28] StringByteLength(): 42
[20:18:28] StringByteLength(#PB_Ascii): 19
[20:18:28] StringByteLength(#PB_UTF8): 23
[20:18:28] StringByteLength(#PB_Unicode): 42
[20:18:28] ----------------
[20:18:28] PeekS(#PB_Ascii): <
[20:18:28] PeekS(#PB_UTF8): <
[20:18:28] PeekS(#PB_Unicode): <text>Hello?ϨҰ</text>
As you can see, CatchXML() doesn't work like PeekS().