Skip to content

Commit 097cd02

Browse files
committed
Deprecate skipchars for skipuntil
Closes JuliaLang#36132 The name skipchars does not clearly communicate the functionality available. Tests for skipchars were left in place to ensure the @deprecate macro correctly converted those calls to using skipuntil. Although CI only runs tests with --depwarn=error, I have confirmed these tests pass successfully with --depwarn=yes/no locally.
1 parent 2897fe8 commit 097cd02

File tree

6 files changed

+62
-86
lines changed

6 files changed

+62
-86
lines changed

base/deprecated.jl

+6
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,9 @@ macro get!(h, key0, default)
208208
end
209209

210210
# END 1.5 deprecations
211+
212+
# BEGIN 1.6 deprecations
213+
214+
@deprecate skipchars(pred, io::IO; linecomment=nothing) skipuntil(!pred, io::IO; linecomment=linecomment)
215+
216+
# END 1.6 deprecations

base/exports.jl

-1
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,6 @@ export
820820
seekend,
821821
seekstart,
822822
skip,
823-
skipchars,
824823
skipuntil,
825824
take!,
826825
truncate,

base/io.jl

-32
Original file line numberDiff line numberDiff line change
@@ -1069,38 +1069,6 @@ Commit all currently buffered writes to the given stream.
10691069
"""
10701070
flush(io::IO) = nothing
10711071

1072-
"""
1073-
skipchars(predicate, io::IO; linecomment=nothing)
1074-
1075-
Advance the stream `io` such that the next-read character will be the first remaining for
1076-
which `predicate` returns `false`. If the keyword argument `linecomment` is specified, all
1077-
characters from that character until the start of the next line are ignored.
1078-
1079-
# Examples
1080-
```jldoctest
1081-
julia> buf = IOBuffer(" text")
1082-
IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=8, maxsize=Inf, ptr=1, mark=-1)
1083-
1084-
julia> skipchars(isspace, buf)
1085-
IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=8, maxsize=Inf, ptr=5, mark=-1)
1086-
1087-
julia> String(readavailable(buf))
1088-
"text"
1089-
```
1090-
"""
1091-
function skipchars(predicate, io::IO; linecomment=nothing)
1092-
while !eof(io)
1093-
c = read(io, Char)
1094-
if c === linecomment
1095-
readline(io)
1096-
elseif !predicate(c)
1097-
skip(io, -ncodeunits(c))
1098-
break
1099-
end
1100-
end
1101-
return io
1102-
end
1103-
11041072
"""
11051073
skipuntil(predicate, io::IO; linecomment=nothing)
11061074

doc/src/base/io-network.md

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ Base.redirect_stdin
4343
Base.redirect_stdin(::Function, ::Any)
4444
Base.readchomp
4545
Base.truncate
46-
Base.skipchars
4746
Base.skipuntil
4847
Base.countlines
4948
Base.PipeBuffer

test/iobuffer.jl

+19-17
Original file line numberDiff line numberDiff line change
@@ -275,28 +275,30 @@ let io = IOBuffer()
275275
@test Base.buffer_writes(io) === io
276276
end
277277

278-
@testset "skipchars" begin
279-
io = IOBuffer("")
280-
@test eof(skipchars(isspace, io))
278+
@static if Base.JLOptions().depwarn != 2
279+
@testset "skipchars" begin
280+
io = IOBuffer("")
281+
@test eof(@test_deprecated(skipchars(isspace, io)))
281282

282-
io = IOBuffer(" ")
283-
@test eof(skipchars(isspace, io))
283+
io = IOBuffer(" ")
284+
@test eof(@test_deprecated(skipchars(isspace, io)))
284285

285-
io = IOBuffer("# \n ")
286-
@test eof(skipchars(isspace, io, linecomment='#'))
286+
io = IOBuffer("# \n ")
287+
@test eof(@test_deprecated(skipchars(isspace, io, linecomment='#')))
287288

