elixir-cldr / cldr_numbers

CLDR Number localisation and formatting
Other
41 stars 23 forks source link

A minor bug with an empty string #23

Closed DaTrader closed 2 years ago

DaTrader commented 2 years ago

Hey Kip,

here's a minor bug for your consideration:

" " |> Cldr.Number.Parser.scan( number: :decimal) |> Cldr.Number.Parser.resolve_currencies() 
** (MatchError) no match of right hand side value: [" "]
    (ex_cldr_numbers 2.23.1) lib/cldr/number/parse.ex:805: Cldr.Number.Parser.starting_string/2
    (ex_cldr_numbers 2.23.1) lib/cldr/number/parse.ex:769: Cldr.Number.Parser.find_and_replace/3
    (ex_cldr_numbers 2.23.1) lib/cldr/number/parse.ex:561: Cldr.Number.Parser.resolve_currency/2
    (ex_cldr_numbers 2.23.1) lib/cldr/number/parse.ex:421: anonymous fn/3 in Cldr.Number.Parser.resolve/3
    (elixir 1.10.3) lib/enum.ex:1396: Enum."-map/2-lists^map/1-0-"/2
    (ex_cldr_numbers 2.23.1) lib/cldr/number/parse.ex:419: Cldr.Number.Parser.resolve/3

Besides this, can you please tell me whether the following compilation warnings have something to do with me or is it something to do with your code?

warning: Code.can_await_module_compilation?/0 is undefined or private
  lib/cldr/locale/cache.ex:35: Cldr.Locale.Cache.compiling?/0

warning: Date.to_gregorian_days/1 is undefined or private
  lib/cldr/calendar/behaviour.ex:6: Cldr.Calendar.Behaviour.__using__/1

warning: Cldr.Config.known_locale_names/1 is deprecated. Use Cldr.Locale.Loader.known_locale_names/1
  lib/cldr/backend.ex:792: MyApp.Cldr.Territory

warning: Cldr.Config.get_locale/2 is deprecated. Use Cldr.Locale.Loader.get_locale/2
  lib/cldr/backend.ex:795: MyApp.Cldr.Territory

These are my cldr related deps:

      { :ex_cldr, "~> 2.23"},
      { :ex_cldr_numbers, "~> 2.23.1"},
      { :ex_cldr_territories, "~> 2.2.2"},
      { :ex_cldr_dates_times, "~> 2.10.1"},

And this is my App.Cldr:

  @iso_currency_amount "¤¤ #,##0"

  use Cldr,
      default_locale: "en",
      locales: [ "en", "fr"],
      add_fallback_locales: false,
      gettext: MyApp.Gettext,
      data_dir: "./priv/cldr",
      otp_app: :my_app,
      precompile_number_formats: [ "¤#,##0.##", "0¤", "0¤¤¤", @iso_currency_amount],
      precompile_transliterations: [],
      providers: [ Cldr.Number, Cldr.Territory, Cldr.Calendar, Cldr.DateTime],
      generate_docs: true,
      force_locale_download: false

Speak soon,

Damir

kipcole9 commented 2 years ago

@DaTrader, thanks for the report as always. As for the parsing bug, no problem, I'll fix that.

The other issues:

warning: Code.can_await_module_compilation?/0 is undefined or private
  lib/cldr/locale/cache.ex:35: Cldr.Locale.Cache.compiling?/0

This is a function only available in Elixir 1.13 but conditional compilation should not result in it being called if you're on earlier releases. Will investigate.

warning: Date.to_gregorian_days/1 is undefined or private
  lib/cldr/calendar/behaviour.ex:6: Cldr.Calendar.Behaviour.__using__/1

This function is only available from Elixir 1.11. I thought it was from Elixir 1.10 so I need to revise the Elixir dependency. What version of Elixir are you on?

warning: Cldr.Config.known_locale_names/1 is deprecated. Use Cldr.Locale.Loader.known_locale_names/1
  lib/cldr/backend.ex:792: MyApp.Cldr.Territory

warning: Cldr.Config.get_locale/2 is deprecated. Use Cldr.Locale.Loader.get_locale/2
  lib/cldr/backend.ex:795: MyApp.Cldr.Territory

Please upgrade to ex_cldr_territories version ~> 2.3.

DaTrader commented 2 years ago

I'm still on 1.10.3. Will upgrade one of these days, but with all the workload I keep on postponing it.

DaTrader commented 2 years ago

Btw, just upgraded to ex_cldr_territories 2.3 and the warnings vanished.

DaTrader commented 2 years ago

I mean all of them, the first two as well.

DaTrader commented 2 years ago

Nah, that could be because it didn't have to recompile that particular library.

kipcole9 commented 2 years ago

I would expect that first two warnings to still exist if you recompile. But I'll work around those, might take me a day though.

kipcole9 commented 2 years ago

Published ex_cldr_numbers 2.23.2 fixing Cldr.Number.Parser.resolve_currencies/1 when there is only whitepspace in the string. The changelog entry is:

Bug Fixes

Will work on the other issues over the weekend.

kipcole9 commented 2 years ago

I have fixed the warning: Code.can_await_module_compilation?/0 is undefined or private error in ex_cldr version 2.24.2 with the following changeling entry:

Bug Fixes

Enhancements