diff --git a/lib/nimble_csv.ex b/lib/nimble_csv.ex index d62c545..0a96347 100644 --- a/lib/nimble_csv.ex +++ b/lib/nimble_csv.ex @@ -114,6 +114,8 @@ defmodule NimbleCSV do @doc """ Eagerly dumps an enumerable into iodata (a list of binaries and bytes and other lists). + + Each value is converted to a string using `String.Chars.to_string/1`. """ @callback dump_to_iodata(rows :: Enumerable.t()) :: iodata() @@ -121,6 +123,8 @@ defmodule NimbleCSV do Lazily dumps from an enumerable to a stream. It returns a stream that emits each row as iodata. + + Each value is converted to a string using `String.Chars.to_string/1`. """ @callback dump_to_stream(rows :: Enumerable.t()) :: Enumerable.t() @@ -690,7 +694,7 @@ defmodule NimbleCSV do end defp maybe_escape(entry, check) do - entry = to_string(entry) + entry = String.Chars.to_string(entry) case :binary.match(entry, check) do {_, _} -> diff --git a/test/nimble_csv_test.exs b/test/nimble_csv_test.exs index 862bd62..650c4f3 100644 --- a/test/nimble_csv_test.exs +++ b/test/nimble_csv_test.exs @@ -315,11 +315,11 @@ defmodule NimbleCSVTest do """ assert IO.iodata_to_binary( - Enum.to_list(CSV.dump_to_stream([["name", "age"], ["john\ndoe", 27]])) + Enum.to_list(CSV.dump_to_stream([["name", "dob"], ["john\ndoe", ~D[1970-01-01]]])) ) == """ - name,age\r\n\ + name,dob\r\n\ "john - doe",27\r\n\ + doe",1970-01-01\r\n\ """ assert IO.iodata_to_binary(