..
   This file is part of Logtalk <https://logtalk.org/>  
   SPDX-FileCopyrightText: 1998-2023 Paulo Moura <pmoura@logtalk.org>
   SPDX-License-Identifier: Apache-2.0

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.


.. rst-class:: align-right

**directive**

.. index:: pair: encoding/1; Directive
.. _directives_encoding_1:

``encoding/1``
==============

Description
-----------

::

   encoding(Encoding)

Declares the source file text encoding. Requires a :term:`backend Prolog compiler`
supporting the chosen encoding. When used, this directive must be the first
term in the source file in the first line. This directive is also supported
in files included in a main file or in a dynamically created entity using
:ref:`directives_include_1` directives.

The encoding used in a source file (and, in the case of a Unicode
encoding, any BOM present) will be used for the intermediate Prolog
file generated by the compiler. Logtalk uses the encoding names specified by
`IANA <http://www.iana.org/assignments/character-sets/character-sets.xhtml>`_.
In those cases where a preferred MIME name alias is specified, the alias is
used instead. Examples includes ``'US-ASCII'``, ``'ISO-8859-1'``,
``'ISO-8859-2'``, ``'ISO-8859-15'``, ``'UCS-2'``, ``'UCS-2LE'``,
``'UCS-2BE'``, ``'UTF-8'``, ``'UTF-16'``, ``'UTF-16LE'``, ``'UTF-16BE'``,
``'UTF-32'``, ``'UTF-32LE'``, ``'UTF-32BE'``, ``'Shift_JIS'``, and
``'EUC-JP'``. When writing portable code that cannot be expressed using
ASCII, ``'UTF-8'`` is the most commonly supported Unicode encoding.

The backend Prolog compiler adapter files define a table that translates
between the Logtalk and Prolog specific atoms that represent each supported
encoding. The :ref:`encoding_directive <flag_encoding_directive>` read-only
flag can be used to find if a backend supports this directive and how.

Template and modes
------------------

::

   encoding(+atom)

Examples
--------

::

   :- encoding('UTF-8').
