[serializerclass-general] mbcs fix; oh you fixed it already, which fix is right?
Brought to you by:
sephiroth_tmm
From: Jamie P <ja...@e-...> - 2005-01-14 08:47:44
|
Hi all, While reworking PHPobject I came across a bug in Alessandro's serializer class multibyte support. I have tried to fix the deserialize function which wasn't handling MB strings properly. Here are the main changes (- marks the old code + the new): + private function getCStringLength ():Number { + var colon:Number = this.buffer.indexOf (":", 3); // index of second colon + var ss:Number = colon+2; // index of start of string + var len:Number = parseInt (this.buffer.substr (2, colon - 2)); var i:Number; - var j:Number = len; + var j:Number = len; //char length of string to be calculated + var c:Number; var cstr = this.buffer; - for (i = 0; i < j; i++) + for (i = ss; i < (ss + j); i++) { - if (cstr.charCodeAt (i + 5) > 128) - { - j = j - 2; + c=cstr.charCodeAt(i); + + if (c<128) { + //do nothing + }else if (c<1024) { + j = j-1; + } else if (c<32768) { + j = j-2; + } else if (c<2097152) { + j = j-3; } } return j; - }; // getCStringLenght + }; // getCStringLength I am now hoping to get PHPobject working with UTF-8 without all the escaping and urlencoding that is being used now, which I think is largely or probably completely unnecessary. I see that there is already a fix for this issue in the CVS! But my fix is different to yours. My fix does the reverse of your serialize function. Which is right I wonder?? I'm not sure how utf-8 is encoded in Flash. According to the Flash docs then char code can only go to 65535. Jamie |