Did you know ... Search Documentation:
utf8.pl -- UTF-8 encoding/decoding on lists of character codes.
PublicShow source
Source utf8_codes(?Codes)// is det
DCG translating between a Unicode code-list and its UTF-8 encoded byte-string. The DCG works two ways. Encoding a code-list to a UTF-8 byte string is achieved using
phrase(utf8_codes(Codes), UTF8)

The algorithm is a close copy of the C-algorithm used internally and defined in src/pl-utf8.c

NOTE: in many cases you can avoid this library and leave encoding and decoding to I/O streams. If only part of the data is to be encoded the encoding of a stream can be switched temporary using set_stream(Stream, encoding(utf8))

See also
- set_stream/2.