@@ -811,16 +811,24 @@ defmodule String do
811811 """
812812 @ spec starts_with? ( t , t | [ t ] ) :: boolean
813813
814- def starts_with? ( _ , "" ) do
814+ def starts_with? ( string , prefixes ) when is_list ( prefixes ) do
815+ Enum . any? ( prefixes , do_starts_with ( string , & 1 ) )
816+ end
817+
818+ def starts_with? ( string , prefix ) do
819+ do_starts_with ( string , prefix )
820+ end
821+
822+ defp do_starts_with ( _ , "" ) do
815823 true
816824 end
817825
818- def starts_with? ( string , prefix ) when is_binary ( prefix ) do
826+ defp do_starts_with ( string , prefix ) when is_binary ( prefix ) do
819827 match? ( { 0 , _ } , :binary . match ( string , prefix ) )
820828 end
821829
822- def starts_with? ( string , prefixes ) when is_list ( prefixes ) do
823- Enum . any? ( prefixes , starts_with? ( string , & 1 ) )
830+ defp do_starts_with ( _ , _ ) do
831+ raise ArgumentError
824832 end
825833
826834 @ doc """
@@ -839,19 +847,27 @@ defmodule String do
839847 """
840848 @ spec ends_with? ( t , t | [ t ] ) :: boolean
841849
842- def ends_with? ( _ , "" ) do
850+ def ends_with? ( string , suffixes ) when is_list ( suffixes ) do
851+ Enum . any? ( suffixes , do_ends_with ( string , & 1 ) )
852+ end
853+
854+ def ends_with? ( string , suffix ) do
855+ do_ends_with ( string , suffix )
856+ end
857+
858+ defp do_ends_with ( _ , "" ) do
843859 true
844860 end
845861
846- def ends_with? ( string , suffix ) when is_binary ( suffix ) do
862+ defp do_ends_with ( string , suffix ) when is_binary ( suffix ) do
847863 string_size = size ( string )
848864 suffix_size = size ( suffix )
849865 scope = { string_size - suffix_size , suffix_size }
850866 ( suffix_size <= string_size ) and ( :nomatch != :binary . match ( string , suffix , [ scope: scope ] ) )
851867 end
852868
853- def ends_with? ( string , suffixes ) when is_list ( suffixes ) do
854- Enum . any? ( suffixes , ends_with? ( string , & 1 ) )
869+ defp do_ends_with ( _ , _ ) do
870+ raise ArgumentError
855871 end
856872
857873 @ doc """
0 commit comments