Skip to content

Commit

Permalink
base: use eachsplit where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
anaveragehuman committed Apr 3, 2021
1 parent 4d1e0b2 commit 94e3e09
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion base/binaryplatforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ function Base.parse(::Type{Platform}, triplet::AbstractString; validate_strict::
libstdcxx_version = get_field(m, libstdcxx_version_mapping)
cxxstring_abi = get_field(m, cxxstring_abi_mapping)
function split_tags(tagstr)
tag_fields = filter(!isempty, split(tagstr, "-"))
tag_fields = split(tagstr, "-"; keepempty=false)
if isempty(tag_fields)
return Pair{String,String}[]
end
Expand Down
4 changes: 2 additions & 2 deletions base/cmd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function addenv(cmd::Cmd, env::Dict; inherit::Bool = true)
merge!(new_env, ENV)
end
else
for (k, v) in split.(cmd.env, "=")
for (k, v) in eachsplit.(cmd.env, "=")
new_env[string(k)::String] = string(v)::String
end
end
Expand All @@ -277,7 +277,7 @@ function addenv(cmd::Cmd, pairs::Pair{<:AbstractString}...; inherit::Bool = true
end

function addenv(cmd::Cmd, env::Vector{<:AbstractString}; inherit::Bool = true)
return addenv(cmd, Dict(k => v for (k, v) in split.(env, "=")); inherit)
return addenv(cmd, Dict(k => v for (k, v) in eachsplit.(env, "=")); inherit)
end

(&)(left::AbstractCmd, right::AbstractCmd) = AndCmds(left, right)
Expand Down
4 changes: 2 additions & 2 deletions base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function init_depot_path()
if haskey(ENV, "JULIA_DEPOT_PATH")
str = ENV["JULIA_DEPOT_PATH"]
isempty(str) && return
for path in split(str, Sys.iswindows() ? ';' : ':')
for path in eachsplit(str, Sys.iswindows() ? ';' : ':')
if isempty(path)
append_default_depot_path!(DEPOT_PATH)
else
Expand Down Expand Up @@ -199,7 +199,7 @@ end
function parse_load_path(str::String)
envs = String[]
isempty(str) && return envs
for env in split(str, Sys.iswindows() ? ';' : ':')
for env in eachsplit(str, Sys.iswindows() ? ';' : ':')
if isempty(env)
for env′ in DEFAULT_LOAD_PATH
env′ in envs || push!(envs, env′)
Expand Down
9 changes: 5 additions & 4 deletions base/logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,11 @@ function handle_message(logger::SimpleLogger, level::LogLevel, message, _module,
buf = IOBuffer()
iob = IOContext(buf, logger.stream)
levelstr = level == Warn ? "Warning" : string(level)
msglines = split(chomp(string(message)::String), '\n')
println(iob, "", levelstr, ": ", msglines[1])
for i in 2:length(msglines)
println(iob, "", msglines[i])
msglines = eachsplit(chomp(string(message)::String), '\n')
msg1, rest = Iterators.peel(msglines)
println(iob, "", levelstr, ": ", msg1)
for msg in rest
println(iob, "", msg)
end
for (key, val) in kwargs
key === :maxlog && continue
Expand Down
4 changes: 2 additions & 2 deletions base/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ function string_mpfr(x::BigFloat, fmt::String)
end

function _prettify_bigfloat(s::String)::String
mantissa, exponent = split(s, 'e')
mantissa, exponent = eachsplit(s, 'e')
if !occursin('.', mantissa)
mantissa = string(mantissa, '.')
end
Expand All @@ -973,7 +973,7 @@ function _prettify_bigfloat(s::String)::String
expo = parse(Int, exponent)
if -5 < expo < 6
expo == 0 && return mantissa
int, frac = split(mantissa, '.')
int, frac = eachsplit(mantissa, '.')
if expo > 0
expo < length(frac) ?
string(int, frac[1:expo], '.', frac[expo+1:end]) :
Expand Down
4 changes: 2 additions & 2 deletions base/path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ function normpath(path::String)
isabs = isabspath(path)
isdir = isdirpath(path)
drive, path = splitdrive(path)
parts = split(path, path_separator_re)
filter!(x->!isempty(x) && x!=".", parts)
parts = split(path, path_separator_re; keepempty=false)
filter!(!=("."), parts)
while true
clean = true
for j = 1:length(parts)-1
Expand Down
2 changes: 1 addition & 1 deletion base/sysinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ function which(program_name::String)
# If we have been given just a program name (not a relative or absolute
# path) then we should search `PATH` for it here:
pathsep = iswindows() ? ';' : ':'
path_dirs = abspath.(split(get(ENV, "PATH", ""), pathsep))
path_dirs = map(abspath, eachsplit(get(ENV, "PATH", ""), pathsep))

# On windows we always check the current directory as well
if iswindows()
Expand Down
2 changes: 1 addition & 1 deletion base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function with_output_color(@nospecialize(f::Function), color::Union{Int, Symbol}
(bold ? disable_text_style[:bold] : "") *
get(disable_text_style, color, text_colors[:default])
first = true
for line in split(str, '\n')
for line in eachsplit(str, '\n')
first || print(buf, '\n')
first = false
isempty(line) && continue
Expand Down
2 changes: 1 addition & 1 deletion base/version.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const VERSION_REGEX = r"^
$"ix

function split_idents(s::AbstractString)
idents = split(s, '.')
idents = eachsplit(s, '.')
pidents = Union{UInt64,String}[occursin(r"^\d+$", ident) ? parse(UInt64, ident) : String(ident) for ident in idents]
return tuple(pidents...)::VerTuple
end
Expand Down

0 comments on commit 94e3e09

Please sign in to comment.