Best way to covert a ByteArray to a string with a particular encoding?
Hi guys. There is a method in Glorp that looks like this: Dialect >> #convert: aByteArray toStringWithEncoding: encodingName self isVisualWorks ifTrue: [^aByteArray asStringEncoding: encodingName]. self error: 'Not yet implemented'. So I wanted to implement it in Pharo. I thought about: self isPharo ifTrue: [ ^aByteArray asString convertToEncoding: encodingName ]. but I am not sure. Opinions? -- Mariano http://marianopeck.wordpress.com
On 10 Jul 2013, at 16:44, Mariano Martinez Peck <marianopeck@gmail.com> wrote:
Hi guys. There is a method in Glorp that looks like this:
Dialect >> #convert: aByteArray toStringWithEncoding: encodingName self isVisualWorks ifTrue: [^aByteArray asStringEncoding: encodingName]. self error: 'Not yet implemented'.
So I wanted to implement it in Pharo. I thought about:
self isPharo ifTrue: [ ^aByteArray asString convertToEncoding: encodingName ].
but I am not sure.
Opinions?
That is using the existing TextConverter framework. An alternative is to use ZnCharacterEncoder. (ZnCharacterEncoder newForEncoding: encodingName) decodeBytes: aByteArray. (ZnCharacterEncoder newForEncoding: encodingName) encodeString: aString. Sven
-- Mariano http://marianopeck.wordpress.com
participants (2)
-
Mariano Martinez Peck -
Sven Van Caekenberghe