Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Commit 51eea57

Browse files
committed
rename chomp keyword argument to keep with inverted meaning
1 parent bea2fb7 commit 51eea57

File tree

14 files changed

+93
-67
lines changed

14 files changed

+93
-67
lines changed

base/client.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ parse_input_line(s::AbstractString) = parse_input_line(String(s))
236236
function parse_input_line(io::IO)
237237
s = ""
238238
while !eof(io)
239-
s *= readline(io, chomp=false)
239+
s *= readline(io, keep=true)
240240
e = parse_input_line(s)
241241
if !(isa(e,Expr) && e.head === :incomplete)
242242
return e

base/deprecated.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ end
459459

460460
@deprecate read(cmd::AbstractCmd, stdin::Redirectable) read(pipeline(stdin, cmd))
461461
@deprecate readstring(cmd::AbstractCmd, stdin::Redirectable) readstring(pipeline(stdin, cmd))
462-
@deprecate eachline(cmd::AbstractCmd, stdin; chomp::Bool=true) eachline(pipeline(stdin, cmd), chomp=chomp)
462+
@deprecate eachline(cmd::AbstractCmd, stdin; kw...) eachline(pipeline(stdin, cmd), kw...)
463463

464464
@deprecate showall(x) show(x)
465465
@deprecate showall(io, x) show(IOContext(io, :limit => false), x)

base/io.jl

+45-27
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,14 @@ julia> rm("my_file.txt")
322322
readuntil(filename::AbstractString, args...) = open(io->readuntil(io, args...), filename)
323323

324324
"""
325-
readline(io::IO=STDIN; chomp::Bool=true)
326-
readline(filename::AbstractString; chomp::Bool=true)
325+
readline(io::IO=STDIN; keep::Bool=false)
326+
readline(filename::AbstractString; keep::Bool=false)
327327
328328
Read a single line of text from the given I/O stream or file (defaults to `STDIN`).
329329
When reading from a file, the text is assumed to be encoded in UTF-8. Lines in the
330-
input end with `'\\n'` or `"\\r\\n"` or the end of an input stream. When `chomp` is
331-
true (as it is by default), these trailing newline characters are removed from the
332-
line before it is returned. When `chomp` is false, they are returned as part of the
330+
input end with `'\\n'` or `"\\r\\n"` or the end of an input stream. When `keep` is
331+
false (as it is by default), these trailing newline characters are removed from the
332+
line before it is returned. When `keep` is true, they are returned as part of the
333333
line.
334334
335335
# Examples
@@ -342,22 +342,30 @@ julia> open("my_file.txt", "w") do io
342342
julia> readline("my_file.txt")
343343
"JuliaLang is a GitHub organization."
344344
345-
julia> readline("my_file.txt", chomp=false)
345+
julia> readline("my_file.txt", keep=true)
346346
"JuliaLang is a GitHub organization.\\n"
347347
348348
julia> rm("my_file.txt")
349349
```
350350
"""
351-
function readline(filename::AbstractString; chomp::Bool=true)
351+
function readline(filename::AbstractString; chomp=nothing, keep::Bool=false)
352+
if chomp !== nothing
353+
keep = !chomp
354+
depwarn("The `chomp=$chomp` argument to `readline` is deprecated in favor of `keep=$keep`.", :readline)
355+
end
352356
open(filename) do f
353-
readline(f, chomp=chomp)
357+
readline(f, keep=keep)
354358
end
355359
end
356360

357-
function readline(s::IO=STDIN; chomp::Bool=true)
361+
function readline(s::IO=STDIN; chomp=nothing, keep::Bool=false)
362+
if chomp !== nothing
363+
keep = !chomp
364+
depwarn("The `chomp=$chomp` argument to `readline` is deprecated in favor of `keep=$keep`.", :readline)
365+
end
358366
line = readuntil(s, 0x0a)
359367
i = length(line)
360-
if !chomp || i == 0 || line[i] != 0x0a
368+
if keep || i == 0 || line[i] != 0x0a
361369
return String(line)
362370
elseif i < 2 || line[i-1] != 0x0d
363371
return String(resize!(line,i-1))
@@ -367,8 +375,8 @@ function readline(s::IO=STDIN; chomp::Bool=true)
367375
end
368376

