From 81cbec83b79381dd60c5ecc51cf02a27f9433a94 Mon Sep 17 00:00:00 2001 From: Kenta Sato Date: Sun, 4 Jan 2015 01:48:03 +0900 Subject: [PATCH] rename beginswith to startswith (#9578) --- NEWS.md | 2 ++ base/REPL.jl | 2 +- base/REPLCompletions.jl | 12 ++++++------ base/Terminals.jl | 2 +- base/client.jl | 2 +- base/deprecated.jl | 2 ++ base/exports.jl | 2 +- base/help.jl | 2 +- base/interactiveutil.jl | 4 ++-- base/markdown/parse/util.jl | 2 +- base/methodshow.jl | 2 +- base/multi.jl | 2 +- base/pkg/github.jl | 2 +- base/precompile.jl | 2 +- base/string.jl | 10 +++++----- doc/DocCheck.jl | 8 ++++---- doc/stdlib/strings.rst | 2 +- test/bigint.jl | 2 +- test/file.jl | 6 +++--- test/parallel.jl | 4 ++-- test/strings.jl | 12 ++++++------ 21 files changed, 44 insertions(+), 40 deletions(-) diff --git a/NEWS.md b/NEWS.md index 39810e08535d4..85a8f17b89df9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -168,6 +168,8 @@ Deprecated or removed * `randbool` is deprecated. Use `rand(Bool)` to produce a random boolean value, and `bitrand` to produce a random BitArray ([#9105], [#9569]). + * `beginswith` is deprecated and renamed to `startswith` ([#9578]). + Julia v0.3.0 Release Notes ========================== diff --git a/base/REPL.jl b/base/REPL.jl index 42b9a2c67ce42..323a0d6d7cca8 100644 --- a/base/REPL.jl +++ b/base/REPL.jl @@ -483,7 +483,7 @@ function history_move_prefix(s::LineEdit.PrefixSearchState, max_idx = length(hist.history)+1 idxs = backwards ? ((cur_idx-1):-1:1) : ((cur_idx+1):max_idx) for idx in idxs - if (idx == max_idx) || (beginswith(hist.history[idx], prefix) && (hist.history[idx] != cur_response || hist.modes[idx] != LineEdit.mode(s))) + if (idx == max_idx) || (startswith(hist.history[idx], prefix) && (hist.history[idx] != cur_response || hist.modes[idx] != LineEdit.mode(s))) m = history_move(s, hist, idx) if m == :ok if length(prefix) == 0 diff --git a/base/REPLCompletions.jl b/base/REPLCompletions.jl index 2c9c54748e1ff..3dae5f966a9a1 100644 --- a/base/REPLCompletions.jl +++ b/base/REPLCompletions.jl @@ -5,7 +5,7 @@ export completions, shell_completions, latex_completions using Base.Meta function completes_global(x, name) - return beginswith(x, name) && !('#' in x) + return startswith(x, name) && !('#' in x) end function filtered_mod_names(ffunc::Function, mod::Module, name::AbstractString, all::Bool=false, imported::Bool=false) @@ -82,7 +82,7 @@ function complete_symbol(sym, ffunc) fields = t.names for field in fields s = string(field) - if beginswith(s, name) + if startswith(s, name) push!(suggestions, s) end end @@ -100,7 +100,7 @@ function complete_keyword(s::ByteString) r = searchsorted(sorted_keywords, s) i = first(r) n = length(sorted_keywords) - while i <= n && beginswith(sorted_keywords[i],s) + while i <= n && startswith(sorted_keywords[i],s) r = first(r):i i += 1 end @@ -124,7 +124,7 @@ function complete_path(path::AbstractString, pos) matches = UTF8String[] for file in files - if beginswith(file, prefix) + if startswith(file, prefix) id = try isdir(joinpath(dir, file)) catch; false end # joinpath is not used because windows needs to complete with double-backslash push!(matches, id ? file * (@windows? "\\\\" : "/") : file) @@ -175,7 +175,7 @@ function latex_completions(string, pos) else # return possible matches; these cannot be mixed with regular # Julian completions as only latex symbols contain the leading \ - latex_names = filter(k -> beginswith(k, s), keys(latex_symbols)) + latex_names = filter(k -> startswith(k, s), keys(latex_symbols)) return (true, (sort!(collect(latex_names)), slashpos:pos, true)) end end @@ -232,7 +232,7 @@ function completions(string, pos) pname[1] != '.' && pname != "METADATA" && pname != "REQUIRE" && - beginswith(pname, s) + startswith(pname, s) end) end ffunc = (mod,x)->(isdefined(mod, x) && isa(mod.(x), Module)) diff --git a/base/Terminals.jl b/base/Terminals.jl index 9ac5db6ef1def..b94047c8e1a50 100644 --- a/base/Terminals.jl +++ b/base/Terminals.jl @@ -196,7 +196,7 @@ start_reading(t::UnixTerminal) = start_reading(t.in_stream) stop_reading(t::UnixTerminal) = stop_reading(t.in_stream) eof(t::UnixTerminal) = eof(t.in_stream) -@unix_only hascolor(t::TTYTerminal) = (beginswith(t.term_type, "xterm") || success(`tput setaf 0`)) +@unix_only hascolor(t::TTYTerminal) = (startswith(t.term_type, "xterm") || success(`tput setaf 0`)) @windows_only hascolor(t::TTYTerminal) = true end # module diff --git a/base/client.jl b/base/client.jl index db5266cb77ebd..fb0a71e980792 100644 --- a/base/client.jl +++ b/base/client.jl @@ -282,7 +282,7 @@ function process_options(args::Vector{UTF8String}) startup = false elseif args[i] == "-i" global is_interactive = true - elseif beginswith(args[i], "--color") + elseif startswith(args[i], "--color") if args[i] == "--color" color_set = true global have_color = true diff --git a/base/deprecated.jl b/base/deprecated.jl index 1157a153d69af..719d5e8aedcf1 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -264,3 +264,5 @@ const base64 = base64encode @deprecate randbool(dims::Int...) bitrand(dims) @deprecate randbool(r::AbstractRNG, dims::Dims) bitrand(r, dims) @deprecate randbool(r::AbstractRNG, dims::Int...) bitrand(r, dims) + +@deprecate beginswith startswith diff --git a/base/exports.jl b/base/exports.jl index 644fa0e62aca2..71eca1fd22acd 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -813,7 +813,7 @@ export base64decode, Base64EncodePipe, Base64DecodePipe, - beginswith, + startswith, bin, bits, bytes2hex, diff --git a/base/help.jl b/base/help.jl index 7dedb812b30e4..414460e5fb61d 100644 --- a/base/help.jl +++ b/base/help.jl @@ -13,7 +13,7 @@ end function decor_help_desc(func::AbstractString, mfunc::AbstractString, desc::AbstractString) sd = convert(Array{ByteString,1}, split(desc, '\n')) for i = 1:length(sd) - if beginswith(sd[i], func) + if startswith(sd[i], func) sd[i] = mfunc * sd[i][length(func)+1:end] else break diff --git a/base/interactiveutil.jl b/base/interactiveutil.jl index 9e3cb9a8024c3..8a3c0f95888ff 100644 --- a/base/interactiveutil.jl +++ b/base/interactiveutil.jl @@ -25,13 +25,13 @@ function edit(file::AbstractString, line::Integer) f != nothing && (file = f) end no_line_msg = "Unknown editor: no line number information passed.\nThe method is defined at line $line." - if beginswith(edname, "emacs") || edname == "gedit" + if startswith(edname, "emacs") || edname == "gedit" spawn(`$edpath +$line $file`) elseif edname == "vim" || edname == "nvim" || edname == "nano" run(`$edpath +$line $file`) elseif edname == "textmate" || edname == "mate" || edname == "kate" spawn(`$edpath $file -l $line`) - elseif beginswith(edname, "subl") || edname == "atom" + elseif startswith(edname, "subl") || edname == "atom" spawn(`$(shell_split(edpath)) $file:$line`) elseif OS_NAME == :Windows && (edname == "start" || edname == "open") spawn(`cmd /c start /b $file`) diff --git a/base/markdown/parse/util.jl b/base/markdown/parse/util.jl index 58ae86376d954..16b4a40d7e9c7 100644 --- a/base/markdown/parse/util.jl +++ b/base/markdown/parse/util.jl @@ -93,7 +93,7 @@ function startswith{T<:String}(stream::IO, ss::Vector{T}; kws...) end function startswith(stream::IO, r::Regex; eat = true, padding = false) - @assert beginswith(r.pattern, "^") + @assert Base.startswith(r.pattern, "^") start = position(stream) padding && skipwhitespace(stream) line = chomp(readline(stream)) diff --git a/base/methodshow.jl b/base/methodshow.jl index 87ae144244046..d340713746a31 100644 --- a/base/methodshow.jl +++ b/base/methodshow.jl @@ -91,7 +91,7 @@ function url(m::Method) root = cd(d) do # dir=d confuses --show-toplevel, apparently Git.readchomp(`rev-parse --show-toplevel`) end - if beginswith(file, root) + if startswith(file, root) commit = Git.readchomp(`rev-parse HEAD`, dir=d) return "https://github.com/$u/tree/$commit/"*file[length(root)+2:end]*"#L$line" else diff --git a/base/multi.jl b/base/multi.jl index 6054a70e3fd8d..adca59f51de42 100644 --- a/base/multi.jl +++ b/base/multi.jl @@ -1139,7 +1139,7 @@ end function redirect_worker_output(ident, stream) @schedule while !eof(stream) line = readline(stream) - if beginswith(line, "\tFrom worker ") + if startswith(line, "\tFrom worker ") print(line) else print("\tFrom worker $(ident):\t$line") diff --git a/base/pkg/github.jl b/base/pkg/github.jl index f6b5cf4cf4816..87007d76784d1 100644 --- a/base/pkg/github.jl +++ b/base/pkg/github.jl @@ -64,7 +64,7 @@ function token(user::AbstractString=user()) tfa = false # Check for two-factor authentication - if status == 401 && get(header, "X-GitHub-OTP", "") |> x->beginswith(x, "required") && isinteractive() + if status == 401 && get(header, "X-GitHub-OTP", "") |> x->startswith(x, "required") && isinteractive() tfa = true info("Two-factor authentication in use. Enter auth code. (You may have to re-enter your password.)") print(STDERR, "Authentication code: ") diff --git a/base/precompile.jl b/base/precompile.jl index 5992ae44abefb..f8f38795004da 100644 --- a/base/precompile.jl +++ b/base/precompile.jl @@ -183,7 +183,7 @@ precompile(Base.associate_julia_struct, (Ptr{Void}, Base.TTY)) precompile(Base.async_run_thunk, (Function,)) precompile(Base.atexit, (Function,)) precompile(Base.banner, (Base.Terminals.TTYTerminal,)) -precompile(Base.beginswith, (ASCIIString, ASCIIString)) +precompile(Base.startswith, (ASCIIString, ASCIIString)) precompile(Base.bool, (Bool,)) precompile(Base.bytestring, (ASCIIString,)) precompile(Base.call, (Type{Base.Dict{Symbol, Any}}, Base.Pair{Symbol, Base.LineEdit.Prompt}, Base.Pair{Symbol, Base.LineEdit.Prompt}, Base.Pair{Symbol, Base.LineEdit.Prompt})) diff --git a/base/string.jl b/base/string.jl index 80883e6fb5326..beef7ea2c9a22 100644 --- a/base/string.jl +++ b/base/string.jl @@ -490,9 +490,9 @@ end ==(a::AbstractString, b::AbstractString) = cmp(a,b) == 0 isless(a::AbstractString, b::AbstractString) = cmp(a,b) < 0 -# begins with and ends with predicates +# starts with and ends with predicates -function beginswith(a::AbstractString, b::AbstractString) +function startswith(a::AbstractString, b::AbstractString) i = start(a) j = start(b) while !done(a,i) && !done(b,i) @@ -502,7 +502,7 @@ function beginswith(a::AbstractString, b::AbstractString) end done(b,i) end -beginswith(str::AbstractString, chars::Chars) = !isempty(str) && str[start(str)] in chars +startswith(str::AbstractString, chars::Chars) = !isempty(str) && str[start(str)] in chars function endswith(a::AbstractString, b::AbstractString) i = endof(a) @@ -528,8 +528,8 @@ cmp(a::Symbol, b::Symbol) = int(sign(ccall(:strcmp, Int32, (Ptr{UInt8}, Ptr{UInt ==(a::ByteString, b::ByteString) = endof(a) == endof(b) && cmp(a,b) == 0 isless(a::Symbol, b::Symbol) = cmp(a,b) < 0 -beginswith(a::ByteString, b::ByteString) = beginswith(a.data, b.data) -beginswith(a::Array{UInt8,1}, b::Array{UInt8,1}) = +startswith(a::ByteString, b::ByteString) = startswith(a.data, b.data) +startswith(a::Array{UInt8,1}, b::Array{UInt8,1}) = (length(a) >= length(b) && ccall(:strncmp, Int32, (Ptr{UInt8}, Ptr{UInt8}, UInt), a, b, length(b)) == 0) # TODO: fast endswith diff --git a/doc/DocCheck.jl b/doc/DocCheck.jl index b365a9696beb5..6f1968b9b23aa 100644 --- a/doc/DocCheck.jl +++ b/doc/DocCheck.jl @@ -25,7 +25,7 @@ isdeprecated(v) = try endswith(functionloc(eval(v))[1], "deprecated.j isdocumented(v) = (s=string(v); haskey(FUNCTION_DICT, s) || haskey(MODULE_DICT, s)) -modfuncjoin(m::AbstractString, f::AbstractString) = beginswith(f, '@') ? "@$m.$(f[2:end])" : "$m.$f" +modfuncjoin(m::AbstractString, f::AbstractString) = startswith(f, '@') ? "@$m.$(f[2:end])" : "$m.$f" modfuncjoin(m, f) = modfuncjoin(string(m), string(f)) # return a list of undefined exports in a module @@ -56,7 +56,7 @@ function undocumented_by_file(m::Module) s = string(f) try for (file, line) in functionlocs(eval(f)) - if beginswith(file, JULIA_HOME) + if startswith(file, JULIA_HOME) file = replace(file, JULIA_HOME, "\$JULIA_HOME", 1) end if !haskey(undocf, file) @@ -120,10 +120,10 @@ function _undocumented_rst() deprecated=[strip(x) for x in split(replace(open(readall, "$JULIA_HOME/../../base/deprecated.jl"),",",""),"\n")] for line in deprecated - if beginswith(line, "@deprecated") + if startswith(line, "@deprecated") fn = split(line, r" +")[2] if haskey(MODULE_DICT, fn); push!(out, string("- [ ] ", fn)); depdoc += 1 end - elseif beginswith(line, "export") + elseif startswith(line, "export") for fn in split(line, r"[ ,]+")[2:end] if haskey(MODULE_DICT, fn); push!(out, string("- [ ]", fn)); depdoc += 1 end end diff --git a/doc/stdlib/strings.rst b/doc/stdlib/strings.rst index 6534ce2589dcb..07e449fe72050 100644 --- a/doc/stdlib/strings.rst +++ b/doc/stdlib/strings.rst @@ -189,7 +189,7 @@ Return ``string`` with any trailing whitespace removed. If ``chars`` (a character, or vector or set of characters) is provided, instead remove characters contained in it. -.. function:: beginswith(string, prefix | chars) +.. function:: startswith(string, prefix | chars) Returns ``true`` if ``string`` starts with ``prefix``. If the second argument is a vector or set of characters, tests whether the first character of ``string`` belongs to that set. diff --git a/test/bigint.jl b/test/bigint.jl index 8463edf174199..39d620f0f0d9a 100644 --- a/test/bigint.jl +++ b/test/bigint.jl @@ -252,7 +252,7 @@ n = bigfib(1000001) s = string(n) @test length(s) == 208988 @test endswith(s, "359244926937501") -@test beginswith(s, "316047687386689") +@test startswith(s, "316047687386689") # serialization (#5133) let diff --git a/test/file.jl b/test/file.jl index 8585821d1bb3b..313fa510df612 100644 --- a/test/file.jl +++ b/test/file.jl @@ -199,7 +199,7 @@ close(s) s = open(file, "r") str = readline(s) close(s) -@test beginswith(str, "Hellx World") +@test startswith(str, "Hellx World") c=nothing; gc(); gc(); # cause munmap finalizer to run & free resources s = open(file, "w") @@ -261,12 +261,12 @@ close(s) s = open(file) mark(s) str = readline(s) -@test beginswith(str, "Marked!") +@test startswith(str, "Marked!") @test ismarked(s) reset(s) @test !ismarked(s) str = readline(s) -@test beginswith(str, "Marked!") +@test startswith(str, "Marked!") mark(s) @test readline(s) == "Hello world!\n" @test ismarked(s) diff --git a/test/parallel.jl b/test/parallel.jl index 7b0b9398b8258..415158f0a6097 100644 --- a/test/parallel.jl +++ b/test/parallel.jl @@ -33,11 +33,11 @@ dims = (20,20,20) @linux_only begin S = SharedArray(Int64, dims) - @test beginswith(S.segname, "/jl") + @test startswith(S.segname, "/jl") @test !ispath("/dev/shm" * S.segname) S = SharedArray(Int64, dims; pids=[id_other]) - @test beginswith(S.segname, "/jl") + @test startswith(S.segname, "/jl") @test !ispath("/dev/shm" * S.segname) end diff --git a/test/strings.jl b/test/strings.jl index c33b1e1642003..b7ac575d0c69c 100644 --- a/test/strings.jl +++ b/test/strings.jl @@ -658,12 +658,12 @@ end @test replace("ḟøøƀäṙḟøø", r"(ḟøø|ƀä)", "ƀäṙ") == "ƀäṙƀäṙṙƀäṙ" -# {begins,ends}with -@test beginswith("abcd", 'a') -@test beginswith("abcd", "a") -@test beginswith("abcd", "ab") -@test !beginswith("ab", "abcd") -@test !beginswith("abcd", "bc") +# {starts,ends}with +@test startswith("abcd", 'a') +@test startswith("abcd", "a") +@test startswith("abcd", "ab") +@test !startswith("ab", "abcd") +@test !startswith("abcd", "bc") @test endswith("abcd", 'd') @test endswith("abcd", "d") @test endswith("abcd", "cd")