1

Evidently in python: print u'\u0420\u043e\u0441\u0441\u0438\u044f'

outputs: Россия

How do I do this in Eiffel?

jjj
  • 23
  • 8

2 Answers2

1

On my linux OS, this code print exactly what you want:

make
        -- Initialisation of `Current'
    local
        l_utf_converter:UTF_CONVERTER
        l_string:STRING_32
    do
        create l_string.make_empty
        l_string.append_code (0x420)
        l_string.append_code (0x43e)
        l_string.append_code (0x441)
        l_string.append_code (0x441)
        l_string.append_code (0x438)
        l_string.append_code (0x44f)
        print(l_utf_converter.utf_32_string_to_utf_8_string_8 (l_string))
    end

In a nutshell, STRING_32 use UTF-32 and the linux console use UTF-8. The UTF_CONVERTER class can be use to convert UTF-32 to UTF-8.

I do not know if it is possible on a Windows console.

Louis M
  • 576
  • 2
  • 4
  • Doesn't really fit in a nutshell, but it works. Thanks. (I upvoted, but I don't have enough reputation to count, I guess.) – jjj Sep 11 '22 at 00:28
1

An example at the first page of eiffel.org (at the time of writintg) suggests the following code:

io.put_string_32 ("[
   Hello!
   ¡Hola!
   Bonjour!
   こんにちは!
   Здравствуйте!
   Γειά σου!
]")

It is supported since EiffelStudio 20.05. (I tested the example with EiffelStudio 22.05.)

In this particular case, using print instead of io.put_string_32 works as well. However, in some boundary cases, when all character codes in the string are below 256, you may need to specify the string type explicitly:

print ({STRING_32} "Zürich") -- All character code points are below 256.

Of course, you can write the character code points explicitly:

io.put_string_32 ("%/0x041f/%/0x0440/%/0x0438/%/0x0432/%/0x0435/%/0x0442/%/0x0021/")

The output code page defaults to UTF-8 for text files and the current console code page for CONSOLE (the standard object type of io). If needed, the default encoding can be changed to any other encoding:

io.standard_default.set_encoding ({SYSTEM_ENCODINGS}.console_encoding)
Alexander Kogtenkov
  • 5,770
  • 1
  • 27
  • 35