369377
"""
370-
readlines(io::IO=STDIN; chomp::Bool=true)
371-
readlines(filename::AbstractString; chomp::Bool=true)
378+
readlines(io::IO=STDIN; keep::Bool=false)
379+
readlines(filename::AbstractString; keep::Bool=false)
372380
373381
Read all lines of an I/O stream or a file as a vector of strings. Behavior is
374382
equivalent to saving the result of reading [`readline`](@ref) repeatedly with the same
@@ -386,20 +394,20 @@ julia> readlines("my_file.txt")
386394
"JuliaLang is a GitHub organization."
387395
"It has many members."
388396
389-
julia> readlines("my_file.txt", chomp=false)
397+
julia> readlines("my_file.txt", keep=true)
390398
2-element Array{String,1}:
391399
"JuliaLang is a GitHub organization.\\n"
392400
"It has many members.\\n"
393401
394402
julia> rm("my_file.txt")
395403
```
396404
"""
397-
function readlines(filename::AbstractString; chomp::Bool=true)
405+
function readlines(filename::AbstractString; kw...)
398406
open(filename) do f
399-
readlines(f, chomp=chomp)
407+
readlines(f; kw...)
400408
end
401409
end
402-
readlines(s=STDIN; chomp::Bool=true) = collect(eachline(s, chomp=chomp))
410+
readlines(s=STDIN; kw...) = collect(eachline(s; kw...))
403411

404412
## byte-order mark, ntoh & hton ##
405413

