@@ -138,14 +138,14 @@ defmodule Base do
138
138
defp from_mixed ( char ) ,
139
139
do: char
140
140
141
- defp maybe_pad ( << >> , _ , _ , _ ) ,
142
- do: << >>
143
141
defp maybe_pad ( subject , false , _ , _ ) ,
144
142
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
149
149
150
150
@ doc """
151
151
Encodes a binary string into a base 16 encoded string.
@@ -649,12 +649,12 @@ defmodule Base do
649
649
<< >> ->
650
650
<< >>
651
651
end
652
- main <> maybe_pad ( tail , pad_flag , 4 , ?= )
652
+ main <> maybe_pad ( tail , pad_flag , 4 , "=" )
653
653
end
654
654
655
655
defp do_decode64 ( << >> , _ ) , do: << >>
656
656
defp do_decode64 ( string , false ) do
657
- maybe_pad ( string , true , 4 , ?= ) |> do_decode64 ( true )
657
+ maybe_pad ( string , true , 4 , "=" ) |> do_decode64 ( true )
658
658
end
659
659
defp do_decode64 ( string , _pad_flag ) when rem ( byte_size ( string ) , 4 ) == 0 do
660
660
split = byte_size ( string ) - 4
@@ -689,12 +689,12 @@ defmodule Base do
689
689
<< >> ->
690
690
<< >>
691
691
end
692
- main <> maybe_pad ( tail , pad_flag , 4 , ?= )
692
+ main <> maybe_pad ( tail , pad_flag , 4 , "=" )
693
693
end
694
694
695
695
defp do_decode64url ( << >> , _ ) , do: << >>
696
696
defp do_decode64url ( string , false ) do
697
- maybe_pad ( string , true , 4 , ?= ) |> do_decode64url ( true )
697
+ maybe_pad ( string , true , 4 , "=" ) |> do_decode64url ( true )
698
698
end
699
699
defp do_decode64url ( string , _pad_flag ) when rem ( byte_size ( string ) , 4 ) == 0 do
700
700
split = byte_size ( string ) - 4
@@ -741,13 +741,13 @@ defmodule Base do
741
741
<< >> ->
742
742
<< >>
743
743
end
744
- main <> maybe_pad ( tail , pad_flag , 8 , ?= )
744
+ main <> maybe_pad ( tail , pad_flag , 8 , "=" )
745
745
end
746
746
end
747
747
748
748
defp do_decode32 ( _ , << >> , _ ) , do: << >>
749
749
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 )
751
751
752
752
for { case , fun } <- [ upper: :from_upper , lower: :from_lower , mixed: :from_mixed ] do
753
753
defp do_decode32 ( unquote ( case ) , string , _pad_flag ) when rem ( byte_size ( string ) , 8 ) == 0 do
@@ -809,13 +809,13 @@ defmodule Base do
809
809
<< >> ->
810
810
<< >>
811
811
end
812
- main <> maybe_pad ( tail , pad_flag , 8 , ?= )
812
+ main <> maybe_pad ( tail , pad_flag , 8 , "=" )
813
813
end
814
814
end
815
815
816
816
defp do_hex_decode32 ( _ , << >> , _ ) , do: << >>
817
817
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 )
819
819
820
820
for { case , fun } <- [ upper: :from_upper , lower: :from_lower , mixed: :from_mixed ] do
821
821
defp do_hex_decode32 ( unquote ( case ) , string , _pad_flag ) when rem ( byte_size ( string ) , 8 ) == 0 do
0 commit comments