Skip to content

Commit 7740ade

Browse files
gamachemichalmuskala
authored andcommitted
superficial changes to formatter
1 parent 8dfc178 commit 7740ade

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

lib/formatter.ex

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ defmodule Jason.Formatter do
5050
"""
5151
@spec pretty_print(iodata, opts) :: binary
5252
def pretty_print(iodata, opts \\ []) do
53-
pretty_print_to_iolist(iodata, opts)
54-
|> :erlang.list_to_binary
53+
pretty_print_to_iodata(iodata, opts)
54+
|> IO.iodata_to_binary
5555
end
5656

5757

@@ -61,19 +61,19 @@ defmodule Jason.Formatter do
6161
6262
See `pretty_print/2` for details and options.
6363
"""
64-
@spec pretty_print_to_iolist(iodata, opts) :: iolist
65-
def pretty_print_to_iolist(iodata, opts \\ []) do
64+
@spec pretty_print_to_iodata(iodata, opts) :: iodata
65+
def pretty_print_to_iodata(iodata, opts \\ []) do
6666
depth = 0
6767
in_str = false
6868
in_bs = false
6969
empty = false
7070
first = true
7171
opts = normalize_opts(opts)
7272

73-
{iolist, _state} =
73+
{output, _state} =
7474
pp_iodata(iodata, [], depth, in_str, in_bs, empty, first, opts)
7575

76-
iolist
76+
output
7777
end
7878

7979

@@ -95,8 +95,8 @@ defmodule Jason.Formatter do
9595
"""
9696
@spec minimize(iodata, opts) :: binary
9797
def minimize(iodata, opts \\ []) do
98-
minimize_to_iolist(iodata, opts)
99-
|> :erlang.list_to_binary
98+
minimize_to_iodata(iodata, opts)
99+
|> IO.iodata_to_binary
100100
end
101101

102102

@@ -106,9 +106,9 @@ defmodule Jason.Formatter do
106106
107107
See `minimize/2` for details and options.
108108
"""
109-
@spec minimize_to_iolist(iodata, opts) :: iolist
110-
def minimize_to_iolist(iodata, opts) do
111-
pretty_print_to_iolist(
109+
@spec minimize_to_iodata(iodata, opts) :: iodata
110+
def minimize_to_iodata(iodata, opts) do
111+
pretty_print_to_iodata(
112112
iodata,
113113
indent: "",
114114
line_separator: "",
@@ -151,14 +151,14 @@ defmodule Jason.Formatter do
151151

152152
@spec pp_iodata(
153153
iodata, ## input -- input data
154-
iolist, ## output_acc -- output iolist (built in reverse order)
154+
iodata, ## output_acc -- output iolist (built in reverse order)
155155
non_neg_integer, ## depth -- current nesting depth
156156
boolean, ## in_str -- is the current byte in a string?
157157
boolean, ## in_bs -- does the current byte follow a backslash in a string?
158158
boolean, ## empty -- is the current object or array empty?
159159
boolean, ## first -- is this the first object or array in the input?
160160
opts
161-
) :: {iolist, pp_state}
161+
) :: {iodata, pp_state}
162162
defp pp_iodata(input, output_acc, depth, in_str, in_bs, empty, first, opts)
163163

164164
defp pp_iodata("", output_acc, depth, in_str, in_bs, empty, first, opts) do
@@ -173,7 +173,7 @@ defmodule Jason.Formatter do
173173
pp_byte(byte, rest, output_acc, depth, in_str, in_bs, empty, first, opts)
174174
end
175175

176-
defp pp_iodata(byte, output_acc, depth, in_str, in_bs, empty, first, opts) when is_number(byte) do
176+
defp pp_iodata(byte, output_acc, depth, in_str, in_bs, empty, first, opts) when is_integer(byte) do
177177
pp_byte(byte, [], output_acc, depth, in_str, in_bs, empty, first, opts)
178178
end
179179

@@ -191,14 +191,14 @@ defmodule Jason.Formatter do
191191
@spec pp_byte(
192192
byte, ## byte -- current byte
193193
iodata, ## rest -- rest of input data
194-
iolist, ## output -- output iolist (built in reverse order)
194+
iodata, ## output -- output iolist (built in reverse order)
195195
non_neg_integer, ## depth -- current nesting depth
196196
boolean, ## in_str -- is the current byte in a string?
197197
boolean, ## in_bs -- does the current byte follow a backslash in a string?
198198
boolean, ## empty -- is the current object or array empty?
199199
boolean, ## first -- is this the first object or array in the input?
200200
opts
201-
) :: {iolist, pp_state}
201+
) :: {iodata, pp_state}
202202
defp pp_byte(byte, rest, output, depth, in_str, in_bs, empty, first, opts)
203203

204204
## in string, following backslash
@@ -239,7 +239,7 @@ defmodule Jason.Formatter do
239239
first -> byte
240240
empty -> [opts[:line_separator], tab(opts, depth), byte]
241241
depth == 0 -> [opts[:record_separator], byte]
242-
:else -> byte
242+
true -> byte
243243
end
244244
first = false
245245
empty = true

0 commit comments

Comments
 (0)