Skip to content

Commit

Permalink
rename beginswith to startswith (#9578)
Browse files Browse the repository at this point in the history
  • Loading branch information
bicycle1885 committed Jan 3, 2015
1 parent b365c36 commit 81cbec8
Show file tree
Hide file tree
Showing 21 changed files with 44 additions and 40 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
==========================

Expand Down
2 changes: 1 addition & 1 deletion base/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions base/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion base/Terminals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ export
base64decode,
Base64EncodePipe,
Base64DecodePipe,
beginswith,
startswith,
bin,
bits,
bytes2hex,
Expand Down
2 changes: 1 addition & 1 deletion base/help.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions base/interactiveutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
2 changes: 1 addition & 1 deletion base/markdown/parse/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion base/methodshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion base/multi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion base/pkg/github.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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: ")
Expand Down
2 changes: 1 addition & 1 deletion base/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}))
Expand Down
10 changes: 5 additions & 5 deletions base/string.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions doc/DocCheck.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion doc/stdlib/strings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion test/bigint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/parallel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions test/strings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 81cbec8

Please sign in to comment.