wiki:League/TextCodec

Version 3 (modified by vadim.godunko, 10 years ago) ( diff )

--

Text Codec

Text Codec helps to convert text from external encoding into internal representation (Universal_String) and back.

Supported encodings

Character encoding Decoder Encoder
UTF-8 + +
UTF-16 (LE/BE) + -
ISO-8859-1 + -
Shift JIS + -
Windows-1250 - -
Windows-1251 + +
Windows-1252 - -
Windows-1253 - -
Windows-1254 - -
Windows-1255 - -
Windows-1256 - -
Windows-1257 - -
Windows-1258 - -

Example

This example outputs string using standard Ada.Streams.Stream_IO package, but correctly converting data into the locale character encoding.

with Ada.Streams.Stream_IO;

with League.Strings;
with League.Text_Codecs;

procedure Example is
   File : Ada.Streams.Stream_IO.File_Type;

begin
   Ada.Streams.Stream_IO.Create
    (File, Ada.Streams.Stream_IO.Out_File, "test.txt");
   Ada.Streams.Stream_IO.Write
    (File,
     League.Text_Codecs.Codec_For_Application_Locale.Encode
      (League.Strings.To_Universal_String
        ("Здравствуй, мир!")).To_Stream_Element_Array);
   Ada.Streams.Stream_IO.Close (File);
end Example;
Note: See TracWiki for help on using the wiki.