Skip to content

Commit 5d0c5d0

Browse files
authored
Document values are encoded with String.Chars.to_string/1 (#91)
1 parent 3341343 commit 5d0c5d0

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/nimble_csv.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,17 @@ defmodule NimbleCSV do
114114

115115
@doc """
116116
Eagerly dumps an enumerable into iodata (a list of binaries and bytes and other lists).
117+
118+
Each value is converted to a string using `String.Chars.to_string/1`.
117119
"""
118120
@callback dump_to_iodata(rows :: Enumerable.t()) :: iodata()
119121

120122
@doc """
121123
Lazily dumps from an enumerable to a stream.
122124
123125
It returns a stream that emits each row as iodata.
126+
127+
Each value is converted to a string using `String.Chars.to_string/1`.
124128
"""
125129
@callback dump_to_stream(rows :: Enumerable.t()) :: Enumerable.t()
126130

@@ -690,7 +694,7 @@ defmodule NimbleCSV do
690694
end
691695

692696
defp maybe_escape(entry, check) do
693-
entry = to_string(entry)
697+
entry = String.Chars.to_string(entry)
694698

695699
case :binary.match(entry, check) do
696700
{_, _} ->

test/nimble_csv_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,11 @@ defmodule NimbleCSVTest do
315315
"""
316316

317317
assert IO.iodata_to_binary(
318-
Enum.to_list(CSV.dump_to_stream([["name", "age"], ["john\ndoe", 27]]))
318+
Enum.to_list(CSV.dump_to_stream([["name", "dob"], ["john\ndoe", ~D[1970-01-01]]]))
319319
) == """
320-
name,age\r\n\
320+
name,dob\r\n\
321321
"john
322-
doe",27\r\n\
322+
doe",1970-01-01\r\n\
323323
"""
324324

325325
assert IO.iodata_to_binary(

0 commit comments

Comments
 (0)