288-
io = IOBuffer(" text")
289-
skipchars(isspace, io)
290-
@test String(readavailable(io)) == "text"
289+
io = IOBuffer(" text")
290+
@test_deprecated skipchars(isspace, io)
291+
@test String(readavailable(io)) == "text"
291292

292-
io = IOBuffer(" # comment \n text")
293-
skipchars(isspace, io, linecomment='#')
294-
@test String(readavailable(io)) == "text"
293+
io = IOBuffer(" # comment \n text")
294+
@test_deprecated skipchars(isspace, io, linecomment='#')
295+
@test String(readavailable(io)) == "text"
295296

296-
for char in ['@','߷','','𐋺']
297-
io = IOBuffer("alphabeticalstuff$char")
298-
@test !eof(skipchars(isletter, io))
299-
@test read(io, Char) == char
297+
for char in ['@','߷','','𐋺']
298+
io = IOBuffer("alphabeticalstuff$char")
299+
@test !eof(@test_deprecated(skipchars(isletter, io)))
300+
@test read(io, Char) == char
301+
end
300302
end
301303
end
302304

test/iostream.jl

+37-35
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
@testset "skipchars for IOStream" begin
4-
mktemp() do path, file
5-
function append_to_file(str)
6-
mark(file)
7-
print(file, str)
8-
flush(file)
9-
reset(file)
10-
end
11-
# test it doesn't error on eof
12-
@test eof(skipchars(isspace, file))
13-
14-
# test it correctly skips
15-
append_to_file(" ")
16-
@test eof(skipchars(isspace, file))
17-
18-
# test it correctly detects comment lines
19-
append_to_file("# \n ")
20-
@test eof(skipchars(isspace, file, linecomment='#'))
21-
22-
# test it stops at the appropriate time
23-
append_to_file(" not a space")
24-
@test !eof(skipchars(isspace, file))
25-
@test read(file, Char) == 'n'
26-
27-
# test it correctly ignores the contents of comment lines
28-
append_to_file(" #not a space \n not a space")
29-
@test !eof(skipchars(isspace, file, linecomment='#'))
30-
@test read(file, Char) == 'n'
31-
32-
# test it correctly handles unicode
33-
for (byte, char) in zip(1:4, ('@','߷','','𐋺'))
34-
append_to_file("abcdef$char")
35-
@test ncodeunits(char) == byte
36-
@test !eof(skipchars(isletter, file))
37-
@test read(file, Char) == char
3+
@static if Base.JLOptions().depwarn != 2
4+
@testset "skipchars for IOStream" begin
5+
mktemp() do path, file
6+
function append_to_file(str)
7+
mark(file)
8+
print(file, str)
9+
flush(file)
10+
reset(file)
11+
end
12+
# test it doesn't error on eof
13+
@test eof(@test_deprecated(skipchars(isspace, file)))
14+
15+
# test it correctly skips
16+
append_to_file(" ")
17+
@test eof(@test_deprecated(skipchars(isspace, file)))
18+
19+
# test it correctly detects comment lines
20+
append_to_file("# \n ")
21+
@test eof(@test_deprecated(skipchars(isspace, file, linecomment='#')))
22+
23+
# test it stops at the appropriate time
24+
append_to_file(" not a space")
25+
@test !eof(@test_deprecated(skipchars(isspace, file)))
26+
@test read(file, Char) == 'n'
27+
28+
# test it correctly ignores the contents of comment lines
29+
append_to_file(" #not a space \n not a space")
30+
@test !eof(@test_deprecated(skipchars(isspace, file, linecomment='#')))
31+
@test read(file, Char) == 'n'
32+
33+
# test it correctly handles unicode
34+
for (byte, char) in zip(1:4, ('@','߷','','𐋺'))
35+
append_to_file("abcdef$char")
36+
@test ncodeunits(char) == byte
37+
@test !eof(@test_deprecated(skipchars(isletter, file)))
38+
@test read(file, Char) == char
39+
end
3840
end
3941
end
4042
end

0 commit comments

Comments
 (0)