Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contains(haystack, needle) -> occursin(needle, haystack) #677

Merged
merged 1 commit into from
Mar 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
julia 0.6
Compat 0.58.0
Compat 0.62.0
DocStringExtensions 0.2
4 changes: 2 additions & 2 deletions src/CrossReferences.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const NAMED_XREF = r"^@ref (.+)$"

function xref(link::Markdown.Link, meta, page, doc)
link.url == "@ref" ? basicxref(link, meta, page, doc) :
contains(link.url, NAMED_XREF) ? namedxref(link, meta, page, doc) : nothing
occursin(NAMED_XREF, link.url) ? namedxref(link, meta, page, doc) : nothing
return false # Stop `walk`ing down this `link` element.
end
xref(other, meta, page, doc) = true # Continue to `walk` through element `other`.
Expand All @@ -55,7 +55,7 @@ function basicxref(link::Markdown.Link, meta, page, doc)
elseif isa(link.text, Vector)
# No `name` was provided, since given a `@ref`, so slugify the `.text` instead.
text = strip(sprint(Markdown.plain, Markdown.Paragraph(link.text)))
if contains(text, r"#[0-9]+")
if occursin(r"#[0-9]+", text)
issue_xref(link, lstrip(text, '#'), meta, page, doc)
else
name = Utilities.slugify(text)
Expand Down
2 changes: 1 addition & 1 deletion src/Deps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function localbin()
end

