Skip to content

Commit

Permalink
change skipchars(io, predicate) to skipchars(predicate, io)
Browse files Browse the repository at this point in the history
This is to be consistent with our style guide.
  • Loading branch information
rfourquet committed Jan 21, 2018
1 parent 324dc49 commit f03fbf9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,9 @@ Deprecated or removed

* `nb_available` is now `bytesavailable` ([#25634]).

* `skipchars(io::IO, predicate; linecomment=nothing)` is deprecated in favor of
`skipchars(predicate, io::IO; linecomment=nothing)` ([#25667]).

* `Bidiagonal` constructors now use a `Symbol` (`:U` or `:L`) for the upper/lower
argument, instead of a `Bool` or a `Char` ([#22703]).

Expand Down
2 changes: 2 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,8 @@ end

@deprecate nb_available bytesavailable

@deprecate skipchars(io::IO, predicate; linecomment=nothing) skipchars(predicate, io, linecomment=linecomment)

# issue #9053
if Sys.iswindows()
function Filesystem.tempname(uunique::UInt32)
Expand Down
8 changes: 4 additions & 4 deletions base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ Commit all currently buffered writes to the given stream.
flush(io::IO) = nothing

"""
skipchars(io::IO, predicate; linecomment=nothing)
skipchars(predicate, io::IO; linecomment=nothing)
Advance the stream `io` such that the next-read character will be the first remaining for
which `predicate` returns `false`. If the keyword argument `linecomment` is specified, all
Expand All @@ -923,19 +923,19 @@ characters from that character until the start of the next line are ignored.
julia> buf = IOBuffer(" text")
IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=8, maxsize=Inf, ptr=1, mark=-1)
julia> skipchars(buf, isspace)
julia> skipchars(isspace, buf)
IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=8, maxsize=Inf, ptr=5, mark=-1)
julia> String(readavailable(buf))
"text"
```
"""
function skipchars(io::IO, pred; linecomment=nothing)
function skipchars(predicate, io::IO; linecomment=nothing)
while !eof(io)
c = read(io, Char)
if c === linecomment
readline(io)
elseif !pred(c)
elseif !predicate(c)
skip(io, -codelen(c))
break
end
Expand Down
2 changes: 1 addition & 1 deletion base/repl/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ end

function edit_replace_word_right(buf::IOBuffer, replace::Function)
# put the cursor at the beginning of the next word
skipchars(buf, is_non_word_char)
skipchars(is_non_word_char, buf)
b = position(buf)
char_move_word_right(buf)
e = position(buf)
Expand Down
12 changes: 6 additions & 6 deletions test/iobuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -262,25 +262,25 @@ end
# skipchars
let
io = IOBuffer("")
@test eof(skipchars(io, isspace))
@test eof(skipchars(isspace, io))

io = IOBuffer(" ")
@test eof(skipchars(io, isspace))
@test eof(skipchars(isspace, io))

io = IOBuffer("# \n ")
@test eof(skipchars(io, isspace, linecomment='#'))
@test eof(skipchars(isspace, io, linecomment='#'))

io = IOBuffer(" text")
skipchars(io, isspace)
skipchars(isspace, io)
@test String(readavailable(io)) == "text"

io = IOBuffer(" # comment \n text")
skipchars(io, isspace, linecomment='#')
skipchars(isspace, io, linecomment='#')
@test String(readavailable(io)) == "text"

for char in ['@','߷','','𐋺']
io = IOBuffer("alphabeticalstuff$char")
@test !eof(skipchars(io, isalpha))
@test !eof(skipchars(isalpha, io))
@test read(io, Char) == char
end
end
Expand Down
12 changes: 6 additions & 6 deletions test/iostream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ mktemp() do path, file
end

# test it doesn't error on eof
@test eof(skipchars(file, isspace))
@test eof(skipchars(isspace, file))

# test it correctly skips
append_to_file(" ")
@test eof(skipchars(file, isspace))
@test eof(skipchars(isspace, file))

# test it correctly detects comment lines
append_to_file("# \n ")
@test eof(skipchars(file, isspace, linecomment='#'))
@test eof(skipchars(isspace, file, linecomment='#'))

# test it stops at the appropriate time
append_to_file(" not a space")
@test !eof(skipchars(file, isspace))
@test !eof(skipchars(isspace, file))
@test read(file, Char) == 'n'

# test it correctly ignores the contents of comment lines
append_to_file(" #not a space \n not a space")
@test !eof(skipchars(file, isspace, linecomment='#'))
@test !eof(skipchars(isspace, file, linecomment='#'))
@test read(file, Char) == 'n'

# test it correctly handles unicode
for (byte,char) in zip(1:4, ('@','߷','','𐋺'))
append_to_file("abcdef$char")
@test Base.codelen(char) == byte
@test !eof(skipchars(file, isalpha))
@test !eof(skipchars(isalpha, file))
@test read(file, Char) == char
end
end
Expand Down

0 comments on commit f03fbf9

Please sign in to comment.