Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is to convert a array of ASCII captured in http_resposse() even back a UTF-8 string
- string ascii_array_to_utf8(string byte_array)
- {
- integer len = llStringLength(byte_array);
- string s;
- integer i;
- while (i < len)
- {
- integer o = llOrd(byte_array, i);
- if (o < 128)
- {
- s += llChar(o);
- i += 1;
- }
- else if (o < 192)
- {
- // Invalid byte for the first byte of a multi-byte character
- s += "�";
- i += 1;
- }
- else if (o < 224 && i + 1 < len)
- {
- // 2-byte character
- s += llChar(((o & 31) << 6) | (llOrd(byte_array, i + 1) & 63));
- i += 2;
- }
- else if (o < 240 && i + 2 < len)
- {
- // 3-byte character
- s += llChar(((o & 15) << 12) | ((llOrd(byte_array, i + 1) & 63) << 6) | (llOrd(byte_array, i + 2) & 63));
- i += 3;
- }
- else if (i + 3 < len)
- {
- // 4-byte character
- s += llChar(((o & 7) << 18) | ((llOrd(byte_array, i + 1) & 63) << 12) | ((llOrd(byte_array, i + 2) & 63) << 6) | (llOrd(byte_array, i + 3) & 63));
- i += 4;
- }
- else
- {
- s += "�"; // Handle cases where the sequence is incomplete
- i += 1; // Move past the initial byte to prevent endless loop
- }
- }
- return s;
- }
Add Comment
Please, Sign In to add comment