diff --git a/README.md b/README.md index b17379f..d803c2f 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ The package can be installed by adding `sms_part_counter` to your list of depend ```elixir def deps do [ - {:sms_part_counter, "~> 0.1.3"} + {:sms_part_counter, "~> 0.1.7"} ] end ``` diff --git a/lib/sms_part_counter.ex b/lib/sms_part_counter.ex index 7411616..7127ff3 100644 --- a/lib/sms_part_counter.ex +++ b/lib/sms_part_counter.ex @@ -26,8 +26,11 @@ defmodule SmsPartCounter do """ @spec count(binary) :: integer() def count(str) when is_binary(str) do - String.codepoints(str) - |> Enum.count() + codepoints = String.to_charlist(str) + + codepoints + |> Enum.count(fn cp -> cp > 0xFFFF end) + |> then(&(&1 + Enum.count(codepoints))) end @doc """ diff --git a/mix.exs b/mix.exs index 5246b0d..ff40ac2 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule SmsPartCounter.MixProject do def project do [ app: :sms_part_counter, - version: "0.1.6", + version: "0.1.7", elixir: "~> 1.13", start_permanent: Mix.env() == :prod, deps: deps(), @@ -35,6 +35,7 @@ defmodule SmsPartCounter.MixProject do defp package() do [ + maintainers: ["m4hi2", "Rum&Code"], licenses: ["MIT"], links: %{"GitHub" => "https://github.com/m4hi2/sms-counter"} ] diff --git a/test/sms_part_counter_test.exs b/test/sms_part_counter_test.exs index bbd9ae5..3561804 100644 --- a/test/sms_part_counter_test.exs +++ b/test/sms_part_counter_test.exs @@ -21,6 +21,14 @@ defmodule SmsPartCounterTest do assert SmsPartCounter.count(" ") == 1 assert SmsPartCounter.count("আমি তুমি") == 8 end + + test "can count emoji characters" do + assert SmsPartCounter.count("👨‍👨‍👧‍👧") == 11 + assert SmsPartCounter.count("😃") == 2 + assert SmsPartCounter.count("😃🥃💻") == 6 + assert SmsPartCounter.count("👨‍👨‍👧‍👧😃") == 13 + assert SmsPartCounter.count("👨‍👨‍👧‍👧😃👨‍👨‍👧‍👧") == 24 + end end describe "GSM 7bit encoding SMS part counter" do