API: utf8
Source:
utils/utf8.ts
Utility class for performing UTF-8 encoding and decoding operations. It provides methods to handle conversions between standard JavaScript strings and raw UTF-8 byte representations.
Usage
import { utf8 } from "sdk/utils";
import { response } from "sdk/http";
response.println(JSON.stringify(utf8.encode("mystring")));
response.flush();
response.close();Classes
UTF8
Utility class for performing UTF-8 encoding and decoding operations.
It provides methods to handle conversions between standard JavaScript strings and
raw UTF-8 byte representations.
Methods
encode
encode (input:string|any[]):stringEncodes the input (either a standard JavaScript string or a raw byte array)
into a UTF-8 encoded string representation.
@param input The text string to be encoded, or a byte array to convert to its string representation.
@returns The resulting UTF-8 encoded string.
decode
decode (input:string|any[]):stringDecodes the input (either a UTF-8 encoded string or a raw byte array)
back into a standard JavaScript string.
@param input The UTF-8 encoded string or byte array to be decoded.
@returns The resulting standard decoded string.
bytesToString
bytesToString (bytes:any[], offset:number, length:number):stringDecodes a specific segment of a raw byte array into a standard string
using UTF-8 encoding.
@param bytes The raw byte array containing the UTF-8 data.
@param offset The starting index (inclusive) from which to begin decoding.
@param length The number of bytes to decode starting from the offset.
@returns The decoded string segment.