![]() ![]() When $ZCONVERT is done then the new value of handle will either be the empty string or handle will contain the unconverted substring at the end of the input value. Evaluating $ZCONVERT(UnicodeText,"O","UTF8",handle) will do its conversion on an input value containing the concatenation of handle with UnicodeText. Fortunately, the $ZCONVERT function takes an optional fourth argument which is a local variable name. That incomplete sequence must be concatenated onto the beginning of the next BinaryText substring. Issue two: the "SET UnicodeText=$ZCONVERT(BinaryText,"I","UTF8")" statement might be given a BinaryText substring that ends with an incomplete UTF-8 sequence of characters. Only the very last call on the Base64Encode(substring) method can have a substring byte length which is not a multiple of 3. The new string length may not be a perfect multiple of 3 characters long and $64Encode converts sequences of 3 bytes into 4 bytes so when the Base64Encode(substring) method is called with a substring that has a non-multiple of 3 byte length then the extra 1 or 2 bytes at the end of the substring must be saved and then concatenated onto the beginning of the next substring to be passed to the Base64Encode(substring) method. Issue one: the SET BinaryText=$ZCONVERT(UnicodeText,"O","UTF8") statement can return more characters of BinaryText than there are characters of UnicodeText. So you will need to workaround some issues in the code that was part of the %64Encode Class Reference documentation. If you read from a long %Stream a sequence of substrings then it might not be possible to simply call $64Encode(BinaryText.) and $ZConvert(BinaryText,"I","UTF8") and because the substrings can be broken between binary bytes that must be combined in order to do the conversion. If you have a %Stream that is too long then you will need to loop over substrings of the %Stream and you should read on. Just execute the code excerpt from the %64Encode Class Reference documentation. Now if your Base64Encoded, UTF-8 encoded string cannot be longer than 3,641,144 bytes then you can ignore the rest of this reply. S UnicodeText=$ZCONVERT(BinaryText,"I","UTF8") s BinaryText=$ZCONVERT(UnicodeText,"O","UTF8") ![]() If you need to Base 64 encode an unicode string, you should first translate the string to UTF8 format, then encode it. The following documentation excerpt from the %64Encode Class Reference page will describe a first step at turning Unicode into a UTF-8 byte string and then applying the Base64 encoding to that byte string (but if your encoded stream exceeds the string limit in size then you will need to do more.) Note: Base 64 encoding is not able to encode a string which contains unicode (2 byte) characters. If you have a Unicode string with a character with an encoded value greater than 255 then direct Base64 encoding is not possible. Base64 encoding only works on strings of 8-bit bytes. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |