0

I have a simple euro_to_dm command line program written but the "€" symbol doesn't work. The example change every time "dm to euro" but not "€ to dm". Sorry for my English.

Ubuntu 19.4 ise-eiffel AND liberty-eiffel

class EURO

inherit ARGUMENTS_32

create {ANY}
   make

feature {ANY}

   make
      do
         works_not
      end

   works_not
      local ok: BOOLEAN
      do
         print ("%N%NAnzahl Argumente : " + argument_count.out + "%N")
         print ("%NArgument -> Programmname    : " + argument(0))
         print ("%NArgument -> Wert            : " + argument(1))
         print ("%NArgument -> Währung         : " + argument(2) + "%N")

         ok := argument(2).is_equal("€")     
         print ("%NArgument(2) ist Euro ?  " + ok.out + "%N%N")

         print ("don't work")
         io.put_new_line

         if argument(2).is_equal("€") then
            euro_in_dm(argument(1).to_real)
         else
            dm_in_euro(argument(1).to_real)
         end
      end


feature {ANY}

   euro_in_dm (a: REAL)
      do
         io.put_string("%N Euro -> DM ")
         io.put_real(a * 1.95583)
         io.put_string("%N%N")
      end

   dm_in_euro (a: REAL)
      do
         io.put_string("%N DM -> Euro ")
         io.put_real(a / 1.95583)
         io.put_string("%N%N")
      end

end
GSerg
  • 76,472
  • 17
  • 159
  • 346

2 Answers2

0

To create manifest Unicode string, you should use {STRING_32} "€"

To compare strings, you'd better use same_string, i.e if s.same_string ({STRING_32} "€") then ...

Note the syntax for manifest Unicode character using the hexadecimal value is {CHARACTER_32} '%/0x20AC/'

To output Unicode in console/terminal, it is better to use the LOCALIZED_PRINTER from the encoding library.

see https://www.eiffel.org/blog/jocelyn_fiat/lets_talk_about_the_encoding_library#Write_unicode_into_the_console

Jocelyn
  • 693
  • 5
  • 8
  • also be aware that `"foo" + {STRING_32} "%/20AC/"` will not do what you want, as the expression looks like `{STRING_8} + {STRING_32}.as_string_8`. So you should really do `{STRING_32} "foo" + {STRING_32} "%/20AC/"` , or use a local `s: STRING_32`, then use the `append` method. – Jocelyn Jun 09 '19 at 12:55
  • lock at the next line - don’t work : if argument(2).same_string({STRING_32}"€") then euro_in_dm(argument(1).to_real) else dm_in_euro(argument(1).to_real) end end – user7450201 Jun 10 '19 at 09:52
0

Here the program that works (this is in spanish). You should include the library encoding to your project. You cannot show the symbol € with print, you should use localized_print.

class
    EURO

inherit
    ARGUMENTS_32
    LOCALIZED_PRINTER

create
    make

feature {ANY}

   make
      do
         works_not
      end

   works_not
      local ok: BOOLEAN
      do
         print ("%N%NArgumentos                 : " + argument_count.out + "%N")
         print ("%NArgument -> Programa         : " + argument(0) + "%N")
         print ("%NArgument -> Valor            : " + argument(1) + "%N")
         localized_print ({STRING_32} "%NArgument -> Moneda           : " + argument(2) + {STRING_32} "%N")

         ok := argument(2).item(argument(2).lower).is_equal ('%/0x000020AC/')
         print ("%NArgument(2) ist Euro ?  " + ok.out + "%N%N")

         if ok then
            euro_in_dm(argument(1).to_real)
         else
            dm_in_euro(argument(1).to_real)
         end
      end


feature {ANY}

   euro_in_dm (a: REAL)
      do
         io.put_string("%N Euro -> DM ")
         io.put_real(a * 1.95583)
         io.put_string("%N%N")
      end

   dm_in_euro (a: REAL)
      do
         io.put_string("%N DM -> Euro ")
         io.put_real(a / 1.95583)
         io.put_string("%N%N")
      end
  • don't work too. Problem ise-eiffel don't found localized_printer. ise19_05 – user7450201 Jun 18 '19 at 14:11
  • You should add the library "encoding" to your project. Click the icon "Add Library" at "Groups Tool" (the panel at right). Then search and select the "encoding" library and click the "Include" button. – Germán Arias Jun 19 '19 at 16:54