function updatepath!(p = localbin())
if contains(ENV["PATH"], p)
if occursin(p, ENV["PATH"])
ENV["PATH"]
else
ENV["PATH"] = "$p:$(ENV["PATH"])"
Expand Down
16 changes: 8 additions & 8 deletions src/DocChecks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ function doctest(block::Markdown.Code, meta::Dict, doc::Documents.Document, page
Meta.isexpr(expr, :block) && (expr.head = :toplevel)
eval(sandbox, expr)
end
if contains(block.code, r"^julia> "m)
if occursin(r"^julia> "m, block.code)
eval_repl(block, sandbox, meta, doc, page)
block.language = "julia-repl"
elseif contains(block.code, r"^# output$"m)
elseif occursin(r"^# output$"m, block.code)
eval_script(block, sandbox, meta, doc, page)
block.language = "julia"
else
Expand Down Expand Up @@ -280,7 +280,7 @@ function filter_doctests(strings::NTuple{2, AbstractString},
meta_block_filters == nothing && meta_block_filters == []
doctest_local_filters = get(meta[:LocalDocTestArguments], :filter, [])
for r in [doc.user.doctestfilters; meta_block_filters; doctest_local_filters]
if all(contains.(strings, r))
if all(occursin.(r, strings))
strings = replace.(strings, r => "")
end
end
Expand Down Expand Up @@ -456,7 +456,7 @@ function repl_splitter(code)
# TODO: handle multiline comments?
# ANON_FUNC_DECLARATION deals with `x->x` -> `#1 (generic function ....)` on 0.7
# TODO: Remove this special case and just disallow lines with comments?
startswith(line, '#') && !contains(line, ANON_FUNC_DECLARATION) && continue
startswith(line, '#') && !occursin(ANON_FUNC_DECLARATION, line) && continue
prompt = match(PROMPT_REGEX, line)
if prompt === nothing
source = match(SOURCE_REGEX, line)
Expand Down Expand Up @@ -484,7 +484,7 @@ end
function takeuntil!(r, buf, lines)
while !isempty(lines)
line = lines[1]
if !contains(line, r)
if !occursin(r, line)
println(buf, popfirst!(lines))
else
break
Expand Down Expand Up @@ -595,13 +595,13 @@ function linkcheck(link::Markdown.Link, doc::Documents.Document)
return false
end
local STATUS_REGEX = r"^HTTP/1.1 (\d+) (.+)$"m
if contains(result, STATUS_REGEX)
if occursin(STATUS_REGEX, result)
status = parse(Int, match(STATUS_REGEX, result).captures[1])
if status < 300
printstyled(INDENT, "$(status) ", link.url, "\n", color=:green)
elseif status < 400
LOCATION_REGEX = r"^Location: (.+)$"m
if contains(result, LOCATION_REGEX)
if occursin(LOCATION_REGEX, result)
location = strip(match(LOCATION_REGEX, result).captures[1])
printstyled(INDENT, "$(status) ", link.url, "\n", color=:yellow)
printstyled(INDENT, " -> ", location, "\n\n", color=:yellow)
Expand All @@ -622,7 +622,7 @@ end
linkcheck(other, doc::Documents.Document) = true

linkcheck_ismatch(r::String, url) = (url == r)
linkcheck_ismatch(r::Regex, url) = contains(url, r)
linkcheck_ismatch(r::Regex, url) = occursin(r, url)

function disable_color(func)
orig = setcolor!(false)
Expand Down
8 changes: 4 additions & 4 deletions src/Documenter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,13 @@ function deploydocs(;
if !isa(julia, AbstractString)
error("julia must be a string, got $julia ($(typeof(julia)))")
end
if !isempty(travis_repo_slug) && !contains(repo, travis_repo_slug)
if !isempty(travis_repo_slug) && !occursin(travis_repo_slug, repo)
warn("repo $repo does not match $travis_repo_slug")
end

# When should a deploy be attempted?
should_deploy =
contains(repo, travis_repo_slug) &&
occursin(travis_repo_slug, repo) &&
travis_pull_request == "false" &&
travis_osname == osname &&
travis_julia == julia &&
Expand Down Expand Up @@ -518,7 +518,7 @@ function git_push(
Writers.HTMLWriter.generate_siteinfo_file(tagged_dir, tag)
# Build a `release-*.*` folder as well when the travis tag is
# valid, which it *should* always be anyway.
if contains(tag, Base.VERSION_REGEX)
if occursin(Base.VERSION_REGEX, tag)
version = VersionNumber(tag)
release = "release-$(version.major).$(version.minor)"
gitrm_copy(target_dir, joinpath(dirname, release))
Expand Down Expand Up @@ -584,7 +584,7 @@ end

function getenv(regex::Regex)
for (key, value) in ENV
contains(key, regex) && return value
occursin(regex, key) && return value
end
error("could not find key/iv pair.")
end
Expand Down
6 changes: 3 additions & 3 deletions src/Expanders.jl
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ end
# Utilities.
# ----------

iscode(x::Markdown.Code, r::Regex) = contains(x.language, r)
iscode(x::Markdown.Code, r::Regex) = occursin(r, x.language)
iscode(x::Markdown.Code, lang) = x.language == lang
iscode(x, lang) = false

Expand All @@ -571,7 +571,7 @@ const NAMEDHEADER_REGEX = r"^@id (.+)$"
function namedheader(h::Markdown.Header)
if isa(h.text, Vector) && length(h.text) === 1 && isa(h.text[1], Markdown.Link)
url = h.text[1].url
contains(url, NAMEDHEADER_REGEX)
occursin(NAMEDHEADER_REGEX, url)
else
false
end
Expand All @@ -581,7 +581,7 @@ end
function droplines(code; skip = 0)
buffer = IOBuffer()
for line in split(code, '\n')[(skip + 1):end]
contains(line, r"^(.*)#\s*hide$") && continue
occursin(r"^(.*)#\s*hide$", line) && continue
println(buffer, rstrip(line))
end
strip(String(take!(buffer)), '\n')
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/DOM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ string is constructed with the characters escaped. The returned object should
always be treated as an immutable copy and compared using `==` rather than `===`.
"""
function escapehtml(text::AbstractString)
if contains(text, r"[<>&'\"]")
if occursin(r"[<>&'\"]", text)
buffer = IOBuffer()
for char in text
char === '<' ? write(buffer, "&lt;") :
Expand Down
12 changes: 6 additions & 6 deletions src/Utilities/Utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function parseblock(code::AbstractString, doc, page; skip = 0, keywords = true)
code = string(code, '\n')
code = last(split(code, '\n', limit = skip + 1))
# Check whether we have windows-style line endings.
offset = contains(code, "\n\r") ? 2 : 1
offset = occursin("\n\r", code) ? 2 : 1
endofstr = lastindex(code)
results = []
cursor = 1
Expand Down Expand Up @@ -332,7 +332,7 @@ filterdocs(other, modules::Set{Module}) = other
"""
Does the given docstring represent actual documentation or a no docs error message?
"""
nodocs(x) = contains(stringmime("text/plain", x), "No documentation found.")
nodocs(x) = occursin("No documentation found.", stringmime("text/plain", x))
nodocs(::Nothing) = false

header_level(::Markdown.Header{N}) where {N} = N
Expand Down Expand Up @@ -464,11 +464,11 @@ end
# "https://bitbucket.org/xxx" => RepoBitbucket
# If no match, returns RepoUnknown
function repo_host_from_url(repoURL::String)
if contains(repoURL, "bitbucket")
if occursin("bitbucket", repoURL)
return RepoBitbucket
elseif contains(repoURL, "github")
elseif occursin("github", repoURL)
return RepoGithub
elseif contains(repoURL, "gitlab")
elseif occursin("gitlab", repoURL)
return RepoGitlab
else
return RepoUnknown
Expand Down Expand Up @@ -592,7 +592,7 @@ end
Checks whether `url` is an absolute URL (as opposed to a relative one).
"""
isabsurl(url) = contains(url, ABSURL_REGEX)
isabsurl(url) = occursin(ABSURL_REGEX, url)
const ABSURL_REGEX = r"^[[:alpha:]+-.]+://"

include("DOM.jl")
Expand Down
6 changes: 3 additions & 3 deletions src/Writers/HTMLWriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@ function generate_version_file(dir::AbstractString)
tag_folders = []
for each in readdir(dir)
each in ("stable", "latest") ? push!(named_folders, each) :
contains(each, r"release\-\d+\.\d+") ? push!(release_folders, each) :
contains(each, Base.VERSION_REGEX) ? push!(tag_folders, each) : nothing
occursin(r"release\-\d+\.\d+", each) ? push!(release_folders, each) :
occursin(Base.VERSION_REGEX, each) ? push!(tag_folders, each) : nothing
end
open(joinpath(dir, "versions.js"), "w") do buf
println(buf, "var DOC_VERSIONS = [")
Expand Down Expand Up @@ -895,7 +895,7 @@ function mdconvert(c::Markdown.Code, parent::MDBlockContext; kwargs...)
# script-type doctest should match the corresponding one in DocChecks.jl. This makes
# sure that doctests get highlighted the same way independent of whether they're
# being run or not.
contains(c.code, r"^julia> "m) ? "julia-repl" : "julia"
occursin(r"^julia> "m, c.code) ? "julia-repl" : "julia"
else
c.language
end
Expand Down
4 changes: 2 additions & 2 deletions src/Writers/LaTeXWriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ function latex(io::IO, code::Markdown.Code)
# script-type doctest should match the corresponding one in DocChecks.jl. This makes
# sure that doctests get highlighted the same way independent of whether they're
# being run or not.
contains(code.code, r"^julia> "m) ? "julia-repl" : "julia"
occursin(r"^julia> "m, code.code) ? "julia-repl" : "julia"
else
code.language
end
Expand Down Expand Up @@ -440,7 +440,7 @@ function latexinline(io::IO, md::Markdown.Link)
if io.in_header
latexinline(io, md.text)
else
if contains(md.url, ".md#")
if occursin(".md#", md.url)
file, target = split(md.url, ".md#"; limit = 2)
id = string(hash(target))
wrapinline(io, "hyperlink") do
Expand Down
5 changes: 3 additions & 2 deletions test/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module UtilitiesTests

import Compat
using Compat.Test
import Compat: occursin
import Compat.Base64: stringmime

import Documenter
Expand Down Expand Up @@ -47,9 +48,9 @@ end
@test a !== nothing
@test a === doc
@test b !== nothing
@test contains(stringmime("text/plain", b), "Documenter unit tests.")
@test occursin("Documenter unit tests.", stringmime("text/plain", b))
@test c !== nothing
@test !contains(stringmime("text/plain", c), "Documenter unit tests.")
@test !occursin("Documenter unit tests.", stringmime("text/plain", c))
@test d === nothing
end

Expand Down