@@ -138,14 +138,14 @@ defmodule Base do
138138 defp from_mixed ( char ) ,
139139 do: char
140140
141- defp maybe_pad ( << >> , _ , _ , _ ) ,
142- do: << >>
143141 defp maybe_pad ( subject , false , _ , _ ) ,
144142 do: subject
145- defp maybe_pad ( subject , _ , group_size , _ ) when rem ( byte_size ( subject ) , group_size ) == 0 ,
146- do: subject
147- defp maybe_pad ( subject , _ , group_size , pad ) ,
148- do: String . ljust ( subject , byte_size ( subject ) + ( group_size - rem ( byte_size ( subject ) , group_size ) ) , pad )
143+ defp maybe_pad ( subject , _ , group_size , pad ) do
144+ case rem ( byte_size ( subject ) , group_size ) do
145+ 0 -> subject
146+ x -> subject <> String . duplicate ( pad , group_size - x )
147+ end
148+ end
149149
150150 @ doc """
151151 Encodes a binary string into a base 16 encoded string.
@@ -649,12 +649,12 @@ defmodule Base do
649649 << >> ->
650650 << >>
651651 end
652- main <> maybe_pad ( tail , pad_flag , 4 , ?= )
652+ main <> maybe_pad ( tail , pad_flag , 4 , "=" )
653653 end
654654
655655 defp do_decode64 ( << >> , _ ) , do: << >>
656656 defp do_decode64 ( string , false ) do
657- maybe_pad ( string , true , 4 , ?= ) |> do_decode64 ( true )
657+ maybe_pad ( string , true , 4 , "=" ) |> do_decode64 ( true )
658658 end
659659 defp do_decode64 ( string , _pad_flag ) when rem ( byte_size ( string ) , 4 ) == 0 do
660660 split = byte_size ( string ) - 4
@@ -689,12 +689,12 @@ defmodule Base do
689689 << >> ->
690690 << >>
691691 end
692- main <> maybe_pad ( tail , pad_flag , 4 , ?= )
692+ main <> maybe_pad ( tail , pad_flag , 4 , "=" )
693693 end
694694
695695 defp do_decode64url ( << >> , _ ) , do: << >>
696696 defp do_decode64url ( string , false ) do
697- maybe_pad ( string , true , 4 , ?= ) |> do_decode64url ( true )
697+ maybe_pad ( string , true , 4 , "=" ) |> do_decode64url ( true )
698698 end
699699 defp do_decode64url ( string , _pad_flag ) when rem ( byte_size ( string ) , 4 ) == 0 do
700700 split = byte_size ( string ) - 4
@@ -741,13 +741,13 @@ defmodule Base do
741741 << >> ->
742742 << >>
743743 end
744- main <> maybe_pad ( tail , pad_flag , 8 , ?= )
744+ main <> maybe_pad ( tail , pad_flag , 8 , "=" )
745745 end
746746 end
747747
748748 defp do_decode32 ( _ , << >> , _ ) , do: << >>
749749 defp do_decode32 ( case , string , false ) ,
750- do: do_decode32 ( case , maybe_pad ( string , true , 8 , ?= ) , true )
750+ do: do_decode32 ( case , maybe_pad ( string , true , 8 , "=" ) , true )
751751
752752 for { case , fun } <- [ upper: :from_upper , lower: :from_lower , mixed: :from_mixed ] do
753753 defp do_decode32 ( unquote ( case ) , string , _pad_flag ) when rem ( byte_size ( string ) , 8 ) == 0 do
@@ -809,13 +809,13 @@ defmodule Base do
809809 << >> ->
810810 << >>
811811 end
812- main <> maybe_pad ( tail , pad_flag , 8 , ?= )
812+ main <> maybe_pad ( tail , pad_flag , 8 , "=" )
813813 end
814814 end
815815
816816 defp do_hex_decode32 ( _ , << >> , _ ) , do: << >>
817817 defp do_hex_decode32 ( case , string , false ) ,
818- do: do_hex_decode32 ( case , maybe_pad ( string , true , 8 , ?= ) , true )
818+ do: do_hex_decode32 ( case , maybe_pad ( string , true , 8 , "=" ) , true )
819819
820820 for { case , fun } <- [ upper: :from_upper , lower: :from_lower , mixed: :from_mixed ] do
821821 defp do_hex_decode32 ( unquote ( case ) , string , _pad_flag ) when rem ( byte_size ( string ) , 8 ) == 0 do
0 commit comments