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
839
839
"""
840
840
@ spec ends_with? ( t , t | [ t ] ) :: boolean
841
841
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
843
847
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 ] ) )
848
851
end
849
852
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
851
856
852
857
@ doc """
853
858
Returns true if `string` contains match, otherwise false.
You can’t perform that action at this time.
0 commit comments