File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed
Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -839,15 +839,20 @@ defmodule String do
839839 """
840840 @ spec ends_with? ( t , t | [ t ] ) :: boolean
841841
842- def ends_with? ( string , suffixes ) when is_list ( suffixes ) do
842+ def ends_with? ( _ , "" ) do
843+ true
844+ end
845+
846+ def ends_with? ( string , suffix ) when is_binary ( suffix ) do
843847 string_size = size ( string )
844- Enum . any? suffixes , fn suffix ->
845- suffix_size = size ( suffix )
846- ( suffix_size <= string_size ) and suffix == :binary . part ( string , { string_size , - suffix_size } )
847- end
848+ suffix_size = size ( suffix )
849+ scope = { string_size - suffix_size , suffix_size }
850+ ( suffix_size <= string_size ) and ( :nomatch != :binary . match ( string , suffix , [ scope: scope ] ) )
848851 end
849852
850- def ends_with? ( string , suffix ) , do: ends_with? ( string , [ suffix ] )
853+ def ends_with? ( string , suffixes ) when is_list ( suffixes ) do
854+ Enum . any? ( suffixes , ends_with? ( string , & 1 ) )
855+ end
851856
852857 @ doc """
853858 Returns true if `string` contains match, otherwise false.
You can’t perform that action at this time.
0 commit comments