@@ -797,20 +805,20 @@ read(s::IO, T::Type) = error("The IO stream does not support reading objects of
797805
mutable struct EachLine
798806
stream::IO
799807
ondone::Function
800-
chomp::Bool
808+
keep::Bool
801809

802-
EachLine(stream::IO=STDIN; ondone::Function=()->nothing, chomp::Bool=true) =
803-
new(stream, ondone, chomp)
810+
EachLine(stream::IO=STDIN; ondone::Function=()->nothing, keep::Bool=false) =
811+
new(stream, ondone, keep)
804812
end
805813

806814
"""
807-
eachline(io::IO=STDIN; chomp::Bool=true)
808-
eachline(filename::AbstractString; chomp::Bool=true)
815+
eachline(io::IO=STDIN; keep::Bool=false)
816+
eachline(filename::AbstractString; keep::Bool=false)
809817
810818
Create an iterable `EachLine` object that will yield each line from an I/O stream
811819
or a file. Iteration calls [`readline`](@ref) on the stream argument repeatedly with
812-
`chomp` passed through, determining whether trailing end-of-line characters are
813-
removed. When called with a file name, the file is opened once at the beginning of
820+
`keep` passed through, determining whether trailing end-of-line characters are
821+
retained. When called with a file name, the file is opened once at the beginning of
814822
iteration and closed at the end. If iteration is interrupted, the file will be
815823
closed when the `EachLine` object is garbage collected.
816824
@@ -828,11 +836,21 @@ JuliaLang is a GitHub organization. It has many members.
828836
julia> rm("my_file.txt");
829837
```
830838
"""
831-
eachline(stream::IO=STDIN; chomp::Bool=true) = EachLine(stream, chomp=chomp)::EachLine
839+
function eachline(stream::IO=STDIN; chomp=nothing, keep::Bool=false)
840+
if chomp !== nothing
841+
keep = !chomp
842+
depwarn("The `chomp=$chomp` argument to `eachline` is deprecated in favor of `keep=$keep`.", :eachline)
843+
end
844+
EachLine(stream, keep=keep)::EachLine
845+
end
832846

833-
function eachline(filename::AbstractString; chomp::Bool=true)
847+
function eachline(filename::AbstractString; chomp=nothing, keep::Bool=false)
848+
if chomp !== nothing
849+
keep = !chomp
850+
depwarn("The `chomp=$chomp` argument to `eachline` is deprecated in favor of `keep=$keep`.", :eachline)
851+
end
834852
s = open(filename)
835-
EachLine(s, ondone=()->close(s), chomp=chomp)::EachLine
853+
EachLine(s, ondone=()->close(s), keep=keep)::EachLine
836854
end
837855

838856
start(itr::EachLine) = nothing
@@ -841,7 +859,7 @@ function done(itr::EachLine, ::Nothing)
841859
itr.ondone()
842860
true
843861
end
844-
next(itr::EachLine, ::Nothing) = (readline(itr.stream, chomp=itr.chomp), nothing)
862+
next(itr::EachLine, ::Nothing) = (readline(itr.stream, keep=itr.keep), nothing)
845863

846864
eltype(::Type{EachLine}) = String
847865

base/iostream.jl

+6-2
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,12 @@ function readuntil_string(s::IOStream, delim::UInt8)
366366
ccall(:jl_readuntil, Ref{String}, (Ptr{Cvoid}, UInt8, UInt8, UInt8), s.ios, delim, 1, false)
367367
end
368368

369-
function readline(s::IOStream; chomp::Bool=true)
370-
ccall(:jl_readuntil, Ref{String}, (Ptr{Cvoid}, UInt8, UInt8, UInt8), s.ios, '\n', 1, chomp)
369+
function readline(s::IOStream; chomp=nothing, keep::Bool=false)
370+
if chomp !== nothing
371+
keep = !chomp
372+
depwarn("The `chomp=$chomp` argument to `readline` is deprecated in favor of `keep=$keep`.", :readline)
373+
end
374+
ccall(:jl_readuntil, Ref{String}, (Ptr{Cvoid}, UInt8, UInt8, UInt8), s.ios, '\n', 1, !keep)
371375
end
372376

373377
function readbytes_all!(s::IOStream, b::Array{UInt8}, nb)

base/markdown/Common/block.jl

+7-7
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function indentcode(stream::IO, block::MD)
108108
buffer = IOBuffer()
109109
while !eof(stream)
110110
if startswith(stream, " ") || startswith(stream, "\t")
111-
write(buffer, readline(stream, chomp=false))
111+
write(buffer, readline(stream, keep=true))
112112
elseif blankline(stream)
113113
write(buffer, '\n')
114114
else
@@ -139,10 +139,10 @@ function footnote(stream::IO, block::MD)
139139
else
140140
ref = match(regex, str).captures[1]
141141
buffer = IOBuffer()
142-
write(buffer, readline(stream, chomp=false))
142+
write(buffer, readline(stream, keep=true))
143143
while !eof(stream)
144144
if startswith(stream, " ")
145-
write(buffer, readline(stream, chomp=false))
145+
write(buffer, readline(stream, keep=true))
146146
elseif blankline(stream)
147147
write(buffer, '\n')
148148
else
@@ -174,7 +174,7 @@ function blockquote(stream::IO, block::MD)
174174
empty = true
175175
while eatindent(stream) && startswith(stream, '>')
176176
startswith(stream, " ")
177-
write(buffer, readline(stream, chomp=false))
177+
write(buffer, readline(stream, keep=true))
178178
empty = false
179179
end
180180
empty && return false
@@ -229,7 +229,7 @@ function admonition(stream::IO, block::MD)
229229
buffer = IOBuffer()
230230
while !eof(stream)
231231
if startswith(stream, " ")
232-
write(buffer, readline(stream, chomp=false))
232+
write(buffer, readline(stream, keep=true))
233233
elseif blankline(stream)
234234
write(buffer, '\n')
235235
else
@@ -305,7 +305,7 @@ function list(stream::IO, block::MD)
305305
newline = false
306306
if startswith(stream, " "^indent)
307307
# Indented text that is part of the current list item.
308-
print(buffer, readline(stream, chomp=false))
308+
print(buffer, readline(stream, keep=true))
309309
else
310310
matched = startswith(stream, regex)
311311
if isempty(matched)
@@ -316,7 +316,7 @@ function list(stream::IO, block::MD)
316316
# Start of a new list item.
317317
count += 1
318318
count > 1 && pushitem!(list, buffer)
319-
print(buffer, readline(stream, chomp=false))
319+
print(buffer, readline(stream, keep=true))
320320
end
321321
end
322322
end

base/markdown/GitHub/GitHub.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function fencedcode(stream::IO, block::MD)
3030
seek(stream, line_start)
3131
end
3232
end
33-
write(buffer, readline(stream, chomp=false))
33+
write(buffer, readline(stream, keep=true))
3434
end
3535
return false
3636
end

base/process.jl

+6-2
Original file line numberDiff line numberDiff line change
@@ -561,13 +561,17 @@ Run a command object asynchronously, returning the resulting `Process` object.
561561
spawn(cmds::AbstractCmd, args...; chain::Union{ProcessChain, Nothing}=nothing) =
562562
spawn(cmds, spawn_opts_swallow(args...)...; chain=chain)
563563

564-
function eachline(cmd::AbstractCmd; chomp::Bool=true)
564+
function eachline(cmd::AbstractCmd; chomp=nothing, keep::Bool=false)
565+
if chomp !== nothing
566+
keep = !chomp
567+
depwarn("The `chomp=$chomp` argument to `eachline` is deprecated in favor of `keep=$keep`.", :eachline)
568+
end
565569
stdout = Pipe()
566570
processes = spawn(cmd, (DevNull,stdout,STDERR))
567571
close(stdout.in)
568572
out = stdout.out
569573
# implicitly close after reading lines, since we opened
570-
return EachLine(out, chomp=chomp,
574+
return EachLine(out, keep=keep,
571575
ondone=()->(close(out); success(processes) || pipeline_error(processes)))::EachLine
572576
end
573577

base/util.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ function prompt(message::AbstractString; default::AbstractString="", password::B
458458
uinput = getpass(msg)
459459
else
460460
print(msg)
461-
uinput = readline(chomp=false)
461+
uinput = readline(keep=true)
462462
isempty(uinput) && return nothing # Encountered an EOF
463463
uinput = chomp(uinput)
464464
end

stdlib/REPL/src/LineEdit.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ function refresh_multi_line(termbuf::TerminalBuffer, terminal::UnixTerminal, buf
381381
seek(buf, 0)
382382
moreinput = true # add a blank line if there is a trailing newline on the last line
383383
while moreinput
384-
l = readline(buf, chomp=false)
384+
l = readline(buf, keep=true)
385385
moreinput = endswith(l, "\n")
386386
# We need to deal with on-screen characters, so use textwidth to compute occupied columns
387387
llength = textwidth(l)

stdlib/REPL/src/REPL.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ function run_frontend(repl::BasicREPL, backend::REPLBackendRef)
207207
interrupted = false
208208
while true
209209
try
210-
line *= readline(repl.terminal, chomp=false)
210+
line *= readline(repl.terminal, keep=true)
211211
catch e
212212
if isa(e,InterruptException)
213213
try # raise the debugger if present
@@ -378,7 +378,7 @@ An editor may have converted tabs to spaces at line """
378378

379379
function hist_getline(file)
380380
while !eof(file)
381-
line = readline(file, chomp=false)
381+
line = readline(file, keep=true)
382382
isempty(line) && return line
383383
line[1] in "\r\n" || return line
384384
end
@@ -1112,7 +1112,7 @@ function run_frontend(repl::StreamREPL, backend::REPLBackendRef)
11121112
if have_color
11131113
print(repl.stream, input_color(repl))
11141114
end
1115-
line = readline(repl.stream, chomp=false)
1115+
line = readline(repl.stream, keep=true)
11161116
if !isempty(line)
11171117
ast = Base.parse_input_line(line)
11181118
if have_color

test/file.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ end
252252
emptyfile = joinpath(dir, "empty")
253253
touch(emptyfile)
254254
emptyf = open(emptyfile)
255-
@test isempty(readlines(emptyf, chomp=false))
255+
@test isempty(readlines(emptyf, keep=true))
256256
close(emptyf)
257257
rm(emptyfile)
258258

test/iobuffer.jl

+12-12
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,29 @@ Base.compact(io)
8181
@test write(io,"pancakes\nwaffles\nblueberries\n") > 0
8282
@test readlines(io) == String["pancakes", "waffles", "blueberries"]
8383
write(io,"\n\r\n\n\r \n") > 0
84-
@test readlines(io, chomp=false) == String["\n", "\r\n", "\n", "\r \n"]
84+
@test readlines(io, keep=true) == String["\n", "\r\n", "\n", "\r \n"]
8585
write(io,"\n\r\n\n\r \n") > 0
86-
@test readlines(io, chomp=true) == String["", "", "", "\r "]
86+
@test readlines(io, keep=false) == String["", "", "", "\r "]
8787
@test write(io,"α\nβ\nγ\nδ") > 0
88-
@test readlines(io, chomp=false) == String["α\n","β\n","γ\n","δ"]
88+
@test readlines(io, keep=true) == String["α\n","β\n","γ\n","δ"]
8989
@test write(io,"α\nβ\nγ\nδ") > 0
90-
@test readlines(io, chomp=true) == String["α", "β", "γ", "δ"]
91-
@test readlines(IOBuffer(""), chomp=false) == []
92-
@test readlines(IOBuffer(""), chomp=true) == []
93-
@test readlines(IOBuffer("first\nsecond"), chomp=false) == String["first\n", "second"]
94-
@test readlines(IOBuffer("first\nsecond"), chomp=true) == String["first", "second"]
90+
@test readlines(io, keep=false) == String["α", "β", "γ", "δ"]
91+
@test readlines(IOBuffer(""), keep=true) == []
92+
@test readlines(IOBuffer(""), keep=false) == []
93+
@test readlines(IOBuffer("first\nsecond"), keep=true) == String["first\n", "second"]
94+
@test readlines(IOBuffer("first\nsecond"), keep=false) == String["first", "second"]
9595

9696
let fname = tempname()
97-
for dochomp in [true, false],
97+
for dokeep in [true, false],
9898
endline in ["\n", "\r\n"],
9999
i in -5:5
100100

101101
ref = ("1"^(2^17 - i)) * endline
102102
open(fname, "w") do io
103103
write(io, ref)
104104
end
105-
x = readlines(fname, chomp = dochomp)
106-
if dochomp
105+
x = readlines(fname, keep = dokeep)
106+
if !dokeep
107107
ref = chomp(ref)
108108
end
109109
@test ref == x[1]
@@ -170,7 +170,7 @@ let io = IOBuffer("abcdef"),
170170
@test eof(io)
171171
end
172172

173-
@test isempty(readlines(IOBuffer(), chomp=false))
173+
@test isempty(readlines(IOBuffer(), keep=true))
174174

175175
# issue #8193
176176
let io=IOBuffer("asdf")

test/iterators.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ end
3232
let b = IOBuffer("foo\n")
3333
@test collect(EachLine(b)) == ["foo"]
3434
seek(b, 0)
35-
@test collect(EachLine(b, chomp=false)) == ["foo\n"]
35+
@test collect(EachLine(b, keep=true)) == ["foo\n"]
3636
seek(b, 0)
3737
@test collect(EachLine(b, ondone=()->0)) == ["foo"]
3838
seek(b, 0)
39-
@test collect(EachLine(b, chomp=false, ondone=()->0)) == ["foo\n"]
39+
@test collect(EachLine(b, keep=true, ondone=()->0)) == ["foo\n"]
4040
end
4141

4242
# enumerate (issue #6284)

0 commit comments

Comments
 (0)