Hi Jon,
I9;m seeing the same behavior with asCharacter. An alternative is to use atPut on sequence.
Io> Sequence clone atPut(0, 198) at(0)
==> 198
asCharacter ends up setting the character first as ascii, and then converting the ascii to utf-8.
Io> 194 asCharacter asMutable setEncoding("ascii")
==> [0, 0]
Io> 231 asCharacter asMutable setEncoding("ascii") size
==> 4
The interesting bit, is 194 appears to go to all zeros...
Following through the C code translates into:
Io> s := Sequence clone setItemType("uint8") setEncoding("ascii") setSize(1) atPut(0, 198)
==> Æ
Io> s setEncoding("utf8")
==> Æ
Io> s convertToFixedSizeType
==>
Io> s size
==> 1
Io> s at(0)
==> 0
int UArray_convertToFixedSizeType(UArray *self)
{
if (self->encoding == CENCODING_UTF8)
{
int maxCharSize = UArray_maxCharSize(self);
if(maxCharSize == 1)
{
self->encoding = CENCODING_ASCII;
}
else if(maxCharSize == 2)
{
UArray_convertToUTF16(self);
}
else
{
UArray_convertToUTF32(self);
}
return 1;
}
return 0;
}
Io> s asUTF16 at(0)
==> 0
Io> s asUTF32 at(0)
==> 0
Io> s := Sequence clone setItemType("uint8") setEncoding("ascii") setSize(1) atPut(0, 198) setEncoding("utf8")
==> Æ
Io> s convertToFixedSizeType
maxCharSize: 2
Io> s := "abc" asMutable
==> abc
Io> s asUTF16
==> abc
Io> s atPut(1, 193)
==> aÁc
Io> s
==> aÁc
Io> s asUTF16
==> aIo>
==> nil
Io> s asUTF16 size
==> 3
Io> s asUTF16 at(0)
==> 97
Io> s asUTF16 at(1)
==> 0
Io> s asUTF16 at(2)
==> 0
Looks like the conversion functions aren't working. More digging for later.
Thanks,
Jonathan.
On 5/18/07, Jon Kleiser < jon.kleiser
usit.uio.no">jon.kleiser
usit.uio.no> wrote:
Using IoVM version 20050910 I could have this:
Io> 195 asCharacter at(0)
==> 195
However, if I use today's Io (on my PPC Mac), I notice that
n asCharacter at(0)
seems to give 0 for all values of n > 191.
If this is not a bug, then I would need some other way to generate
such high value characters.
/Jon
.