pUtf8Conv contains auxiliary functions for converting UTF-16 and ISO 8859-1 (Latin 1) to UTF-8 and back.

Dependencies: pAssert, pInterp, pName, pUtf8

API

pUtf8Conv.fromLatin1ToUtf8

Converts a Latin 1 (ISO 8859-1) string to UTF-8.

pUtf8Conv.fromLatin1ToUtf8(s)
  • s: The Latin 1 string to convert.

Returns: The converted UTF-8 string, or nil, error string, and byte index if there was a problem.


pUtf8Conv.fromUtf16ToUtf8

Converts a UTF-16 string to UTF-8.

pUtf8Conv.fromUtf16ToUtf8(s, [big_en])
  • s: The UTF-16 string to convert.

  • [big_en]: (nil) true if the input UTF-16 string is big-endian, false/nil if it is little-endian.

Returns: The converted UTF-8 string, or nil, error string, and byte index if there was a problem.


pUtf8Conv.fromUtf8ToLatin1

Converts a UTF-8 string to Latin 1 (ISO 8859-1).

Only code points 0 through 255 can be directly mapped to a Latin 1 string. Use the [unmapped] argument to control what happens when an unmappable code point is encountered.

pUtf8Conv.fromUtf8ToLatin1(s, [unmapped])
  • s: The UTF-8 string to convert.

  • [unmapped]: When unmapped is a string, it is used in place of unmappable code points. (Pass in an empty string to ignore unmappable code points.) When unmapped is any other type, the function returns nil, an error string, and the byte where the unmappable code point was encountered.

Returns: The converted Latin 1 string, or nil, error string, and byte index if there was a problem.


pUtf8Conv.fromUtf8ToUtf16

Converts a UTF-8 string to UTF-16.

pUtf8Conv.fromUtf8ToUtf16(s, [big_en])
  • s: The UTF-8 string to convert.

  • [big_en]: (nil) true if the converted UTF-16 string is big-endian, false/nil if it is little-endian.

Returns: The converted UTF-16 string, or nil, error string, and byte index if there was a problem.


VERSION: 2.106