From 5a2536015d6fc905532dfa11676b57ea1775486b Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Sat, 1 Nov 2014 13:42:16 -0400 Subject: [PATCH] rename String => AbstractString --- NEWS.md | 2 + base/LineEdit.jl | 6 +- base/REPL.jl | 22 +- base/REPLCompletions.jl | 8 +- base/Terminals.jl | 2 +- base/ascii.jl | 2 +- base/base.jl | 18 +- base/boot.jl | 8 +- base/c.jl | 12 +- base/client.jl | 10 +- base/datafmt.jl | 42 +-- base/dates/accessors.jl | 2 +- base/dates/adjusters.jl | 2 +- base/dates/arithmetic.jl | 2 +- base/dates/conversions.jl | 2 +- base/dates/io.jl | 28 +- base/dates/periods.jl | 6 +- base/dates/query.jl | 18 +- base/dates/ranges.jl | 2 +- base/deprecated.jl | 6 +- base/dict.jl | 2 +- base/env.jl | 32 +- base/error.jl | 2 +- base/fftw.jl | 4 +- base/file.jl | 26 +- base/floatfuncs.jl | 2 +- base/fs.jl | 22 +- base/gmp.jl | 4 +- base/grisu/bignum.jl | 2 +- base/grisu/fastprecision.jl | 2 +- base/grisu/fastshortest.jl | 2 +- base/grisu/float.jl | 2 +- base/help.jl | 8 +- base/inference.jl | 10 +- base/interactiveutil.jl | 18 +- base/io.jl | 6 +- base/iostream.jl | 16 +- base/libc.jl | 8 +- base/linalg/arnoldi.jl | 2 +- base/linalg/cholmod.jl | 2 +- base/linalg/umfpack.jl | 2 +- base/loading.jl | 24 +- base/mpfr.jl | 4 +- base/multi.jl | 18 +- base/multimedia.jl | 28 +- base/operators.jl | 2 +- base/path.jl | 40 +-- base/pcre.jl | 2 +- base/pkg.jl | 48 +-- base/pkg/cache.jl | 6 +- base/pkg/dir.jl | 6 +- base/pkg/entry.jl | 64 ++-- base/pkg/generate.jl | 42 +-- base/pkg/git.jl | 8 +- base/pkg/github.jl | 30 +- base/pkg/read.jl | 20 +- base/pkg/reqs.jl | 26 +- base/pkg/types.jl | 2 +- base/pkg/write.jl | 12 +- base/poll.jl | 2 +- base/precompile.jl | 10 +- base/printf.jl | 22 +- base/process.jl | 18 +- base/random.jl | 10 +- base/regex.jl | 22 +- base/sharedarray.jl | 2 +- base/show.jl | 26 +- base/socket.jl | 8 +- base/stat.jl | 6 +- base/stream.jl | 10 +- base/string.jl | 334 +++++++++--------- base/sysinfo.jl | 10 +- base/utf16.jl | 6 +- base/utf32.jl | 6 +- base/utf8.jl | 6 +- base/utf8proc.jl | 8 +- base/util.jl | 14 +- base/version.jl | 6 +- base/version_git.sh | 8 +- doc/DocCheck.jl | 16 +- doc/helpdb.jl | 194 +++++----- doc/manual/calling-c-and-fortran-code.rst | 2 +- .../integers-and-floating-point-numbers.rst | 2 +- doc/manual/interacting-with-julia.rst | 8 +- doc/manual/metaprogramming.rst | 2 +- doc/manual/parallel-computing.rst | 8 +- doc/manual/strings.rst | 18 +- doc/manual/style-guide.rst | 4 +- doc/manual/types.rst | 42 +-- doc/stdlib/base.rst | 116 +++--- doc/stdlib/dates.rst | 12 +- doc/stdlib/file.rst | 28 +- doc/stdlib/pkg.rst | 6 +- doc/stdlib/sparse.rst | 2 +- doc/tabcomplete.jl | 2 +- test/collections.jl | 22 +- test/core.jl | 22 +- test/dates.jl | 2 +- test/dates/accessors.jl | 2 +- test/dates/adjusters.jl | 2 +- test/dates/arithmetic.jl | 2 +- test/dates/conversions.jl | 2 +- test/gitutils.jl | 10 +- test/linalg/lapack.jl | 2 +- test/linalg/tridiag.jl | 2 +- test/netload/memtest.jl | 2 +- test/perf/blas/perf.jl | 2 +- test/perf/kernel/json.jl | 8 +- test/perf/shootout/k_nucleotide.jl | 10 +- test/perf/shootout/perf.jl | 2 +- test/perf/sort/perf.jl | 10 +- test/perf/spell/perf.jl | 12 +- test/reflection.jl | 6 +- test/replcompletions.jl | 2 +- test/strings.jl | 4 +- 115 files changed, 942 insertions(+), 936 deletions(-) diff --git a/NEWS.md b/NEWS.md index edead637c40c2..74d7a9b8584b2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -99,6 +99,8 @@ Library improvements * The `machinefile` now supports an host count ([#7616]). + * `String` has been renamed to `AbstractString`. + Deprecated or removed --------------------- diff --git a/base/LineEdit.jl b/base/LineEdit.jl index cc3ced4a1e6d2..ae777dcf86fb4 100644 --- a/base/LineEdit.jl +++ b/base/LineEdit.jl @@ -183,7 +183,7 @@ function _clear_input_area(terminal, state::InputAreaState) end prompt_string(s::PromptState) = s.p.prompt -prompt_string(s::String) = s +prompt_string(s::AbstractString) = s refresh_multi_line(termbuf::TerminalBuffer, s::PromptState) = s.ias = refresh_multi_line(termbuf, terminal(s), buffer(s), s.ias, s, indent = s.indent) @@ -457,7 +457,7 @@ end # splice! for IOBuffer: convert from 0-indexed positions, update the size, # and keep the cursor position stable with the text -function splice_buffer!{T<:Integer}(buf::IOBuffer, r::UnitRange{T}, ins::String = "") +function splice_buffer!{T<:Integer}(buf::IOBuffer, r::UnitRange{T}, ins::AbstractString = "") pos = position(buf) if !isempty(r) && pos in r seek(buf, first(r)) @@ -652,7 +652,7 @@ write_prompt(terminal, s::ASCIIString) = write(terminal, s) normalize_key(key::Char) = string(key) normalize_key(key::Integer) = normalize_key(char(key)) -function normalize_key(key::String) +function normalize_key(key::AbstractString) '\0' in key && error("Matching \\0 not currently supported.") buf = IOBuffer() i = start(key) diff --git a/base/REPL.jl b/base/REPL.jl index 97cb7d09c27cb..8dc532c013e4b 100644 --- a/base/REPL.jl +++ b/base/REPL.jl @@ -67,7 +67,7 @@ function eval_user_input(ast::ANY, backend::REPLBackend) end end -function parse_input_line(s::String) +function parse_input_line(s::AbstractString) # s = bytestring(s) # (expr, pos) = parse(s, 1) # (ex, pos) = ccall(:jl_parse_string, Any, @@ -232,11 +232,11 @@ end type LineEditREPL <: AbstractREPL t::TextTerminal hascolor::Bool - prompt_color::String - input_color::String - answer_color::String - shell_color::String - help_color::String + prompt_color::AbstractString + input_color::AbstractString + answer_color::AbstractString + shell_color::AbstractString + help_color::AbstractString no_history_file::Bool in_shell::Bool in_help::Bool @@ -298,7 +298,7 @@ end type REPLHistoryProvider <: HistoryProvider - history::Array{String,1} + history::Array{AbstractString,1} history_file cur_idx::Int last_idx::Int @@ -308,7 +308,7 @@ type REPLHistoryProvider <: HistoryProvider modes::Array{Symbol,1} end REPLHistoryProvider(mode_mapping) = - REPLHistoryProvider(String[], nothing, 0, -1, IOBuffer(), + REPLHistoryProvider(AbstractString[], nothing, 0, -1, IOBuffer(), nothing, mode_mapping, Uint8[]) const invalid_history_message = """ @@ -836,9 +836,9 @@ end type StreamREPL <: AbstractREPL stream::IO - prompt_color::String - input_color::String - answer_color::String + prompt_color::AbstractString + input_color::AbstractString + answer_color::AbstractString waserror::Bool StreamREPL(stream,pc,ic,ac) = new(stream,pc,ic,ac,false) end diff --git a/base/REPLCompletions.jl b/base/REPLCompletions.jl index df8c965d58f47..82114eaa3b8b0 100644 --- a/base/REPLCompletions.jl +++ b/base/REPLCompletions.jl @@ -8,7 +8,7 @@ function completes_global(x, name) return beginswith(x, name) && !('#' in x) end -function filtered_mod_names(ffunc::Function, mod::Module, name::String, all::Bool=false, imported::Bool=false) +function filtered_mod_names(ffunc::Function, mod::Module, name::AbstractString, all::Bool=false, imported::Bool=false) ssyms = names(mod, all, imported) filter!(ffunc, ssyms) syms = UTF8String[string(s) for s in ssyms] @@ -107,7 +107,7 @@ function complete_keyword(s::ByteString) sorted_keywords[r] end -function complete_path(path::String, pos) +function complete_path(path::AbstractString, pos) dir, prefix = splitdir(path) local files try @@ -133,7 +133,7 @@ function complete_path(path::String, pos) matches, (nextind(path, pos-sizeof(prefix))):pos, length(matches) > 0 end -function complete_methods(input::String) +function complete_methods(input::AbstractString) tokens = split(input, '.') fn = Main for token in tokens @@ -254,7 +254,7 @@ function shell_completions(string, pos) # Now look at the last thing we parsed isempty(args.args[end].args) && return UTF8String[], 0:-1, false arg = args.args[end].args[end] - if all(map(s -> isa(s, String), args.args[end].args)) + if all(map(s -> isa(s, AbstractString), args.args[end].args)) # Treat this as a path (perhaps give a list of comands in the future as well?) return complete_path(join(args.args[end].args), pos) elseif isexpr(arg, :escape) && (isexpr(arg.args[1], :incomplete) || isexpr(arg.args[1], :error)) diff --git a/base/Terminals.jl b/base/Terminals.jl index ada72ab06d16b..a8c8fc44947f4 100644 --- a/base/Terminals.jl +++ b/base/Terminals.jl @@ -187,7 +187,7 @@ write(t::UnixTerminal, p::Ptr{Uint8}) = write(t.out_stream, p) write(t::UnixTerminal, p::Ptr{Uint8}, x::Integer) = write(t.out_stream, p, x) write(t::UnixTerminal, x::Uint8) = write(t.out_stream, x) read{T,N}(t::UnixTerminal, x::Array{T,N}) = read(t.in_stream, x) -readuntil(t::UnixTerminal, s::String) = readuntil(t.in_stream, s) +readuntil(t::UnixTerminal, s::AbstractString) = readuntil(t.in_stream, s) readuntil(t::UnixTerminal, c::Char) = readuntil(t.in_stream, c) readuntil(t::UnixTerminal, s) = readuntil(t.in_stream, s) read(t::UnixTerminal, ::Type{Uint8}) = read(t.in_stream, Uint8) diff --git a/base/ascii.jl b/base/ascii.jl index 75c4fd12b765f..1dff10a0213db 100644 --- a/base/ascii.jl +++ b/base/ascii.jl @@ -117,4 +117,4 @@ function convert(::Type{ASCIIString}, a::Array{Uint8,1}, invalids_as::ASCIIStrin end convert(ASCIIString, a) end -convert(::Type{ASCIIString}, s::String) = ascii(bytestring(s)) +convert(::Type{ASCIIString}, s::AbstractString) = ascii(bytestring(s)) diff --git a/base/base.jl b/base/base.jl index 129b4ebf068b1..7a4e9306ffebe 100644 --- a/base/base.jl +++ b/base/base.jl @@ -59,36 +59,36 @@ cconvert(T, x) = convert(T, x) # use the code in ccall.cpp to safely allocate temporary pointer arrays cconvert{T}(::Type{Ptr{Ptr{T}}}, a::Array) = a # convert strings to ByteString to pass as pointers -cconvert{P<:Union(Int8,Uint8)}(::Type{Ptr{P}}, s::String) = bytestring(s) +cconvert{P<:Union(Int8,Uint8)}(::Type{Ptr{P}}, s::AbstractString) = bytestring(s) reinterpret{T,S}(::Type{T}, x::S) = box(T,unbox(S,x)) abstract IO type ErrorException <: Exception - msg::String + msg::AbstractString end type SystemError <: Exception - prefix::String + prefix::AbstractString errnum::Int32 - SystemError(p::String, e::Integer) = new(p, int32(e)) - SystemError(p::String) = new(p, errno()) + SystemError(p::AbstractString, e::Integer) = new(p, int32(e)) + SystemError(p::AbstractString) = new(p, errno()) end type TypeError <: Exception func::Symbol - context::String + context::AbstractString expected::Type got end type ParseError <: Exception - msg::String + msg::AbstractString end type ArgumentError <: Exception - msg::String + msg::AbstractString end #type UnboundError <: Exception @@ -100,7 +100,7 @@ type KeyError <: Exception end type LoadError <: Exception - file::String + file::AbstractString line::Int error end diff --git a/base/boot.jl b/base/boot.jl index 737bce7308c0f..b11a3b3e08a49 100644 --- a/base/boot.jl +++ b/base/boot.jl @@ -128,7 +128,7 @@ export Int32, Int64, Int128, Ptr, Real, Signed, Uint, Uint8, Uint16, Uint32, Uint64, Uint128, Unsigned, # string types - Char, ASCIIString, ByteString, DirectIndexString, String, UTF8String, + Char, ASCIIString, ByteString, DirectIndexString, AbstractString, UTF8String, # errors BoundsError, DivideError, DomainError, Exception, InexactError, InterruptException, MemoryError, OverflowError, @@ -214,8 +214,8 @@ type UndefVarError <: Exception end type InterruptException <: Exception end -abstract String -abstract DirectIndexString <: String +abstract AbstractString +abstract DirectIndexString <: AbstractString type SymbolNode name::Symbol @@ -233,7 +233,7 @@ immutable ASCIIString <: DirectIndexString data::Array{Uint8,1} end -immutable UTF8String <: String +immutable UTF8String <: AbstractString data::Array{Uint8,1} end diff --git a/base/c.jl b/base/c.jl index 0ebbf053ee5ed..fa10ae50543ce 100644 --- a/base/c.jl +++ b/base/c.jl @@ -12,12 +12,12 @@ const RTLD_NOLOAD = 0x00000010 const RTLD_DEEPBIND = 0x00000020 const RTLD_FIRST = 0x00000040 -function dlsym(hnd::Ptr, s::Union(Symbol,String)) +function dlsym(hnd::Ptr, s::Union(Symbol,AbstractString)) hnd == C_NULL && error("NULL library handle") ccall(:jl_dlsym, Ptr{Void}, (Ptr{Void}, Ptr{Uint8}), hnd, s) end -function dlsym_e(hnd::Ptr, s::Union(Symbol,String)) +function dlsym_e(hnd::Ptr, s::Union(Symbol,AbstractString)) hnd == C_NULL && error("NULL library handle") ccall(:jl_dlsym_e, Ptr{Void}, (Ptr{Void}, Ptr{Uint8}), hnd, s) end @@ -25,10 +25,10 @@ end dlopen(s::Symbol, flags::Integer = RTLD_LAZY | RTLD_DEEPBIND) = dlopen(string(s), flags) -dlopen(s::String, flags::Integer = RTLD_LAZY | RTLD_DEEPBIND) = +dlopen(s::AbstractString, flags::Integer = RTLD_LAZY | RTLD_DEEPBIND) = ccall(:jl_load_dynamic_library, Ptr{Void}, (Ptr{Uint8},Uint32), s, flags) -dlopen_e(s::String, flags::Integer = RTLD_LAZY | RTLD_DEEPBIND) = +dlopen_e(s::AbstractString, flags::Integer = RTLD_LAZY | RTLD_DEEPBIND) = ccall(:jl_load_dynamic_library_e, Ptr{Void}, (Ptr{Uint8},Uint32), s, flags) dlopen_e(s::Symbol, flags::Integer = RTLD_LAZY | RTLD_DEEPBIND) = @@ -112,11 +112,11 @@ function find_library{T<:ByteString, S<:ByteString}(libnames::Array{T,1}, extrap return "" end -function ccallable(f::Function, rt::Type, argt::(Type...), name::Union(String,Symbol)=string(f)) +function ccallable(f::Function, rt::Type, argt::(Type...), name::Union(AbstractString,Symbol)=string(f)) ccall(:jl_extern_c, Void, (Any, Any, Any, Ptr{Uint8}), f, rt, argt, name) end -function ccallable(f::Function, argt::(Type...), name::Union(String,Symbol)=string(f)) +function ccallable(f::Function, argt::(Type...), name::Union(AbstractString,Symbol)=string(f)) ccall(:jl_extern_c, Void, (Any, Ptr{Void}, Any, Ptr{Uint8}), f, C_NULL, argt, name) end diff --git a/base/client.jl b/base/client.jl index 46c6f9f055694..8f8db5a6fc900 100644 --- a/base/client.jl +++ b/base/client.jl @@ -65,7 +65,7 @@ function repl_cmd(cmd) nothing end -function repl_hook(input::String) +function repl_hook(input::AbstractString) Expr(:call, :(Base.repl_cmd), macroexpand(Expr(:macrocall,symbol("@cmd"),input))) end @@ -129,7 +129,7 @@ end _repl_start = Condition() -function parse_input_line(s::String) +function parse_input_line(s::AbstractString) # s = bytestring(s) # (expr, pos) = parse(s, 1) # (ex, pos) = ccall(:jl_parse_string, Any, @@ -169,7 +169,7 @@ function incomplete_tag(ex::Expr) end # try to include() a file, ignoring if not found -try_include(path::String) = isfile(path) && include(path) +try_include(path::AbstractString) = isfile(path) && include(path) function init_bind_addr(args::Vector{UTF8String}) # Treat --bind-to in a position independent manner in ARGS since @@ -335,8 +335,8 @@ function load_juliarc() try_include(abspath(homedir(),".juliarc.jl")) end -function load_machine_file(path::String) - machines = String[] +function load_machine_file(path::AbstractString) + machines = AbstractString[] for line in split(readall(path),'\n'; keep=false) s = split(line,'*'; keep=false) if length(s) > 1 diff --git a/base/datafmt.jl b/base/datafmt.jl index ed5667067603a..83810cb62139e 100644 --- a/base/datafmt.jl +++ b/base/datafmt.jl @@ -12,7 +12,7 @@ const invalid_dlm = char(0xfffffffe) const offs_chunk_size = 5000 countlines(nameorfile) = countlines(nameorfile, '\n') -function countlines(filename::String, eol::Char) +function countlines(filename::AbstractString, eol::Char) open(filename) do io countlines(io, eol) end @@ -50,20 +50,20 @@ readdlm(input, dlm::Char, T::Type, eol::Char; opts...) = readdlm_auto(input, dlm function readdlm_auto(input, dlm::Char, T::Type, eol::Char, auto::Bool; opts...) optsd = val_opts(opts) use_mmap = get(optsd, :use_mmap, @windows ? false : true) - isa(input, String) && (fsz = filesize(input); input = use_mmap && (fsz > 0) && fsz < typemax(Int) ? as_mmap(input,fsz) : readall(input)) + isa(input, AbstractString) && (fsz = filesize(input); input = use_mmap && (fsz > 0) && fsz < typemax(Int) ? as_mmap(input,fsz) : readall(input)) sinp = isa(input, Vector{Uint8}) ? bytestring(input) : isa(input, IO) ? readall(input) : input readdlm_string(sinp, dlm, T, eol, auto, optsd) end -function as_mmap(fname::String, fsz::Int64) +function as_mmap(fname::AbstractString, fsz::Int64) open(fname) do io mmap_array(Uint8, (int(fsz),), io) end end -function ascii_if_possible(sbuff::String) +function ascii_if_possible(sbuff::AbstractString) isascii(sbuff) ? convert(ASCIIString,sbuff) : sbuff end @@ -81,7 +81,7 @@ type DLMOffsets <: DLMHandler thresh::Int bufflen::Int - function DLMOffsets(sbuff::String) + function DLMOffsets(sbuff::AbstractString) offsets = Array(Array{Int,1}, 1) offsets[1] = Array(Int, offs_chunk_size) thresh = int(Base.Sys.total_memory() / sizeof(Int) / 5) @@ -125,8 +125,8 @@ function result(dlmoffsets::DLMOffsets) dlmoffsets.oarr end -type DLMStore{T,S<:String} <: DLMHandler - hdr::Array{String, 2} +type DLMStore{T,S<:AbstractString} <: DLMHandler + hdr::Array{AbstractString, 2} data::Array{T, 2} nrows::Int @@ -140,7 +140,7 @@ type DLMStore{T,S<:String} <: DLMHandler tmp64::Array{Float64,1} end -function DLMStore{T,S<:String}(::Type{T}, dims::NTuple{2,Integer}, has_header::Bool, sbuff::S, auto::Bool, eol::Char) +function DLMStore{T,S<:AbstractString}(::Type{T}, dims::NTuple{2,Integer}, has_header::Bool, sbuff::S, auto::Bool, eol::Char) (nrows,ncols) = dims ((nrows == 0) || (ncols == 0)) && error("Empty input") ((nrows < 0) || (ncols < 0)) && error("Invalid dimensions") @@ -148,7 +148,7 @@ function DLMStore{T,S<:String}(::Type{T}, dims::NTuple{2,Integer}, has_header::B DLMStore{T,S}(fill(SubString(sbuff,1,0), 1, ncols), Array(T, nrows-hdr_offset, ncols), nrows, ncols, 0, 0, hdr_offset, sbuff, auto, eol, Array(Float64,1)) end -function store_cell{T,S<:String}(dlmstore::DLMStore{T,S}, row::Int, col::Int, quoted::Bool, startpos::Int, endpos::Int) +function store_cell{T,S<:AbstractString}(dlmstore::DLMStore{T,S}, row::Int, col::Int, quoted::Bool, startpos::Int, endpos::Int) drow = row - dlmstore.hdr_offset ncols = dlmstore.ncols @@ -170,7 +170,7 @@ function store_cell{T,S<:String}(dlmstore::DLMStore{T,S}, row::Int, col::Int, qu lastrow += 1 end for cidx in (lastcol+1):ncols - if (T <: String) || (T == Any) + if (T <: AbstractString) || (T == Any) cells[lastrow,cidx] = SubString(sbuff, 1, 0) elseif ((T <: Number) || (T <: Char)) && dlmstore.auto throw(TypeError(:store_cell, "", Any, T)) @@ -213,7 +213,7 @@ function result{T}(dlmstore::DLMStore{T}) while lastrow <= nrows (lastcol == ncols) && (lastcol = 0; lastrow += 1) for cidx in (lastcol+1):ncols - if (T <: String) || (T == Any) + if (T <: AbstractString) || (T == Any) cells[lastrow,cidx] = SubString(sbuff, 1, 0) elseif ((T <: Number) || (T <: Char)) && dlmstore.auto throw(TypeError(:store_cell, "", Any, T)) @@ -231,7 +231,7 @@ function result{T}(dlmstore::DLMStore{T}) end -function readdlm_string(sbuff::String, dlm::Char, T::Type, eol::Char, auto::Bool, optsd::Dict) +function readdlm_string(sbuff::AbstractString, dlm::Char, T::Type, eol::Char, auto::Bool, optsd::Dict) ign_empty = (dlm == invalid_dlm) quotes = get(optsd, :quotes, true) comments = get(optsd, :comments, true) @@ -288,7 +288,7 @@ function val_opts(opts) d end -function dlm_fill(T::DataType, offarr::Vector{Vector{Int}}, dims::NTuple{2,Integer}, has_header::Bool, sbuff::String, auto::Bool, eol::Char) +function dlm_fill(T::DataType, offarr::Vector{Vector{Int}}, dims::NTuple{2,Integer}, has_header::Bool, sbuff::AbstractString, auto::Bool, eol::Char) idx = 1 offidx = 1 offsets = offarr[1] @@ -313,12 +313,12 @@ function dlm_fill(T::DataType, offarr::Vector{Vector{Int}}, dims::NTuple{2,Integ end -colval{T<:Bool, S<:String}(sval::S, cells::Array{T,2}, row::Int, col::Int, tmp64::Array{Float64,1}) = ((sval=="true") && (cells[row,col]=true; return false); (sval=="false") && (cells[row,col]=false; return false); true) -colval{T<:Number, S<:String}(sval::S, cells::Array{T,2}, row::Int, col::Int, tmp64::Array{Float64,1}) = (float64_isvalid(sval, tmp64) ? ((cells[row,col] = tmp64[1]); false) : true) -colval{T<:String, S<:String}(sval::S, cells::Array{T,2}, row::Int, col::Int, tmp64::Array{Float64,1}) = ((cells[row,col] = sval); false) -colval{S<:String}(sval::S, cells::Array{Any,2}, row::Int, col::Int, tmp64::Array{Float64,1}) = ((cells[row,col] = float64_isvalid(sval, tmp64) ? tmp64[1] : sval); false) -colval{T<:Char, S<:String}(sval::S, cells::Array{T,2}, row::Int, col::Int, tmp64::Array{Float64,1}) = ((length(sval) == 1) ? ((cells[row,col] = next(sval,1)[1]); false) : true) -colval{S<:String}(sval::S, cells::Array, row::Int, col::Int, tmp64::Array{Float64,1}) = true +colval{T<:Bool, S<:AbstractString}(sval::S, cells::Array{T,2}, row::Int, col::Int, tmp64::Array{Float64,1}) = ((sval=="true") && (cells[row,col]=true; return false); (sval=="false") && (cells[row,col]=false; return false); true) +colval{T<:Number, S<:AbstractString}(sval::S, cells::Array{T,2}, row::Int, col::Int, tmp64::Array{Float64,1}) = (float64_isvalid(sval, tmp64) ? ((cells[row,col] = tmp64[1]); false) : true) +colval{T<:AbstractString, S<:AbstractString}(sval::S, cells::Array{T,2}, row::Int, col::Int, tmp64::Array{Float64,1}) = ((cells[row,col] = sval); false) +colval{S<:AbstractString}(sval::S, cells::Array{Any,2}, row::Int, col::Int, tmp64::Array{Float64,1}) = ((cells[row,col] = float64_isvalid(sval, tmp64) ? tmp64[1] : sval); false) +colval{T<:Char, S<:AbstractString}(sval::S, cells::Array{T,2}, row::Int, col::Int, tmp64::Array{Float64,1}) = ((length(sval) == 1) ? ((cells[row,col] = next(sval,1)[1]); false) : true) +colval{S<:AbstractString}(sval::S, cells::Array, row::Int, col::Int, tmp64::Array{Float64,1}) = true dlm_parse(s::ASCIIString, eol::Char, dlm::Char, qchar::Char, cchar::Char, ign_adj_dlm::Bool, allow_quote::Bool, allow_comments::Bool, skipstart::Int, skipblanks::Bool, dh::DLMHandler) = begin dlm_parse(s.data, uint8(uint32(eol)), uint8(uint32(dlm)), uint8(uint32(qchar)), uint8(uint32(cchar)), @@ -487,7 +487,7 @@ readcsv(io, T::Type; opts...) = readdlm(io, ',', T; opts...) # todo: keyword argument for # of digits to print writedlm_cell(io::IO, elt::FloatingPoint, dlm, quotes) = print_shortest(io, elt) -function writedlm_cell{T}(io::IO, elt::String, dlm::T, quotes::Bool) +function writedlm_cell{T}(io::IO, elt::AbstractString, dlm::T, quotes::Bool) if quotes && !isempty(elt) && (('"' in elt) || ('\n' in elt) || ((T <: Char) ? (dlm in elt) : contains(elt, dlm))) print(io, '"', replace(elt, r"\"", "\"\""), '"') else @@ -544,7 +544,7 @@ function writedlm(io::IO, itr, dlm; opts...) nothing end -function writedlm(fname::String, a, dlm; opts...) +function writedlm(fname::AbstractString, a, dlm; opts...) open(fname, "w") do io writedlm(io, a, dlm; opts...) end diff --git a/base/dates/accessors.jl b/base/dates/accessors.jl index 495d2bb5b820f..3f9916487d0bc 100644 --- a/base/dates/accessors.jl +++ b/base/dates/accessors.jl @@ -68,4 +68,4 @@ yearmonthday(dt::TimeType) = yearmonthday(days(dt)) @vectorize_1arg TimeType dayofmonth @vectorize_1arg TimeType yearmonth @vectorize_1arg TimeType monthday -@vectorize_1arg TimeType yearmonthday \ No newline at end of file +@vectorize_1arg TimeType yearmonthday diff --git a/base/dates/adjusters.jl b/base/dates/adjusters.jl index c2ebcd9955867..304c6b7bde945 100644 --- a/base/dates/adjusters.jl +++ b/base/dates/adjusters.jl @@ -154,4 +154,4 @@ function recur{T<:TimeType}(fun::Function,start::T,stop::T;step::Period=Day(1),n end function recur{T<:TimeType}(fun::Function,dr::StepRange{T};negate::Bool=false,limit::Int=10000) return recur(fun,first(dr),last(dr);step=step(dr),negate=negate,limit=limit) -end \ No newline at end of file +end diff --git a/base/dates/arithmetic.jl b/base/dates/arithmetic.jl index 9cac50aad9cc7..aff3131f098fa 100644 --- a/base/dates/arithmetic.jl +++ b/base/dates/arithmetic.jl @@ -73,4 +73,4 @@ end (.+){T<:TimeType}(x::AbstractArray{T}, y::Period) = reshape(T[i + y for i in x], size(x)) (.-){T<:TimeType}(x::AbstractArray{T}, y::Period) = reshape(T[i - y for i in x], size(x)) (.+){T<:TimeType}(y::Period, x::AbstractArray{T}) = x .+ y -(.-){T<:TimeType}(y::Period, x::AbstractArray{T}) = x .- y \ No newline at end of file +(.-){T<:TimeType}(y::Period, x::AbstractArray{T}) = x .- y diff --git a/base/dates/conversions.jl b/base/dates/conversions.jl index 87f164f53e441..87dfc3f5d7731 100644 --- a/base/dates/conversions.jl +++ b/base/dates/conversions.jl @@ -41,4 +41,4 @@ datetime2julian(dt::DateTime) = (value(dt) - JULIANEPOCH)/86400000.0 @vectorize_1arg Real rata2datetime @vectorize_1arg DateTime datetime2rata @vectorize_1arg Real julian2datetime -@vectorize_1arg DateTime datetime2julian \ No newline at end of file +@vectorize_1arg DateTime datetime2julian diff --git a/base/dates/io.jl b/base/dates/io.jl index 3b82e505470b2..fc432c89bb561 100644 --- a/base/dates/io.jl +++ b/base/dates/io.jl @@ -39,7 +39,7 @@ immutable DelimitedSlot{P<:AbstractTime} <: Slot{P} period::Type{P} width::Int option::Int - locale::String + locale::AbstractString end immutable FixedWidthSlot{P<:AbstractTime} <: Slot{P} @@ -47,7 +47,7 @@ immutable FixedWidthSlot{P<:AbstractTime} <: Slot{P} period::Type{P} width::Int option::Int - locale::String + locale::AbstractString end immutable DateFormat @@ -60,7 +60,7 @@ immutable DayOfWeekSlot <: AbstractTime end duplicates(slots) = any(map(x->count(y->x.period==y.period,slots),slots) .> 1) -function DateFormat(f::String,locale::String="english") +function DateFormat(f::AbstractString,locale::AbstractString="english") slots = Slot[] trans = [] begtran = match(r"^.*?(?=[ymuUdHMSsEe])",f).match @@ -109,7 +109,7 @@ function getslot(x,slot::DelimitedSlot,df,cursor) end getslot(x,slot,df,cursor) = (cursor+slot.width, slotparse(slot,x[cursor:(cursor+slot.width-1)])) -function parse(x::String,df::DateFormat) +function parse(x::AbstractString,df::DateFormat) x = strip(replace(x, r"#.*$", "")) x = replace(x,df.begtran,"") isempty(x) && throw(ArgumentError("Cannot parse empty format string")) @@ -158,25 +158,25 @@ const ISODateTimeFormat = DateFormat("yyyy-mm-ddTHH:MM:SS.s") const ISODateFormat = DateFormat("yyyy-mm-dd") const RFC1123Format = DateFormat("e, dd u yyyy HH:MM:SS") -DateTime(dt::String,format::String;locale::String="english") = DateTime(dt,DateFormat(format,locale)) -DateTime(dt::String,df::DateFormat=ISODateTimeFormat) = DateTime(parse(dt,df)...) +DateTime(dt::AbstractString,format::AbstractString;locale::AbstractString="english") = DateTime(dt,DateFormat(format,locale)) +DateTime(dt::AbstractString,df::DateFormat=ISODateTimeFormat) = DateTime(parse(dt,df)...) -Date(dt::String,format::String;locale::String="english") = Date(dt,DateFormat(format,locale)) -Date(dt::String,df::DateFormat=ISODateFormat) = Date(parse(dt,df)...) +Date(dt::AbstractString,format::AbstractString;locale::AbstractString="english") = Date(dt,DateFormat(format,locale)) +Date(dt::AbstractString,df::DateFormat=ISODateFormat) = Date(parse(dt,df)...) -format(dt::TimeType,f::String;locale::String="english") = format(dt,DateFormat(f,locale)) +format(dt::TimeType,f::AbstractString;locale::AbstractString="english") = format(dt,DateFormat(f,locale)) # vectorized -DateTime{T<:String}(y::AbstractArray{T},format::String;locale::String="english") = DateTime(y,DateFormat(format,locale)) -function DateTime{T<:String}(y::AbstractArray{T},df::DateFormat=ISODateTimeFormat) +DateTime{T<:AbstractString}(y::AbstractArray{T},format::AbstractString;locale::AbstractString="english") = DateTime(y,DateFormat(format,locale)) +function DateTime{T<:AbstractString}(y::AbstractArray{T},df::DateFormat=ISODateTimeFormat) return reshape(DateTime[DateTime(parse(y[i],df)...) for i in 1:length(y)], size(y)) end -Date{T<:String}(y::AbstractArray{T},format::String;locale::String="english") = Date(y,DateFormat(format,locale)) -function Date{T<:String}(y::AbstractArray{T},df::DateFormat=ISODateFormat) +Date{T<:AbstractString}(y::AbstractArray{T},format::AbstractString;locale::AbstractString="english") = Date(y,DateFormat(format,locale)) +function Date{T<:AbstractString}(y::AbstractArray{T},df::DateFormat=ISODateFormat) return reshape(Date[Date(parse(y[i],df)...) for i in 1:length(y)], size(y)) end -format{T<:TimeType}(y::AbstractArray{T},format::String;locale::String="english") = Dates.format(y,DateFormat(format,locale)) +format{T<:TimeType}(y::AbstractArray{T},format::AbstractString;locale::AbstractString="english") = Dates.format(y,DateFormat(format,locale)) function format(y::AbstractArray{Date},df::DateFormat=ISODateFormat) return reshape([Dates.format(y[i],df) for i in 1:length(y)], size(y)) end diff --git a/base/dates/periods.jl b/base/dates/periods.jl index 72a689c4e1224..dbf3b393913b6 100644 --- a/base/dates/periods.jl +++ b/base/dates/periods.jl @@ -13,8 +13,8 @@ for p in (:Year,:Month,:Week,:Day,:Hour,:Minute,:Second,:Millisecond) @eval _units(x::$p) = " " * lowercase(string($p)) * (abs(value(x)) == 1 ? "" : "s") # periodisless @eval periodisless(x::$p,y::$p) = value(x) < value(y) - # String parsing (mainly for IO code) - @eval $p(x::String) = $p(parseint(Int64,x)) + # AbstractString parsing (mainly for IO code) + @eval $p(x::AbstractString) = $p(parseint(Int64,x)) # Period accessors @eval $p(x::TimeType) = $p($(symbol(lowercase(string(p))))(x)) end @@ -148,4 +148,4 @@ days(c::Week) = 7*value(c) days(c::Year) = 365.2425*value(c) days(c::Month) = 30.436875*value(c) -Day{T<:FixedPeriod}(c::T) = Day(days(c)) \ No newline at end of file +Day{T<:FixedPeriod}(c::T) = Day(days(c)) diff --git a/base/dates/query.jl b/base/dates/query.jl index 86c23128a7321..c2d2afe1826ec 100644 --- a/base/dates/query.jl +++ b/base/dates/query.jl @@ -23,10 +23,10 @@ const VALUETODAYOFWEEK = Dict{UTF8String,Dict{Int,UTF8String}}("english"=>englis const english_daysofweekabbr = Dict(1=>"Mon",2=>"Tue",3=>"Wed", 4=>"Thu",5=>"Fri",6=>"Sat",7=>"Sun") const VALUETODAYOFWEEKABBR = Dict{UTF8String,Dict{Int,UTF8String}}("english"=>english_daysofweekabbr) -dayname(dt::Integer;locale::String="english") = VALUETODAYOFWEEK[locale][dt] -dayabbr(dt::Integer;locale::String="english") = VALUETODAYOFWEEKABBR[locale][dt] -dayname(dt::TimeType;locale::String="english") = VALUETODAYOFWEEK[locale][dayofweek(dt)] -dayabbr(dt::TimeType;locale::String="english") = VALUETODAYOFWEEKABBR[locale][dayofweek(dt)] +dayname(dt::Integer;locale::AbstractString="english") = VALUETODAYOFWEEK[locale][dt] +dayabbr(dt::Integer;locale::AbstractString="english") = VALUETODAYOFWEEKABBR[locale][dt] +dayname(dt::TimeType;locale::AbstractString="english") = VALUETODAYOFWEEK[locale][dayofweek(dt)] +dayabbr(dt::TimeType;locale::AbstractString="english") = VALUETODAYOFWEEKABBR[locale][dayofweek(dt)] # Convenience methods for each day ismonday(dt::TimeType) = dayofweek(dt) == Mon @@ -72,10 +72,10 @@ const englishabbr_months = Dict(1=>"Jan",2=>"Feb",3=>"Mar",4=>"Apr", 5=>"May",6=>"Jun",7=>"Jul",8=>"Aug",9=>"Sep", 10=>"Oct",11=>"Nov",12=>"Dec") const VALUETOMONTHABBR = Dict{UTF8String,Dict{Int,UTF8String}}("english"=>englishabbr_months) -monthname(dt::Integer;locale::String="english") = VALUETOMONTH[locale][dt] -monthabbr(dt::Integer;locale::String="english") = VALUETOMONTHABBR[locale][dt] -monthname(dt::TimeType;locale::String="english") = VALUETOMONTH[locale][month(dt)] -monthabbr(dt::TimeType;locale::String="english") = VALUETOMONTHABBR[locale][month(dt)] +monthname(dt::Integer;locale::AbstractString="english") = VALUETOMONTH[locale][dt] +monthabbr(dt::Integer;locale::AbstractString="english") = VALUETOMONTHABBR[locale][dt] +monthname(dt::TimeType;locale::AbstractString="english") = VALUETOMONTH[locale][month(dt)] +monthabbr(dt::TimeType;locale::AbstractString="english") = VALUETOMONTHABBR[locale][month(dt)] daysinmonth(dt::TimeType) = ((y,m) = yearmonth(dt); return daysinmonth(y,m)) @@ -103,4 +103,4 @@ const QUARTERDAYS = [0,90,181,273] dayofquarter(dt::TimeType) = dayofyear(dt) - QUARTERDAYS[quarterofyear(dt)] @vectorize_1arg TimeType quarterofyear -@vectorize_1arg TimeType dayofquarter \ No newline at end of file +@vectorize_1arg TimeType dayofquarter diff --git a/base/dates/ranges.jl b/base/dates/ranges.jl index 932c1c3f5d86b..144c3552567bf 100644 --- a/base/dates/ranges.jl +++ b/base/dates/ranges.jl @@ -30,4 +30,4 @@ end Base.start{T<:TimeType}(r::StepRange{T}) = 0 Base.next{T<:TimeType}(r::StepRange{T}, i) = (r.start+r.step*i,i+1) -Base.done{T<:TimeType,S<:Period}(r::StepRange{T,S}, i::Integer) = length(r) <= i \ No newline at end of file +Base.done{T<:TimeType,S<:Period}(r::StepRange{T,S}, i::Integer) = length(r) <= i diff --git a/base/deprecated.jl b/base/deprecated.jl index c0e47b6d54adb..c87fd57019261 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -78,7 +78,7 @@ const Stat = StatStruct export CharString const CharString = UTF32String @deprecate UTF32String(c::Integer...) utf32(c...) -@deprecate UTF32String(s::String) utf32(s) +@deprecate UTF32String(s::AbstractString) utf32(s) export Ranges const Ranges = Range @@ -178,7 +178,7 @@ const UdpSocket = UDPSocket const IpAddr = IPAddr @deprecate isblank(c::Char) c == ' ' || c == '\t' -@deprecate isblank(s::String) all(c -> c == ' ' || c == '\t', s) +@deprecate isblank(s::AbstractString) all(c -> c == ' ' || c == '\t', s) @deprecate randbool! rand! @@ -212,3 +212,5 @@ end @deprecate nan(x::FloatingPoint) oftype(x,NaN) @deprecate inf{T<:FloatingPoint}(::Type{T}) convert(T,Inf) @deprecate nan{T<:FloatingPoint}(::Type{T}) convert(T,NaN) + +const String = AbstractString diff --git a/base/dict.jl b/base/dict.jl index 892112b804de4..81be2f3ab9c64 100644 --- a/base/dict.jl +++ b/base/dict.jl @@ -76,7 +76,7 @@ function showdict{K,V}(io::IO, t::Associative{K,V}; limit::Bool = false, rows -= 2 # Subtract the summary and final ⋮ continuation lines # determine max key width to align the output, caching the strings - ks = Array(String, min(rows, length(t))) + ks = Array(AbstractString, min(rows, length(t))) keylen = 0 for (i, k) in enumerate(keys(t)) i > rows && break diff --git a/base/env.jl b/base/env.jl index 076fc623e2bcc..90e5412556883 100644 --- a/base/env.jl +++ b/base/env.jl @@ -1,8 +1,8 @@ ## core libc calls ## @unix_only begin - _getenv(var::String) = ccall(:getenv, Ptr{Uint8}, (Ptr{Uint8},), var) - _hasenv(s::String) = _getenv(s) != C_NULL + _getenv(var::AbstractString) = ccall(:getenv, Ptr{Uint8}, (Ptr{Uint8},), var) + _hasenv(s::AbstractString) = _getenv(s) != C_NULL end @windows_only begin const ERROR_ENVVAR_NOT_FOUND = uint32(203) @@ -28,7 +28,7 @@ end _getenvlen(var::UTF16String) = ccall(:GetEnvironmentVariableW,stdcall,Uint32,(Ptr{Uint16},Ptr{Uint8},Uint32),utf16(var),C_NULL,0) _hasenv(s::UTF16String) = _getenvlen(s)!=0 || GetLastError()!=ERROR_ENVVAR_NOT_FOUND -_hasenv(s::String) = _hasenv(utf16(s)) +_hasenv(s::AbstractString) = _hasenv(utf16(s)) function _jl_win_getenv(s::UTF16String,len::Uint32) val=zeros(Uint16,len) ret=ccall(:GetEnvironmentVariableW,stdcall,Uint32,(Ptr{Uint16},Ptr{Uint16},Uint32),s,val,len) @@ -62,7 +62,7 @@ macro accessEnv(var,errorcase) end end -function _setenv(var::String, val::String, overwrite::Bool) +function _setenv(var::AbstractString, val::AbstractString, overwrite::Bool) @unix_only begin ret = ccall(:setenv, Int32, (Ptr{Uint8},Ptr{Uint8},Int32), var, val, overwrite) systemerror(:setenv, ret != 0) @@ -76,9 +76,9 @@ function _setenv(var::String, val::String, overwrite::Bool) end end -_setenv(var::String, val::String) = _setenv(var, val, true) +_setenv(var::AbstractString, val::AbstractString) = _setenv(var, val, true) -function _unsetenv(var::String) +function _unsetenv(var::AbstractString) @unix_only begin ret = ccall(:unsetenv, Int32, (Ptr{Uint8},), var) systemerror(:unsetenv, ret != 0) @@ -96,12 +96,12 @@ const ENV = EnvHash() similar(::EnvHash) = Dict{ByteString,ByteString}() -getindex(::EnvHash, k::String) = @accessEnv k throw(KeyError(k)) -get(::EnvHash, k::String, def) = @accessEnv k (return def) -in(k::String, ::KeyIterator{EnvHash}) = _hasenv(k) -pop!(::EnvHash, k::String) = (v = ENV[k]; _unsetenv(k); v) -pop!(::EnvHash, k::String, def) = haskey(ENV,k) ? pop!(ENV,k) : def -function delete!(::EnvHash, k::String) +getindex(::EnvHash, k::AbstractString) = @accessEnv k throw(KeyError(k)) +get(::EnvHash, k::AbstractString, def) = @accessEnv k (return def) +in(k::AbstractString, ::KeyIterator{EnvHash}) = _hasenv(k) +pop!(::EnvHash, k::AbstractString) = (v = ENV[k]; _unsetenv(k); v) +pop!(::EnvHash, k::AbstractString, def) = haskey(ENV,k) ? pop!(ENV,k) : def +function delete!(::EnvHash, k::AbstractString) warn_once(""" delete!(ENV,key) now returns the modified environment. Use pop!(ENV,key) to retrieve the value instead. @@ -109,9 +109,9 @@ function delete!(::EnvHash, k::String) _unsetenv(k) ENV end -delete!(::EnvHash, k::String, def) = haskey(ENV,k) ? delete!(ENV,k) : def -setindex!(::EnvHash, v, k::String) = _setenv(k,string(v)) -push!(::EnvHash, k::String, v) = setindex!(ENV, v, k) +delete!(::EnvHash, k::AbstractString, def) = haskey(ENV,k) ? delete!(ENV,k) : def +setindex!(::EnvHash, v, k::AbstractString) = _setenv(k,string(v)) +push!(::EnvHash, k::AbstractString, v) = setindex!(ENV, v, k) @unix_only begin start(::EnvHash) = 0 @@ -171,7 +171,7 @@ function show(io::IO, ::EnvHash) end # temporarily set and then restore an environment value -function with_env(f::Function, key::String, val) +function with_env(f::Function, key::AbstractString, val) old = get(ENV,key,nothing) val != nothing ? (ENV[key]=val) : _unsetenv(key) try f() diff --git a/base/error.jl b/base/error.jl index 8f502e03b68ca..ed863673ce03b 100644 --- a/base/error.jl +++ b/base/error.jl @@ -18,7 +18,7 @@ error(e::Exception) = throw(e) error{E<:Exception}(::Type{E}) = throw(E()) -error(s::String) = throw(ErrorException(s)) +error(s::AbstractString) = throw(ErrorException(s)) error(s...) = throw(ErrorException(string(s...))) macro unexpected() diff --git a/base/fftw.jl b/base/fftw.jl index 2512c5cc255c9..e21076791bd8d 100644 --- a/base/fftw.jl +++ b/base/fftw.jl @@ -70,7 +70,7 @@ typealias fftwTypeSingle Union(Type{Float32},Type{Complex64}) # around FFTW's internal file i/o buffering [see the BUFSZ constant in # FFTW's api/import-wisdom-from-file.c file]. -function export_wisdom(fname::String) +function export_wisdom(fname::AbstractString) f = ccall(:fopen, Ptr{Void}, (Ptr{Uint8},Ptr{Uint8}), fname, "w") systemerror("could not open wisdom file $fname for writing", f == C_NULL) ccall((:fftw_export_wisdom_to_file,libfftw), Void, (Ptr{Void},), f) @@ -79,7 +79,7 @@ function export_wisdom(fname::String) ccall(:fclose, Void, (Ptr{Void},), f) end -function import_wisdom(fname::String) +function import_wisdom(fname::AbstractString) f = ccall(:fopen, Ptr{Void}, (Ptr{Uint8},Ptr{Uint8}), fname, "r") systemerror("could not open wisdom file $fname for reading", f == C_NULL) if ccall((:fftw_import_wisdom_from_file,libfftw),Int32,(Ptr{Void},),f)==0|| diff --git a/base/file.jl b/base/file.jl index c28897e43a9a2..1da8ed93f5bea 100644 --- a/base/file.jl +++ b/base/file.jl @@ -7,12 +7,12 @@ function pwd() bytestring(b[1:len[1]-1]) end -function cd(dir::String) +function cd(dir::AbstractString) uv_error("chdir $dir", ccall(:uv_chdir, Cint, (Ptr{Uint8},), dir)) end cd() = cd(homedir()) -@unix_only function cd(f::Function, dir::String, args...) +@unix_only function cd(f::Function, dir::AbstractString, args...) fd = ccall(:open,Int32,(Ptr{Uint8},Int32),".",0) systemerror(:open, fd == -1) try @@ -23,7 +23,7 @@ cd() = cd(homedir()) systemerror(:close, ccall(:close,Int32,(Int32,),fd) != 0) end end -@windows_only function cd(f::Function, dir::String, args...) +@windows_only function cd(f::Function, dir::AbstractString, args...) old = pwd() try cd(dir) @@ -34,13 +34,13 @@ end end cd(f::Function) = cd(f, homedir()) -function mkdir(path::String, mode::Unsigned=0o777) +function mkdir(path::AbstractString, mode::Unsigned=0o777) @unix_only ret = ccall(:mkdir, Int32, (Ptr{Uint8},Uint32), path, mode) @windows_only ret = ccall(:_wmkdir, Int32, (Ptr{Uint16},), utf16(path)) systemerror(:mkdir, ret != 0) end -function mkpath(path::String, mode::Unsigned=0o777) +function mkpath(path::AbstractString, mode::Unsigned=0o777) isdirpath(path) && (path = dirname(path)) dir = dirname(path) (path == dir || isdir(path)) && return @@ -48,10 +48,10 @@ function mkpath(path::String, mode::Unsigned=0o777) mkdir(path, mode) end -mkdir(path::String, mode::Signed) = error("mode must be an unsigned integer; try 0o$mode") -mkpath(path::String, mode::Signed) = error("mode must be an unsigned integer; try 0o$mode") +mkdir(path::AbstractString, mode::Signed) = error("mode must be an unsigned integer; try 0o$mode") +mkpath(path::AbstractString, mode::Signed) = error("mode must be an unsigned integer; try 0o$mode") -function rm(path::String; recursive::Bool=false) +function rm(path::AbstractString; recursive::Bool=false) if islink(path) || !isdir(path) @windows_only if !iswritable(path); chmod(path, 0o777); end FS.unlink(path) @@ -70,10 +70,10 @@ end # The following use Unix command line facilites -cp(src::String, dst::String) = FS.sendfile(src, dst) -mv(src::String, dst::String) = FS.rename(src, dst) +cp(src::AbstractString, dst::AbstractString) = FS.sendfile(src, dst) +mv(src::AbstractString, dst::AbstractString) = FS.rename(src, dst) -function touch(path::String) +function touch(path::AbstractString) f = FS.open(path,JL_O_WRONLY | JL_O_CREAT, 0o0666) @assert f.handle >= 0 try @@ -115,7 +115,7 @@ function tempdir() return utf8(UTF16String(temppath)) end tempname(uunique::Uint32=uint32(0)) = tempname(tempdir(), uunique) -function tempname(temppath::String,uunique::Uint32) +function tempname(temppath::AbstractString,uunique::Uint32) tname = Array(Uint16,32767) uunique = ccall(:GetTempFileNameW,stdcall,Uint32,(Ptr{Uint16},Ptr{Uint16},Uint32,Ptr{Uint16}), utf16(temppath),utf16("jul"),uunique,tname) @@ -156,7 +156,7 @@ end end end -function readdir(path::String) +function readdir(path::AbstractString) # Allocate space for uv_fs_t struct uv_readdir_req = zeros(Uint8, ccall(:jl_sizeof_uv_fs_t, Int32, ())) diff --git a/base/floatfuncs.jl b/base/floatfuncs.jl index 06cedbac362c6..fe64c14707d6c 100644 --- a/base/floatfuncs.jl +++ b/base/floatfuncs.jl @@ -28,7 +28,7 @@ num2hex(x::Float16) = hex(reinterpret(Uint16,x), 4) num2hex(x::Float32) = hex(box(Uint32,unbox(Float32,x)),8) num2hex(x::Float64) = hex(box(Uint64,unbox(Float64,x)),16) -function hex2num(s::String) +function hex2num(s::AbstractString) if length(s) <= 8 return box(Float32,unbox(Int32,parseint(Int32,s,16))) end diff --git a/base/fs.jl b/base/fs.jl index 3020e7f9c00f5..12712beeba684 100644 --- a/base/fs.jl +++ b/base/fs.jl @@ -49,15 +49,15 @@ include("file_constants.jl") abstract AbstractFile <: IO type File <: AbstractFile - path::String + path::AbstractString open::Bool handle::Int32 - File(path::String) = new(path,false,-1) + File(path::AbstractString) = new(path,false,-1) File(fd::RawFD) = new("",true,fd.fd) end type AsyncFile <: AbstractFile - path::String + path::AbstractString open::Bool end @@ -79,8 +79,8 @@ function open(f::File,flags::Integer,mode::Integer) f.open = true f end -open(f::String,flags,mode) = open(File(f),flags,mode) -open(f::String,flags) = open(f,flags,0) +open(f::AbstractString,flags,mode) = open(File(f),flags,mode) +open(f::AbstractString,flags) = open(f,flags,0) function close(f::File) if !f.open @@ -93,7 +93,7 @@ function close(f::File) f end -function unlink(p::String) +function unlink(p::AbstractString) err = ccall(:jl_fs_unlink, Int32, (Ptr{Uint8},), p) uv_error("unlink",err) end @@ -109,7 +109,7 @@ function unlink(f::File) end # For move command -function rename(src::String, dst::String) +function rename(src::AbstractString, dst::AbstractString) err = ccall(:jl_fs_rename, Int32, (Ptr{Uint8}, Ptr{Uint8}), src, dst) # on error, default to cp && rm @@ -124,7 +124,7 @@ function rename(src::String, dst::String) end # For copy command -function sendfile(src::String, dst::String) +function sendfile(src::AbstractString, dst::AbstractString) src_file = open(src, JL_O_RDONLY) if !src_file.open error("Src file is not open") @@ -150,7 +150,7 @@ function sendfile(src::String, dst::String) end @windows_only const UV_FS_SYMLINK_JUNCTION = 0x0002 -@non_windowsxp_only function symlink(p::String, np::String) +@non_windowsxp_only function symlink(p::AbstractString, np::AbstractString) flags = 0 @windows_only if isdir(p); flags |= UV_FS_SYMLINK_JUNCTION; p = abspath(p); end err = ccall(:jl_fs_symlink, Int32, (Ptr{Uint8}, Ptr{Uint8}, Cint), p, np, flags) @@ -159,10 +159,10 @@ end end uv_error("symlink",err) end -@windowsxp_only symlink(p::String, np::String) = +@windowsxp_only symlink(p::AbstractString, np::AbstractString) = error("WindowsXP does not support soft symlinks") -function chmod(p::String, mode::Integer) +function chmod(p::AbstractString, mode::Integer) err = ccall(:jl_fs_chmod, Int32, (Ptr{Uint8}, Cint), p, mode) uv_error("chmod",err) end diff --git a/base/gmp.jl b/base/gmp.jl index 0a943f694950b..d60bec73229ae 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -48,9 +48,9 @@ widen(::Type{Uint128}) = BigInt widen(::Type{BigInt}) = BigInt BigInt(x::BigInt) = x -BigInt(s::String) = parseint(BigInt,s) +BigInt(s::AbstractString) = parseint(BigInt,s) -function Base.parseint_nocheck(::Type{BigInt}, s::String, base::Int) +function Base.parseint_nocheck(::Type{BigInt}, s::AbstractString, base::Int) s = bytestring(s) sgn, base, i = Base.parseint_preamble(true,s,base) z = BigInt() diff --git a/base/grisu/bignum.jl b/base/grisu/bignum.jl index bac0a036b3eb2..52cc6b8ae06bf 100644 --- a/base/grisu/bignum.jl +++ b/base/grisu/bignum.jl @@ -224,4 +224,4 @@ function fixupmultiply10(estimated_power,is_even,num,den,minus,plus) end end return num, den, minus, plus, decimal_point -end \ No newline at end of file +end diff --git a/base/grisu/fastprecision.jl b/base/grisu/fastprecision.jl index 63174cd6cf9eb..c8235b8355392 100644 --- a/base/grisu/fastprecision.jl +++ b/base/grisu/fastprecision.jl @@ -66,4 +66,4 @@ function fastprecision(v,requested_digits,buffer=Array(Uint8,100)) r, kappa, len = digitgen(scaled_w,buffer,requested_digits) decimal_exponent = -cp.de + kappa return r, len, decimal_exponent+len-1, buffer -end \ No newline at end of file +end diff --git a/base/grisu/fastshortest.jl b/base/grisu/fastshortest.jl index 9ec1b66eb05ae..e6d1151817de8 100644 --- a/base/grisu/fastshortest.jl +++ b/base/grisu/fastshortest.jl @@ -85,4 +85,4 @@ function fastshortest(v,buffer=Array(Uint8,17)) scaled_bound_plus,buffer) decimal_exponent = -cp.de + kappa return r, len, decimal_exponent+len-1, buffer -end \ No newline at end of file +end diff --git a/base/grisu/float.jl b/base/grisu/float.jl index f62e2073f334c..3f9673f4bf039 100644 --- a/base/grisu/float.jl +++ b/base/grisu/float.jl @@ -223,4 +223,4 @@ function binexp_cache(min_exponent,max_exponent) index = div(CachedPowersOffset+k-1,DecimalExponentDistance) + 1 cp = CachedPowers[index+1] return cp -end \ No newline at end of file +end diff --git a/base/help.jl b/base/help.jl index dec1824375049..164f63eb51b34 100644 --- a/base/help.jl +++ b/base/help.jl @@ -10,7 +10,7 @@ function clear_cache() global FUNCTION_DICT = nothing end -function decor_help_desc(func::String, mfunc::String, desc::String) +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) @@ -85,7 +85,7 @@ end func_expr_from_symbols(s::Vector{Symbol}) = length(s) == 1 ? s[1] : Expr(:., func_expr_from_symbols(s[1:end-1]), Expr(:quote, s[end])) -function help(io::IO, fname::String, obj=0) +function help(io::IO, fname::AbstractString, obj=0) init_help() found = false if haskey(FUNCTION_DICT, fname) @@ -140,8 +140,8 @@ end apropos() = help() -apropos(s::String) = apropos(STDOUT, s) -function apropos(io::IO, txt::String) +apropos(s::AbstractString) = apropos(STDOUT, s) +function apropos(io::IO, txt::AbstractString) init_help() n = 0 r = Regex("\\Q$txt", Base.PCRE.CASELESS) diff --git a/base/inference.jl b/base/inference.jl index e982cab827e10..6efc82af570ec 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -1677,7 +1677,7 @@ function eval_annotate(e::ANY, vtypes::ANY, sv::StaticVarInfo, decls, clo) i0 = is(head,:method) ? 2 : 1 for i=i0:length(e.args) subex = e.args[i] - if !(isa(subex,Number) || isa(subex,String)) + if !(isa(subex,Number) || isa(subex,AbstractString)) e.args[i] = eval_annotate(subex, vtypes, sv, decls, clo) end end @@ -1858,7 +1858,7 @@ function resolve_globals(e::ANY, locals, args, from, to, env1, env2) elseif !is(e.head,:line) for i=1:length(e.args) subex = e.args[i] - if !(isa(subex,Number) || isa(subex,String)) + if !(isa(subex,Number) || isa(subex,AbstractString)) e.args[i] = resolve_globals(subex, locals, args, from, to, env1, env2) end end @@ -1958,7 +1958,7 @@ end # and some affect-free calls (allow_volatile=false) -- affect_free means the call # cannot be affected by previous calls, except assignment nodes function effect_free(e::ANY, sv, allow_volatile::Bool) - if isa(e,Symbol) || isa(e,SymbolNode) || isa(e,Number) || isa(e,String) || + if isa(e,Symbol) || isa(e,SymbolNode) || isa(e,Number) || isa(e,AbstractString) || isa(e,TopNode) || isa(e,QuoteNode) || isa(e,Type) || isa(e,Tuple) return true end @@ -2963,7 +2963,7 @@ function tupleref_elim_pass(e::Expr, sv) end elseif isa(e1,Tuple) && (1 <= j <= length(e1)) e1j = e1[j] - if !(isa(e1j,Number) || isa(e1j,String) || isa(e1j,Tuple) || + if !(isa(e1j,Number) || isa(e1j,AbstractString) || isa(e1j,Tuple) || isa(e1j,Type)) e1j = QuoteNode(e1j) end @@ -3006,7 +3006,7 @@ function tuple_elim_pass(ast::Expr) n_ins = 0 for j=1:nv tupelt = tup[j+1] - if isa(tupelt,Number) || isa(tupelt,String) || isa(tupelt,QuoteNode) + if isa(tupelt,Number) || isa(tupelt,AbstractString) || isa(tupelt,QuoteNode) vals[j] = tupelt else elty = exprtype(tupelt) diff --git a/base/interactiveutil.jl b/base/interactiveutil.jl index 0836573fe521d..8d79d693af77f 100644 --- a/base/interactiveutil.jl +++ b/base/interactiveutil.jl @@ -1,6 +1,6 @@ # editing files -function edit(file::String, line::Integer) +function edit(file::AbstractString, line::Integer) if OS_NAME == :Windows || OS_NAME == :Darwin default_editor = "open" elseif isreadable("/etc/alternatives/editor") @@ -51,18 +51,18 @@ function edit( m::Method ) edit( string(file), line ) end -edit(file::String) = edit(file, 1) +edit(file::AbstractString) = edit(file, 1) edit(f::Callable) = edit(functionloc(f)...) edit(f::Callable, t::(Type...)) = edit(functionloc(f,t)...) # terminal pager -function less(file::String, line::Integer) +function less(file::AbstractString, line::Integer) pager = get(ENV, "PAGER", "less") run(`$pager +$(line)g $file`) end -less(file::String) = less(file, 1) +less(file::AbstractString) = less(file, 1) less(f::Callable) = less(functionloc(f)...) less(f::Callable, t::(Type...)) = less(functionloc(f,t)...) @@ -106,7 +106,7 @@ end end @windows_only begin # TODO: these functions leak memory and memory locks if they throw an error - function clipboard(x::String) + function clipboard(x::AbstractString) systemerror(:OpenClipboard, 0==ccall((:OpenClipboard, "user32"), stdcall, Cint, (Ptr{Void},), C_NULL)) systemerror(:EmptyClipboard, 0==ccall((:EmptyClipboard, "user32"), stdcall, Cint, ())) x_u16 = utf16(x) @@ -313,7 +313,7 @@ end # file downloading downloadcmd = nothing -@unix_only function download(url::String, filename::String) +@unix_only function download(url::AbstractString, filename::AbstractString) global downloadcmd if downloadcmd === nothing for checkcmd in (:curl, :wget, :fetch) @@ -335,7 +335,7 @@ downloadcmd = nothing filename end -@windows_only function download(url::String, filename::String) +@windows_only function download(url::AbstractString, filename::AbstractString) res = ccall((:URLDownloadToFileW,:urlmon),stdcall,Cuint, (Ptr{Void},Ptr{Uint16},Ptr{Uint16},Cint,Ptr{Void}),0,utf16(url),utf16(filename),0,0) if res != 0 @@ -344,7 +344,7 @@ end filename end -function download(url::String) +function download(url::AbstractString) filename = tempname() download(url, filename) end @@ -369,7 +369,7 @@ end # testing function runtests(tests = ["all"], numcores = iceil(CPU_CORES/2)) - if isa(tests,String) + if isa(tests,AbstractString) tests = split(tests) end ENV2 = copy(ENV) diff --git a/base/io.jl b/base/io.jl index a52f7416b4913..c6d9e684e0922 100644 --- a/base/io.jl +++ b/base/io.jl @@ -179,13 +179,13 @@ function readuntil{T}(s::IO, delim::T) end # based on code by Glen Hertz -function readuntil(s::IO, t::String) +function readuntil(s::IO, t::AbstractString) l = length(t) if l == 0 return "" end if l > 40 - warn("readuntil(IO,String) will perform poorly with a long string") + warn("readuntil(IO,AbstractString) will perform poorly with a long string") end out = IOBuffer() m = Array(Char, l) # last part of stream to match @@ -245,7 +245,7 @@ function readall(s::IO) b = readbytes(s) return is_valid_ascii(b) ? ASCIIString(b) : UTF8String(b) end -readall(filename::String) = open(readall, filename) +readall(filename::AbstractString) = open(readall, filename) ## high-level iterator interfaces ## diff --git a/base/iostream.jl b/base/iostream.jl index 9b1e6be4d7753..95d682b62992a 100644 --- a/base/iostream.jl +++ b/base/iostream.jl @@ -5,14 +5,14 @@ const sizeof_ios_t = int(ccall(:jl_sizeof_ios_t, Int32, ())) type IOStream <: IO handle::Ptr{Void} ios::Array{Uint8,1} - name::String + name::AbstractString mark::Int64 - IOStream(name::String, buf::Array{Uint8,1}) = new(pointer(buf), buf, name, -1) + IOStream(name::AbstractString, buf::Array{Uint8,1}) = new(pointer(buf), buf, name, -1) end # TODO: delay adding finalizer, e.g. for memio with a small buffer, or # in the case where we takebuf it. -function IOStream(name::String, finalize::Bool) +function IOStream(name::AbstractString, finalize::Bool) buf = zeros(Uint8,sizeof_ios_t) x = IOStream(name, buf) if finalize @@ -20,7 +20,7 @@ function IOStream(name::String, finalize::Bool) end return x end -IOStream(name::String) = IOStream(name, true) +IOStream(name::AbstractString) = IOStream(name, true) convert(T::Type{Ptr{Void}}, s::IOStream) = convert(T, s.ios) show(io::IO, s::IOStream) = print(io, "IOStream(", s.name, ")") @@ -100,7 +100,7 @@ position(h::CFILE) = ccall(:ftell, Clong, (Ptr{Void},), h.ptr) ## constructing and opening streams ## # "own" means the descriptor will be closed with the IOStream -function fdio(name::String, fd::Integer, own::Bool=false) +function fdio(name::AbstractString, fd::Integer, own::Bool=false) s = IOStream(name) ccall(:ios_fd, Ptr{Void}, (Ptr{Void}, Clong, Int32, Int32), s.ios, fd, 0, own); @@ -108,7 +108,7 @@ function fdio(name::String, fd::Integer, own::Bool=false) end fdio(fd::Integer, own::Bool=false) = fdio(string(""), fd, own) -function open(fname::String, rd::Bool, wr::Bool, cr::Bool, tr::Bool, ff::Bool) +function open(fname::AbstractString, rd::Bool, wr::Bool, cr::Bool, tr::Bool, ff::Bool) s = IOStream(string("")) systemerror("opening file $fname", ccall(:ios_file, Ptr{Void}, @@ -119,9 +119,9 @@ function open(fname::String, rd::Bool, wr::Bool, cr::Bool, tr::Bool, ff::Bool) end return s end -open(fname::String) = open(fname, true, false, false, false, false) +open(fname::AbstractString) = open(fname, true, false, false, false, false) -function open(fname::String, mode::String) +function open(fname::AbstractString, mode::AbstractString) mode == "r" ? open(fname, true , false, false, false, false) : mode == "r+" ? open(fname, true , true , false, false, false) : mode == "w" ? open(fname, false, true , true , true , false) : diff --git a/base/libc.jl b/base/libc.jl index ce297b87ec8a8..52d01d76125d4 100644 --- a/base/libc.jl +++ b/base/libc.jl @@ -34,8 +34,8 @@ type TmStruct end strftime(t) = strftime("%c", t) -strftime(fmt::String, t::Real) = strftime(fmt, TmStruct(t)) -function strftime(fmt::String, tm::TmStruct) +strftime(fmt::AbstractString, t::Real) = strftime(fmt, TmStruct(t)) +function strftime(fmt::AbstractString, tm::TmStruct) timestr = Array(Uint8, 128) n = ccall(:strftime, Int, (Ptr{Uint8}, Int, Ptr{Uint8}, Ptr{Void}), timestr, length(timestr), fmt, &tm) @@ -45,8 +45,8 @@ function strftime(fmt::String, tm::TmStruct) bytestring(convert(Ptr{Uint8},timestr)) end -strptime(timestr::String) = strptime("%c", timestr) -function strptime(fmt::String, timestr::String) +strptime(timestr::AbstractString) = strptime("%c", timestr) +function strptime(fmt::AbstractString, timestr::AbstractString) tm = TmStruct() r = ccall(:strptime, Ptr{Uint8}, (Ptr{Uint8}, Ptr{Uint8}, Ptr{Void}), timestr, fmt, &tm) diff --git a/base/linalg/arnoldi.jl b/base/linalg/arnoldi.jl index b45591816421c..41fd670423283 100644 --- a/base/linalg/arnoldi.jl +++ b/base/linalg/arnoldi.jl @@ -31,7 +31,7 @@ function eigs(A, B; bmat = isgeneral ? "G" : "I" isshift = sigma !== nothing - if isa(which,String) + if isa(which,AbstractString) warn("Use symbols instead of strings for specifying which eigenvalues to compute") which=symbol(which) end diff --git a/base/linalg/cholmod.jl b/base/linalg/cholmod.jl index 49d52d967d8f1..a941f7499e78d 100644 --- a/base/linalg/cholmod.jl +++ b/base/linalg/cholmod.jl @@ -463,7 +463,7 @@ function CholmodTriplet{Tv<:CHMVTypes,Ti<:CHMITypes}(tp::Ptr{c_CholmodTriplet{Tv ct end -function chm_rdsp(fnm::String) +function chm_rdsp(fnm::AbstractString) fd = ccall(:fopen, Ptr{Void}, (Ptr{Uint8},Ptr{Uint8}), fnm, "r") res = ccall((:cholmod_read_sparse,:libcholmod), Ptr{c_CholmodSparse{Float64,Cint}}, (Ptr{Void},Ptr{Uint8}),fd,cmn(Cint)) diff --git a/base/linalg/umfpack.jl b/base/linalg/umfpack.jl index 1a7e87fcdc29e..52ce5d7c54a51 100644 --- a/base/linalg/umfpack.jl +++ b/base/linalg/umfpack.jl @@ -12,7 +12,7 @@ import ..LinAlg: A_ldiv_B!, Ac_ldiv_B!, At_ldiv_B!, Factorization, det, lufact, include("umfpack_h.jl") type MatrixIllConditionedException <: Exception - message :: String + message :: AbstractString end function umferror(status::Int) diff --git a/base/loading.jl b/base/loading.jl index dd53b4bf04b2d..d9d63d0fa5f58 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -1,6 +1,6 @@ # require -function find_in_path(name::String) +function find_in_path(name::AbstractString) isabspath(name) && return name isfile(name) && return abspath(name) base = name @@ -36,13 +36,13 @@ end package_list = Dict{ByteString,Float64}() # to synchronize multiple tasks trying to require something package_locks = Dict{ByteString,Any}() -require(fname::String) = require(bytestring(fname)) -require(f::String, fs::String...) = (require(f); for x in fs require(x); end) +require(fname::AbstractString) = require(bytestring(fname)) +require(f::AbstractString, fs::AbstractString...) = (require(f); for x in fs require(x); end) # only broadcast top-level (not nested) requires and reloads toplevel_load = true -function require(name::String) +function require(name::AbstractString) path = find_in_node1_path(name) path == nothing && error("$name not found") @@ -71,7 +71,7 @@ function _require(path) end end -function reload(name::String) +function reload(name::AbstractString) global toplevel_load path = find_in_node1_path(name) path == nothing && error("$name not found") @@ -94,12 +94,12 @@ end # remote/parallel load -include_string(txt::String, fname::String) = +include_string(txt::AbstractString, fname::AbstractString) = ccall(:jl_load_file_string, Any, (Ptr{Uint8},Ptr{Uint8}), txt, fname) -include_string(txt::String) = include_string(txt, "string") +include_string(txt::AbstractString) = include_string(txt, "string") -function source_path(default::Union(String,Void)="") +function source_path(default::Union(AbstractString,Void)="") t = current_task() while true s = t.storage @@ -115,7 +115,7 @@ end macro __FILE__() source_path() end -function include_from_node1(path::String) +function include_from_node1(path::AbstractString) prev = source_path(nothing) path = (prev == nothing) ? abspath(path) : joinpath(dirname(prev),path) tls = task_local_storage() @@ -140,7 +140,7 @@ function include_from_node1(path::String) result end -function reload_path(path::String) +function reload_path(path::AbstractString) had = haskey(package_list, path) if !had package_locks[path] = RemoteRef() @@ -164,7 +164,7 @@ function reload_path(path::String) nothing end -function evalfile(path::String, args::Vector{UTF8String}=UTF8String[]) +function evalfile(path::AbstractString, args::Vector{UTF8String}=UTF8String[]) return eval(Module(:__anon__), Expr(:toplevel, :(const ARGS = $args), @@ -172,4 +172,4 @@ function evalfile(path::String, args::Vector{UTF8String}=UTF8String[]) :(eval(m,x) = Core.eval(m,x)), :(include($path)))) end -evalfile(path::String, args::Vector) = evalfile(path, UTF8String[args...]) +evalfile(path::AbstractString, args::Vector) = evalfile(path, UTF8String[args...]) diff --git a/base/mpfr.jl b/base/mpfr.jl index 5fb6f15549f49..fdd256d0b3035 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -68,13 +68,13 @@ function BigFloat(x::BigInt) return z end -function BigFloat(x::String, base::Int) +function BigFloat(x::AbstractString, base::Int) z = BigFloat() err = ccall((:mpfr_set_str, :libmpfr), Int32, (Ptr{BigFloat}, Ptr{Uint8}, Int32, Int32), &z, x, base, ROUNDING_MODE[end]) if err != 0; error("incorrectly formatted number"); end return z end -BigFloat(x::String) = BigFloat(x, 10) +BigFloat(x::AbstractString) = BigFloat(x, 10) BigFloat(x::Integer) = BigFloat(BigInt(x)) diff --git a/base/multi.jl b/base/multi.jl index 84dc32bb132f2..bf74b39368e73 100644 --- a/base/multi.jl +++ b/base/multi.jl @@ -92,12 +92,12 @@ type Worker manager::ClusterManager config::Dict - Worker(host::String, port::Integer, sock::TCPSocket, id::Int) = + Worker(host::AbstractString, port::Integer, sock::TCPSocket, id::Int) = new(bytestring(host), uint16(port), sock, IOBuffer(), [], [], id, false) end -Worker(host::String, port::Integer, sock::TCPSocket) = +Worker(host::AbstractString, port::Integer, sock::TCPSocket) = Worker(host, port, sock, 0) -function Worker(host::String, port::Integer) +function Worker(host::AbstractString, port::Integer) # Connect to the loopback port if requested host has the same ipaddress as self. if host == string(LPROC.bind_addr) w = Worker(host, port, connect("127.0.0.1", uint16(port))) @@ -117,7 +117,7 @@ function Worker(host::String, port::Integer) end w end -function Worker(host::String, bind_addr::String, port::Integer, tunnel_user::String, sshflags) +function Worker(host::AbstractString, bind_addr::AbstractString, port::Integer, tunnel_user::AbstractString, sshflags) w = Worker(host, port, connect("localhost", ssh_tunnel(tunnel_user, host, bind_addr, uint16(port), sshflags))) @@ -208,7 +208,7 @@ let next_pid = 2 # 1 is reserved for the client (always) end type ProcessGroup - name::String + name::AbstractString workers::Array{Any,1} # global references @@ -985,14 +985,14 @@ function read_cb_response(io::IO, config::Dict) return (io, host, port, host, config) end -function read_cb_response(io::IO, host::String, config::Dict) +function read_cb_response(io::IO, host::AbstractString, config::Dict) (bind_addr, port) = read_worker_host_port(io) return (io, bind_addr, port, host, config) end -read_cb_response(io::IO, host::String, port::Integer, config::Dict) = (io, host, port, host, config) +read_cb_response(io::IO, host::AbstractString, port::Integer, config::Dict) = (io, host, port, host, config) -read_cb_response(host::String, port::Integer, config::Dict) = (nothing, host, port, host, config) +read_cb_response(host::AbstractString, port::Integer, config::Dict) = (nothing, host, port, host, config) function start_cluster_workers(np::Integer, config::Dict, manager::ClusterManager, resp_arr::Array, launched_ntfy::Condition) @@ -1176,7 +1176,7 @@ end function launch_on_machine(manager::SSHManager, config::Dict, resp_arr::Array, machines_launch_ntfy::Condition, - machine::String, cnt::Integer, plaunch_ntfy::Condition) + machine::AbstractString, cnt::Integer, plaunch_ntfy::Condition) dir = config[:dir] exename = config[:exename] exeflags_base = config[:exeflags] diff --git a/base/multimedia.jl b/base/multimedia.jl index 1ea923f05da4f..d1844086c3c1f 100644 --- a/base/multimedia.jl +++ b/base/multimedia.jl @@ -19,7 +19,7 @@ print{mime}(io::IO, ::MIME{mime}) = print(io, mime) # needs to be a macro so that we can use ::@mime(s) in type declarations macro MIME(s) Base.warn_once("@MIME(\"\") is deprecated, use MIME\"\" instead.") - if isa(s,String) + if isa(s,AbstractString) :(MIME{$(Expr(:quote, symbol(s)))}) else :(MIME{symbol($s)}) @@ -38,8 +38,8 @@ mimewritable{mime}(::MIME{mime}, x) = method_exists(writemime, (IO, MIME{mime}, typeof(x))) # it is convenient to accept strings instead of ::MIME -writemime(io::IO, m::String, x) = writemime(io, MIME(m), x) -mimewritable(m::String, x) = mimewritable(MIME(m), x) +writemime(io::IO, m::AbstractString, x) = writemime(io, MIME(m), x) +mimewritable(m::AbstractString, x) = mimewritable(MIME(m), x) ########################################################################### # MIME types are assumed to be binary data except for a set of types known @@ -50,7 +50,7 @@ mimewritable(m::String, x) = mimewritable(MIME(m), x) # is like reprmime except that it always returns a string, which in the # case of binary data is Base64-encoded. # -# Also, if reprmime is passed a String for a text type or Vector{Uint8} for +# Also, if reprmime is passed a AbstractString for a text type or Vector{Uint8} for # a binary type, the argument is assumed to already be in the corresponding # format and is returned unmodified. This is useful so that raw data can be # passed to display(m::MIME, x). @@ -65,7 +65,7 @@ macro textmime(mime) Base.Multimedia.istext(::mimeT) = true if $(mime != "text/plain") # strings are shown escaped for text/plain - Base.Multimedia.reprmime(m::mimeT, x::String) = x + Base.Multimedia.reprmime(m::mimeT, x::AbstractString) = x end Base.Multimedia.reprmime(m::mimeT, x) = sprint(writemime, m, x) Base.Multimedia.stringmime(m::mimeT, x) = reprmime(m, x) @@ -83,9 +83,9 @@ stringmime(m::MIME, x) = base64(writemime, m, x) stringmime(m::MIME, x::Vector{Uint8}) = base64(write, x) # it is convenient to accept strings instead of ::MIME -istext(m::String) = istext(MIME(m)) -reprmime(m::String, x) = reprmime(MIME(m), x) -stringmime(m::String, x) = stringmime(MIME(m), x) +istext(m::AbstractString) = istext(MIME(m)) +reprmime(m::AbstractString, x) = reprmime(MIME(m), x) +stringmime(m::AbstractString, x) = stringmime(MIME(m), x) for mime in ["text/vnd.graphviz", "text/latex", "text/calendar", "text/n3", "text/richtext", "text/x-setext", "text/sgml", "text/tab-separated-values", "text/x-vcalendar", "text/x-vcard", "text/cmd", "text/css", "text/csv", "text/html", "text/javascript", "text/markdown", "text/plain", "text/vcard", "text/xml", "application/atom+xml", "application/ecmascript", "application/json", "application/rdf+xml", "application/rss+xml", "application/xml-dtd", "application/postscript", "image/svg+xml", "application/x-latex", "application/xhtml+xml", "application/javascript", "application/xml", "model/x3d+xml", "model/x3d+vrml", "model/vrml"] @eval @textmime $mime @@ -105,10 +105,10 @@ end abstract Display # it is convenient to accept strings instead of ::MIME -display(d::Display, mime::String, x) = display(d, MIME(mime), x) -display(mime::String, x) = display(MIME(mime), x) -displayable(d::Display, mime::String) = displayable(d, MIME(mime)) -displayable(mime::String) = displayable(MIME(mime)) +display(d::Display, mime::AbstractString, x) = display(d, MIME(mime), x) +display(mime::AbstractString, x) = display(MIME(mime), x) +displayable(d::Display, mime::AbstractString) = displayable(d, MIME(mime)) +displayable(mime::AbstractString) = displayable(MIME(mime)) # simplest display, which only knows how to display text/plain immutable TextDisplay <: Display @@ -198,7 +198,7 @@ function redisplay(x) throw(MethodError(redisplay, (x,))) end -function redisplay(m::Union(MIME,String), x) +function redisplay(m::Union(MIME,AbstractString), x) for i = length(displays):-1:1 xdisplayable(displays[i], m, x) && @try_display return redisplay(displays[i], m, x) @@ -208,7 +208,7 @@ end # default redisplay is simply to call display redisplay(d::Display, x) = display(d, x) -redisplay(d::Display, m::Union(MIME,String), x) = display(d, m, x) +redisplay(d::Display, m::Union(MIME,AbstractString), x) = display(d, m, x) ########################################################################### diff --git a/base/operators.jl b/base/operators.jl index 4bef1bea14d21..75153161a573c 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -171,7 +171,7 @@ widen{T<:Number}(x::T) = convert(widen(T), x) sizeof(x) = Core.sizeof(x) # copying immutable things -copy(x::Union(Symbol,Number,String,Function,Tuple,LambdaStaticData, +copy(x::Union(Symbol,Number,AbstractString,Function,Tuple,LambdaStaticData, TopNode,QuoteNode,DataType,UnionType)) = x # function pipelining diff --git a/base/path.jl b/base/path.jl index aba5551f197fd..abb6807cf4499 100644 --- a/base/path.jl +++ b/base/path.jl @@ -6,7 +6,7 @@ const path_dir_splitter = r"^(.*?)(/+)([^/]*)$" const path_ext_splitter = r"^((?:.*/)?(?:\.|[^/\.])[^/]*?)(\.[^/\.]*|)$" - splitdrive(path::String) = ("",path) + splitdrive(path::AbstractString) = ("",path) homedir() = ENV["HOME"] end @windows_only begin @@ -17,15 +17,15 @@ end const path_dir_splitter = r"^(.*?)([/\\]+)([^/\\]*)$" const path_ext_splitter = r"^((?:.*[/\\])?(?:\.|[^/\\\.])[^/\\]*?)(\.[^/\\\.]*|)$" - function splitdrive(path::String) + function splitdrive(path::AbstractString) m = match(r"^(\w+:|\\\\\w+\\\w+|\\\\\?\\UNC\\\w+\\\w+|\\\\\?\\\w+:|)(.*)$", path) bytestring(m.captures[1]), bytestring(m.captures[2]) end homedir() = get(ENV,"HOME",string(ENV["HOMEDRIVE"],ENV["HOMEPATH"])) end -isabspath(path::String) = ismatch(path_absolute_re, path) -isdirpath(path::String) = ismatch(path_directory_re, splitdrive(path)[2]) +isabspath(path::AbstractString) = ismatch(path_absolute_re, path) +isdirpath(path::AbstractString) = ismatch(path_directory_re, splitdrive(path)[2]) function splitdir(path::ByteString) a, b = splitdrive(path) @@ -34,19 +34,19 @@ function splitdir(path::ByteString) a = string(a, isempty(m.captures[1]) ? m.captures[2][1] : m.captures[1]) a, bytestring(m.captures[3]) end -splitdir(path::String) = splitdir(bytestring(path)) +splitdir(path::AbstractString) = splitdir(bytestring(path)) - dirname(path::String) = splitdir(path)[1] -basename(path::String) = splitdir(path)[2] + dirname(path::AbstractString) = splitdir(path)[1] +basename(path::AbstractString) = splitdir(path)[2] -function splitext(path::String) +function splitext(path::AbstractString) a, b = splitdrive(path) m = match(path_ext_splitter, b) m == nothing && return (path,"") a*m.captures[1], bytestring(m.captures[2]) end -function pathsep(paths::String...) +function pathsep(paths::AbstractString...) for path in paths m = match(path_separator_re, path) m != nothing && return m.match[1] @@ -54,10 +54,10 @@ function pathsep(paths::String...) return path_separator end -joinpath(a::String) = a -joinpath(a::String, b::String, c::String...) = joinpath(joinpath(a,b), c...) +joinpath(a::AbstractString) = a +joinpath(a::AbstractString, b::AbstractString, c::AbstractString...) = joinpath(joinpath(a,b), c...) -function joinpath(a::String, b::String) +function joinpath(a::AbstractString, b::AbstractString) isabspath(b) && return b A, a = splitdrive(a) B, b = splitdrive(b) @@ -68,7 +68,7 @@ function joinpath(a::String, b::String) string(C,a,pathsep(a,b),b) end -function normpath(path::String) +function normpath(path::AbstractString) isabs = isabspath(path) isdir = isdirpath(path) drive, path = splitdrive(path) @@ -101,12 +101,12 @@ function normpath(path::String) end string(drive,path) end -normpath(a::String, b::String...) = normpath(joinpath(a,b...)) +normpath(a::AbstractString, b::AbstractString...) = normpath(joinpath(a,b...)) -abspath(a::String) = normpath(isabspath(a) ? a : joinpath(pwd(),a)) -abspath(a::String, b::String...) = abspath(joinpath(a,b...)) +abspath(a::AbstractString) = normpath(isabspath(a) ? a : joinpath(pwd(),a)) +abspath(a::AbstractString, b::AbstractString...) = abspath(joinpath(a,b...)) -@windows_only realpath(path::String) = realpath(utf16(path)) +@windows_only realpath(path::AbstractString) = realpath(utf16(path)) @windows_only function realpath(path::UTF16String) p = uint32((sizeof(path)>>2) + 1) while true @@ -123,7 +123,7 @@ abspath(a::String, b::String...) = abspath(joinpath(a,b...)) end end -@unix_only function realpath(path::String) +@unix_only function realpath(path::AbstractString) p = ccall(:realpath, Ptr{Uint8}, (Ptr{Uint8}, Ptr{Uint8}), path, C_NULL) systemerror(:realpath, p == C_NULL) s = bytestring(p) @@ -131,8 +131,8 @@ end return s end -@windows_only expanduser(path::String) = path # on windows, ~ means "temporary file" -@unix_only function expanduser(path::String) +@windows_only expanduser(path::AbstractString) = path # on windows, ~ means "temporary file" +@unix_only function expanduser(path::AbstractString) i = start(path) c, i = next(path,i) if c != '~' return path end diff --git a/base/pcre.jl b/base/pcre.jl index d7d6202f84f02..a36a0236ba2e9 100644 --- a/base/pcre.jl +++ b/base/pcre.jl @@ -82,7 +82,7 @@ function config{T}(what::Integer, ::Type{T}) reinterpret(T,buf)[1] end -function compile(pattern::String, options::Integer) +function compile(pattern::AbstractString, options::Integer) errstr = Array(Ptr{Uint8},1) erroff = Array(Int32,1) re_ptr = ccall((:pcre_compile, :libpcre), Ptr{Void}, diff --git a/base/pkg.jl b/base/pkg.jl index 7bef424bbbb07..d1969839dfe8a 100644 --- a/base/pkg.jl +++ b/base/pkg.jl @@ -13,61 +13,61 @@ end const cd = Dir.cd dir(path...) = Dir.path(path...) -init(meta::String=DEFAULT_META, branch::String=META_BRANCH) = Dir.init(meta,branch) +init(meta::AbstractString=DEFAULT_META, branch::AbstractString=META_BRANCH) = Dir.init(meta,branch) edit() = cd(Entry.edit) -rm(pkg::String) = cd(Entry.rm,pkg) -add(pkg::String, vers::VersionNumber...) = cd(Entry.add,pkg,vers...) +rm(pkg::AbstractString) = cd(Entry.rm,pkg) +add(pkg::AbstractString, vers::VersionNumber...) = cd(Entry.add,pkg,vers...) available() = cd(Entry.available) -available(pkg::String) = cd(Entry.available,pkg) +available(pkg::AbstractString) = cd(Entry.available,pkg) installed() = cd(Entry.installed) -installed(pkg::String) = cd(Entry.installed,pkg) +installed(pkg::AbstractString) = cd(Entry.installed,pkg) status(io::IO=STDOUT) = cd(Entry.status,io) -status(pkg::String = "", io::IO=STDOUT) = cd(Entry.status,io,pkg) +status(pkg::AbstractString = "", io::IO=STDOUT) = cd(Entry.status,io,pkg) -clone(url_or_pkg::String) = cd(Entry.clone,url_or_pkg) -clone(url::String, pkg::String) = cd(Entry.clone,url,pkg) +clone(url_or_pkg::AbstractString) = cd(Entry.clone,url_or_pkg) +clone(url::AbstractString, pkg::AbstractString) = cd(Entry.clone,url,pkg) -checkout(pkg::String, branch::String="master"; merge::Bool=true, pull::Bool=true) = +checkout(pkg::AbstractString, branch::AbstractString="master"; merge::Bool=true, pull::Bool=true) = cd(Entry.checkout,pkg,branch,merge,pull) -free(pkg::String) = cd(Entry.free,pkg) +free(pkg::AbstractString) = cd(Entry.free,pkg) -pin(pkg::String) = cd(Entry.pin,pkg) -pin(pkg::String, ver::VersionNumber) = cd(Entry.pin,pkg,ver) +pin(pkg::AbstractString) = cd(Entry.pin,pkg) +pin(pkg::AbstractString, ver::VersionNumber) = cd(Entry.pin,pkg,ver) update() = cd(Entry.update,META_BRANCH) resolve() = cd(Entry.resolve) -register(pkg::String) = cd(Entry.register,pkg) -register(pkg::String, url::String) = cd(Entry.register,pkg,url) +register(pkg::AbstractString) = cd(Entry.register,pkg) +register(pkg::AbstractString, url::AbstractString) = cd(Entry.register,pkg,url) -tag(pkg::String, sym::Symbol=:patch) = cd(Entry.tag,pkg,sym) -tag(pkg::String, sym::Symbol, commit::String) = cd(Entry.tag,pkg,sym,false,commit) +tag(pkg::AbstractString, sym::Symbol=:patch) = cd(Entry.tag,pkg,sym) +tag(pkg::AbstractString, sym::Symbol, commit::AbstractString) = cd(Entry.tag,pkg,sym,false,commit) -tag(pkg::String, ver::VersionNumber; force::Bool=false) = cd(Entry.tag,pkg,ver,force) -tag(pkg::String, ver::VersionNumber, commit::String; force::Bool=false) = +tag(pkg::AbstractString, ver::VersionNumber; force::Bool=false) = cd(Entry.tag,pkg,ver,force) +tag(pkg::AbstractString, ver::VersionNumber, commit::AbstractString; force::Bool=false) = cd(Entry.tag,pkg,ver,force,commit) -submit(pkg::String) = cd(Entry.submit,pkg) -submit(pkg::String, commit::String) = cd(Entry.submit,pkg,commit) +submit(pkg::AbstractString) = cd(Entry.submit,pkg) +submit(pkg::AbstractString, commit::AbstractString) = cd(Entry.submit,pkg,commit) publish() = cd(Entry.publish,META_BRANCH) build() = cd(Entry.build) -build(pkgs::String...) = cd(Entry.build,[pkgs...]) +build(pkgs::AbstractString...) = cd(Entry.build,[pkgs...]) -generate(pkg::String, license::String; force::Bool=false, authors::Union(String,Array) = [], config::Dict=Dict()) = +generate(pkg::AbstractString, license::AbstractString; force::Bool=false, authors::Union(AbstractString,Array) = [], config::Dict=Dict()) = cd(Generate.package,pkg,license,force=force,authors=authors,config=config) test(;coverage::Bool=false) = cd(Entry.test; coverage=coverage) -test(pkgs::String...; coverage::Bool=false) = cd(Entry.test,String[pkgs...]; coverage=coverage) +test(pkgs::AbstractString...; coverage::Bool=false) = cd(Entry.test,AbstractString[pkgs...]; coverage=coverage) -dependents(packagename::String) = Reqs.dependents(packagename) +dependents(packagename::AbstractString) = Reqs.dependents(packagename) @deprecate release free @deprecate fixup build diff --git a/base/pkg/cache.jl b/base/pkg/cache.jl index 23d0c44a9a327..45961ceec121c 100644 --- a/base/pkg/cache.jl +++ b/base/pkg/cache.jl @@ -3,7 +3,7 @@ module Cache import ..Git, ..Dir using ..Types -path(pkg::String) = abspath(".cache", pkg) +path(pkg::AbstractString) = abspath(".cache", pkg) function mkcachedir() cache = joinpath(realpath("."), ".cache") @@ -26,7 +26,7 @@ function mkcachedir() end -function prefetch{S<:String}(pkg::String, url::String, sha1s::Vector{S}) +function prefetch{S<:AbstractString}(pkg::AbstractString, url::AbstractString, sha1s::Vector{S}) isdir(".cache") || mkcachedir() cache = path(pkg) if !isdir(cache) @@ -45,6 +45,6 @@ function prefetch{S<:String}(pkg::String, url::String, sha1s::Vector{S}) end filter(sha1->!Git.iscommit(sha1, dir=cache), sha1s) end -prefetch(pkg::String, url::String, sha1::String...) = prefetch(pkg, url, String[sha1...]) +prefetch(pkg::AbstractString, url::AbstractString, sha1::AbstractString...) = prefetch(pkg, url, AbstractString[sha1...]) end # module diff --git a/base/pkg/dir.jl b/base/pkg/dir.jl index 722357b11af4a..538861eb9b33b 100644 --- a/base/pkg/dir.jl +++ b/base/pkg/dir.jl @@ -6,7 +6,7 @@ import ..Git const DIR_NAME = ".julia" _pkgroot() = abspath(get(ENV,"JULIA_PKGDIR",joinpath(homedir(),DIR_NAME))) -isversioned(p::String) = ((x,y) = (VERSION.major, VERSION.minor); basename(p) == "v$x.$y") +isversioned(p::AbstractString) = ((x,y) = (VERSION.major, VERSION.minor); basename(p) == "v$x.$y") function path() b = _pkgroot() @@ -17,7 +17,7 @@ function path() end return b end -path(pkg::String...) = normpath(path(),pkg...) +path(pkg::AbstractString...) = normpath(path(),pkg...) function cd(f::Function, args...; kws...) dir = path() @@ -28,7 +28,7 @@ function cd(f::Function, args...; kws...) Base.cd(()->f(args...; kws...), dir) end -function init(meta::String=DEFAULT_META, branch::String=META_BRANCH) +function init(meta::AbstractString=DEFAULT_META, branch::AbstractString=META_BRANCH) dir = path() info("Initializing package repository $dir") if isdir(joinpath(dir,"METADATA")) diff --git a/base/pkg/entry.jl b/base/pkg/entry.jl index bc4b01173ea0b..5a961e3dfe372 100644 --- a/base/pkg/entry.jl +++ b/base/pkg/entry.jl @@ -13,7 +13,7 @@ macro recover(ex) end end -function edit(f::Function, pkg::String, args...) +function edit(f::Function, pkg::AbstractString, args...) r = Reqs.read("REQUIRE") reqs = Reqs.parse(r) avail = Read.available() @@ -40,7 +40,7 @@ function edit() resolve(reqsʹ) end -function add(pkg::String, vers::VersionSet) +function add(pkg::AbstractString, vers::VersionSet) outdated = :maybe @sync begin @async if !edit(Reqs.add,pkg,vers) @@ -68,9 +68,9 @@ function add(pkg::String, vers::VersionSet) info("Use `Pkg.update()` to get the latest versions of your packages") end end -add(pkg::String, vers::VersionNumber...) = add(pkg,VersionSet(vers...)) +add(pkg::AbstractString, vers::VersionNumber...) = add(pkg,VersionSet(vers...)) -function rm(pkg::String) +function rm(pkg::AbstractString) edit(Reqs.rm,pkg) && return ispath(pkg) || return info("Nothing to be done") info("Removing $pkg (unregistered)") @@ -79,7 +79,7 @@ end available() = sort!(ASCIIString[keys(Read.available())...], by=lowercase) -function available(pkg::String) +function available(pkg::AbstractString) avail = Read.available(pkg) if !isempty(avail) || Read.isinstalled(pkg) return sort!([keys(avail)...]) @@ -95,14 +95,14 @@ function installed() return pkgs end -function installed(pkg::String) +function installed(pkg::AbstractString) avail = Read.available(pkg) Read.isinstalled(pkg) && return Read.installed_version(pkg,avail) isempty(avail) && error("$pkg is not a package (not registered or installed)") return nothing # registered but not installed end -function status(io::IO; pkgname::String = "") +function status(io::IO; pkgname::AbstractString = "") showpkg(pkg) = (pkgname == "") ? (true) : (pkg == pkgname) reqs = Reqs.parse("REQUIRE") instd = Read.installed() @@ -127,15 +127,15 @@ function status(io::IO; pkgname::String = "") end end -status(io::IO, pkg::String) = status(io, pkgname = pkg) +status(io::IO, pkg::AbstractString) = status(io, pkgname = pkg) -function status(io::IO, pkg::String, ver::VersionNumber, fix::Bool) +function status(io::IO, pkg::AbstractString, ver::VersionNumber, fix::Bool) @printf io " - %-29s " pkg fix || return println(io,ver) @printf io "%-19s" ver if ispath(pkg,".git") print(io, Git.attached(dir=pkg) ? Git.branch(dir=pkg) : Git.head(dir=pkg)[1:8]) - attrs = String[] + attrs = AbstractString[] isfile("METADATA",pkg,"url") || push!(attrs,"unregistered") Git.dirty(dir=pkg) && push!(attrs,"dirty") isempty(attrs) || print(io, " (",join(attrs,", "),")") @@ -145,7 +145,7 @@ function status(io::IO, pkg::String, ver::VersionNumber, fix::Bool) println(io) end -function clone(url::String, pkg::String) +function clone(url::AbstractString, pkg::AbstractString) info("Cloning $pkg from $url") ispath(pkg) && error("$pkg already exists") try @@ -162,7 +162,7 @@ function clone(url::String, pkg::String) end end -function clone(url_or_pkg::String) +function clone(url_or_pkg::AbstractString) urlpath = joinpath("METADATA",url_or_pkg,"url") if isfile(urlpath) pkg = url_or_pkg @@ -177,7 +177,7 @@ function clone(url_or_pkg::String) clone(url,pkg) end -function _checkout(pkg::String, what::String, merge::Bool=false, pull::Bool=false, branch::Bool=false) +function _checkout(pkg::AbstractString, what::AbstractString, merge::Bool=false, pull::Bool=false, branch::Bool=false) Git.transact(dir=pkg) do Git.dirty(dir=pkg) && error("$pkg is dirty, bailing") branch ? Git.run(`checkout -q -B $what -t origin/$what`, dir=pkg) : Git.run(`checkout -q $what`, dir=pkg) @@ -190,13 +190,13 @@ function _checkout(pkg::String, what::String, merge::Bool=false, pull::Bool=fals end end -function checkout(pkg::String, branch::String, merge::Bool, pull::Bool) +function checkout(pkg::AbstractString, branch::AbstractString, merge::Bool, pull::Bool) ispath(pkg,".git") || error("$pkg is not a git repo") info("Checking out $pkg $branch...") _checkout(pkg,branch,merge,pull,true) end -function free(pkg::String) +function free(pkg::AbstractString) ispath(pkg,".git") || error("$pkg is not a git repo") Read.isinstalled(pkg) || error("$pkg cannot be freed – not an installed package") avail = Read.available(pkg) @@ -215,7 +215,7 @@ function free(pkg::String) end end -function pin(pkg::String, head::String) +function pin(pkg::AbstractString, head::AbstractString) ispath(pkg,".git") || error("$pkg is not a git repo") branch = "pinned.$(head[1:8]).tmp" rslv = (head != Git.head(dir=pkg)) @@ -223,9 +223,9 @@ function pin(pkg::String, head::String) Git.run(`checkout -q -B $branch $head`, dir=pkg) rslv ? resolve() : nothing end -pin(pkg::String) = pin(pkg,Git.head(dir=pkg)) +pin(pkg::AbstractString) = pin(pkg,Git.head(dir=pkg)) -function pin(pkg::String, ver::VersionNumber) +function pin(pkg::AbstractString, ver::VersionNumber) ispath(pkg,".git") || error("$pkg is not a git repo") Read.isinstalled(pkg) || error("$pkg cannot be pinned – not an installed package".tmp) avail = Read.available(pkg) @@ -234,7 +234,7 @@ function pin(pkg::String, ver::VersionNumber) pin(pkg,avail[ver].sha1) end -function update(branch::String) +function update(branch::AbstractString) info("Updating METADATA...") cd("METADATA") do if Git.branch() != branch @@ -282,7 +282,7 @@ function update(branch::String) updatehook(sort!([keys(installed())...])) end -function pull_request(dir::String, commit::String="", url::String="") +function pull_request(dir::AbstractString, commit::AbstractString="", url::AbstractString="") commit = isempty(commit) ? Git.head(dir=dir) : Git.readchomp(`rev-parse --verify $commit`, dir=dir) isempty(url) && (url = Git.readchomp(`config remote.origin.url`, dir=dir)) @@ -300,13 +300,13 @@ function pull_request(dir::String, commit::String="", url::String="") @osx? run(`open $pr_url`) : info("To create a pull-request, open:\n\n $pr_url\n") end -function submit(pkg::String, commit::String="") +function submit(pkg::AbstractString, commit::AbstractString="") urlpath = joinpath("METADATA",pkg,"url") url = ispath(urlpath) ? readchomp(urlpath) : "" pull_request(pkg, commit, url) end -function publish(branch::String) +function publish(branch::AbstractString) Git.branch(dir="METADATA") == branch || error("METADATA must be on $branch to publish changes") Git.run(`fetch -q`, dir="METADATA") @@ -445,7 +445,7 @@ function resolve( build(map(x->x[1],filter(x->x[2][2]!=nothing,changes))) end -function write_tag_metadata(pkg::String, ver::VersionNumber, commit::String, force::Bool=false) +function write_tag_metadata(pkg::AbstractString, ver::VersionNumber, commit::AbstractString, force::Bool=false) cmd = Git.cmd(`cat-file blob $commit:REQUIRE`, dir=pkg) reqs = success(cmd) ? Reqs.read(cmd) : Reqs.Line[] cd("METADATA") do @@ -470,7 +470,7 @@ function write_tag_metadata(pkg::String, ver::VersionNumber, commit::String, for return nothing end -function register(pkg::String, url::String) +function register(pkg::AbstractString, url::AbstractString) ispath(pkg,".git") || error("$pkg is not a git repo") isfile("METADATA",pkg,"url") && error("$pkg already registered") tags = split(Git.readall(`tag -l v*`, dir=pkg)) @@ -506,7 +506,7 @@ function register(pkg::String, url::String) end end -function register(pkg::String) +function register(pkg::AbstractString) Git.success(`config remote.origin.url`, dir=pkg) || error("$pkg: no URL configured") url = Git.readchomp(`config remote.origin.url`, dir=pkg) @@ -521,7 +521,7 @@ end nextbump(v::VersionNumber) = isrewritable(v) ? v : nextpatch(v) -function tag(pkg::String, ver::Union(Symbol,VersionNumber), force::Bool=false, commit::String="HEAD") +function tag(pkg::AbstractString, ver::Union(Symbol,VersionNumber), force::Bool=false, commit::AbstractString="HEAD") ispath(pkg,".git") || error("$pkg is not a git repo") Git.dirty(dir=pkg) && error("$pkg is dirty – commit or stash changes to tag") @@ -674,7 +674,7 @@ function updatehook(pkgs::Vector) """) end -function test!(pkg::String, errs::Vector{String}, notests::Vector{String}; coverage::Bool=false) +function test!(pkg::AbstractString, errs::Vector{AbstractString}, notests::Vector{AbstractString}; coverage::Bool=false) reqs_path = abspath(pkg,"test","REQUIRE") if isfile(reqs_path) tests_require = Reqs.parse(reqs_path) @@ -706,20 +706,20 @@ function test!(pkg::String, errs::Vector{String}, notests::Vector{String}; cover resolve() end -function test(pkgs::Vector{String}; coverage::Bool=false) - errs = String[] - notests = String[] +function test(pkgs::Vector{AbstractString}; coverage::Bool=false) + errs = AbstractString[] + notests = AbstractString[] for pkg in pkgs test!(pkg,errs,notests; coverage=coverage) end if !isempty(errs) || !isempty(notests) - messages = String[] + messages = AbstractString[] isempty(errs) || push!(messages, "$(join(errs,", "," and ")) had test errors") isempty(notests) || push!(messages, "$(join(notests,", "," and ")) did not provide a test/runtests.jl file") error(join(messages, "and")) end end -test(;coverage::Bool=false) = test(sort!(String[keys(installed())...]); coverage=coverage) +test(;coverage::Bool=false) = test(sort!(AbstractString[keys(installed())...]); coverage=coverage) end # module diff --git a/base/pkg/generate.jl b/base/pkg/generate.jl index 1885676000d75..20ea7ba948e49 100644 --- a/base/pkg/generate.jl +++ b/base/pkg/generate.jl @@ -3,10 +3,10 @@ module Generate import ..Git, ..Read copyright_year() = readchomp(`date +%Y`) -copyright_name(dir::String) = readchomp(Git.cmd(`config --get user.name`, dir=dir)) +copyright_name(dir::AbstractString) = readchomp(Git.cmd(`config --get user.name`, dir=dir)) github_user() = readchomp(ignorestatus(`git config --global --get github.user`)) -function git_contributors(dir::String, n::Int=typemax(Int)) +function git_contributors(dir::AbstractString, n::Int=typemax(Int)) contrib = Dict() tty = @windows? "CON:" : "/dev/tty" for line in eachline(tty |> Git.cmd(`shortlog -nes`, dir=dir)) @@ -28,12 +28,12 @@ function git_contributors(dir::String, n::Int=typemax(Int)) end function package( - pkg::String, - license::String; + pkg::AbstractString, + license::AbstractString; force::Bool = false, - authors::Union(String,Array) = "", - years::Union(Int,String) = copyright_year(), - user::String = github_user(), + authors::Union(AbstractString,Array) = "", + years::Union(Int,AbstractString) = copyright_year(), + user::AbstractString = github_user(), config::Dict = Dict(), ) isnew = !ispath(pkg) @@ -83,7 +83,7 @@ function package( end end -function init(pkg::String, url::String=""; config::Dict=Dict()) +function init(pkg::AbstractString, url::AbstractString=""; config::Dict=Dict()) if !ispath(pkg) info("Initializing $pkg repo: $(abspath(pkg))") Git.run(`init -q $pkg`) @@ -99,9 +99,9 @@ function init(pkg::String, url::String=""; config::Dict=Dict()) Git.set_remote_url(url,dir=pkg) end -function license(pkg::String, license::String, - years::Union(Int,String), - authors::Union(String,Array); +function license(pkg::AbstractString, license::AbstractString, + years::Union(Int,AbstractString), + authors::Union(AbstractString,Array); force::Bool=false) genfile(pkg,"LICENSE.md",force) do io if !haskey(LICENSES,license) @@ -112,7 +112,7 @@ function license(pkg::String, license::String, end || info("License file exists, leaving unmodified; use `force=true` to overwrite") end -function readme(pkg::String, user::String=""; force::Bool=false) +function readme(pkg::AbstractString, user::AbstractString=""; force::Bool=false) genfile(pkg,"README.md",force) do io println(io, "# $pkg") isempty(user) && return @@ -121,7 +121,7 @@ function readme(pkg::String, user::String=""; force::Bool=false) end end -function tests(pkg::String; force::Bool=false) +function tests(pkg::AbstractString; force::Bool=false) genfile(pkg,"test/runtests.jl",force) do io print(io, """ using $pkg @@ -133,7 +133,7 @@ function tests(pkg::String; force::Bool=false) end end -function travis(pkg::String; force::Bool=false) +function travis(pkg::AbstractString; force::Bool=false) genfile(pkg,".travis.yml",force) do io print(io, """ language: cpp @@ -157,7 +157,7 @@ function travis(pkg::String; force::Bool=false) end end -function entrypoint(pkg::String; force::Bool=false) +function entrypoint(pkg::AbstractString; force::Bool=false) genfile(pkg,"src/$pkg.jl",force) do io print(io, """ module $pkg @@ -169,7 +169,7 @@ function entrypoint(pkg::String; force::Bool=false) end end -function genfile(f::Function, pkg::String, file::String, force::Bool=false) +function genfile(f::Function, pkg::AbstractString, file::AbstractString, force::Bool=false) path = joinpath(pkg,file) if force || !ispath(path) info("Generating $file") @@ -181,9 +181,9 @@ function genfile(f::Function, pkg::String, file::String, force::Bool=false) return false end -copyright(years::String, authors::String) = "> Copyright (c) $years: $authors." +copyright(years::AbstractString, authors::AbstractString) = "> Copyright (c) $years: $authors." -function copyright(years::String, authors::Array) +function copyright(years::AbstractString, authors::Array) text = "> Copyright (c) $years:" for author in authors text *= "\n> * $author" @@ -191,7 +191,7 @@ function copyright(years::String, authors::Array) return text end -mit(pkg::String, years::String, authors::Union(String,Array)) = +mit(pkg::AbstractString, years::AbstractString, authors::Union(AbstractString,Array)) = """ The $pkg.jl package is licensed under the MIT "Expat" License: @@ -217,7 +217,7 @@ $(copyright(years,authors)) > SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -bsd(pkg::String, years::String, authors::Union(String,Array)) = +bsd(pkg::AbstractString, years::AbstractString, authors::Union(AbstractString,Array)) = """ The $pkg.jl package is licensed under the Simplified "2-clause" BSD License: @@ -246,7 +246,7 @@ $(copyright(years,authors)) > OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """ -asl(pkg::String, years::String, authors::Union(String,Array)) = +asl(pkg::AbstractString, years::AbstractString, authors::Union(AbstractString,Array)) = """ The $pkg.jl package is licensed under version 2.0 of the Apache License: diff --git a/base/pkg/git.jl b/base/pkg/git.jl index 82c29da1df18f..1e87d9885a81a 100644 --- a/base/pkg/git.jl +++ b/base/pkg/git.jl @@ -31,7 +31,7 @@ function success(args::Cmd; dir="") end modules(args::Cmd; dir="") = readchomp(`config -f .gitmodules $args`, dir=dir) -different(verA::String, verB::String, path::String; dir="") = +different(verA::AbstractString, verB::AbstractString, path::AbstractString; dir="") = !success(`diff-tree --quiet $verA $verB -- $path`, dir=dir) dirty(; dir="") = !success(`diff-index --quiet HEAD`, dir=dir) @@ -84,7 +84,7 @@ function transact(f::Function; dir="") end end -function is_ancestor_of(a::String, b::String; dir="") +function is_ancestor_of(a::AbstractString, b::AbstractString; dir="") A = readchomp(`rev-parse $a`, dir=dir) readchomp(`merge-base $A $b`, dir=dir) == A end @@ -92,7 +92,7 @@ end const GITHUB_REGEX = r"^(?:git@|git://|https://(?:[\w\.\+\-]+@)?)github.com[:/](([^/].+)/(.+?))(?:\.git)?$"i -function set_remote_url(url::String; remote::String="origin", dir="") +function set_remote_url(url::AbstractString; remote::AbstractString="origin", dir="") run(`config remote.$remote.url $url`, dir=dir) m = match(GITHUB_REGEX,url) m == nothing && return @@ -100,7 +100,7 @@ function set_remote_url(url::String; remote::String="origin", dir="") push != url && run(`config remote.$remote.pushurl $push`, dir=dir) end -function normalize_url(url::String) +function normalize_url(url::AbstractString) m = match(GITHUB_REGEX,url) m == nothing ? url : "git://github.com/$(m.captures[1]).git" end diff --git a/base/pkg/github.jl b/base/pkg/github.jl index 5d998e73b06ee..f6b5cf4cf4816 100644 --- a/base/pkg/github.jl +++ b/base/pkg/github.jl @@ -31,12 +31,12 @@ function json() Main.JSON end -function curl(url::String, opts::Cmd=``) +function curl(url::AbstractString, opts::Cmd=``) success(`curl --version`) || error("using the GitHub API requires having `curl` installed") out, proc = open(`curl -i -s -S $opts $url`,"r") head = readline(out) status = int(split(head,r"\s+";limit=3)[2]) - header = Dict{String,String}() + header = Dict{AbstractString,AbstractString}() for line in eachline(out) if !ismatch(r"^\s*$",line) (k,v) = split(line, r":\s*"; limit=2) @@ -47,8 +47,8 @@ function curl(url::String, opts::Cmd=``) end error("strangely formatted HTTP response") end -curl(url::String, data::Void, opts::Cmd=``) = curl(url,opts) -curl(url::String, data, opts::Cmd=``) = +curl(url::AbstractString, data::Void, opts::Cmd=``) = curl(url,opts) +curl(url::AbstractString, data, opts::Cmd=``) = curl(url,`--data $(sprint(io->json().print(io,data))) $opts`) function delete_token() @@ -57,7 +57,7 @@ function delete_token() info("Could not authenticate with existing token. Deleting token and trying again.") end -function token(user::String=user()) +function token(user::AbstractString=user()) tokfile = Dir.path(".github","token") isfile(tokfile) && return strip(readchomp(tokfile)) status, header, content = curl("https://api.github.com/authorizations",AUTH_DATA,`-u $user`) @@ -106,25 +106,25 @@ function token(user::String=user()) return tok end -function req(resource::String, data, opts::Cmd=``) +function req(resource::AbstractString, data, opts::Cmd=``) url = "https://api.github.com/$resource" status, header, content = curl(url,data,`-u $(token()):x-oauth-basic $opts`) response = json().parse(content) status, response end -GET(resource::String, data, opts::Cmd=``) = req(resource,data,opts) -HEAD(resource::String, data, opts::Cmd=``) = req(resource,data,`-I $opts`) -PUT(resource::String, data, opts::Cmd=``) = req(resource,data,`-X PUT $opts`) -POST(resource::String, data, opts::Cmd=``) = req(resource,data,`-X POST $opts`) -PATCH(resource::String, data, opts::Cmd=``) = req(resource,data,`-X PATCH $opts`) -DELETE(resource::String, data, opts::Cmd=``) = req(resource,data,`-X DELETE $opts`) +GET(resource::AbstractString, data, opts::Cmd=``) = req(resource,data,opts) +HEAD(resource::AbstractString, data, opts::Cmd=``) = req(resource,data,`-I $opts`) +PUT(resource::AbstractString, data, opts::Cmd=``) = req(resource,data,`-X PUT $opts`) +POST(resource::AbstractString, data, opts::Cmd=``) = req(resource,data,`-X POST $opts`) +PATCH(resource::AbstractString, data, opts::Cmd=``) = req(resource,data,`-X PATCH $opts`) +DELETE(resource::AbstractString, data, opts::Cmd=``) = req(resource,data,`-X DELETE $opts`) for m in (:GET,:HEAD,:PUT,:POST,:PATCH,:DELETE) - @eval $m(resource::String, opts::Cmd=``) = $m(resource,nothing,opts) + @eval $m(resource::AbstractString, opts::Cmd=``) = $m(resource,nothing,opts) end -function pushable(owner::String, repo::String, user::String=user()) +function pushable(owner::AbstractString, repo::AbstractString, user::AbstractString=user()) status, response = HEAD("repos/$owner/$repo") status == 404 && error("repo $owner/$repo does not exist") status, response = GET("repos/$owner/$repo/collaborators/$user") @@ -133,7 +133,7 @@ function pushable(owner::String, repo::String, user::String=user()) error("unexpected API status code: $status – $(response["message"])") end -function fork(owner::String, repo::String) +function fork(owner::AbstractString, repo::AbstractString) status, response = POST("repos/$owner/$repo/forks") if status == 401 delete_token() diff --git a/base/pkg/read.jl b/base/pkg/read.jl index d1e624ed9b54c..56e2c3ce2f4ea 100644 --- a/base/pkg/read.jl +++ b/base/pkg/read.jl @@ -5,8 +5,8 @@ using ..Types readstrip(path...) = strip(readall(joinpath(path...))) -url(pkg::String) = readstrip("METADATA", pkg, "url") -sha1(pkg::String, ver::VersionNumber) = readstrip("METADATA", pkg, "versions", string(ver), "sha1") +url(pkg::AbstractString) = readstrip("METADATA", pkg, "url") +sha1(pkg::AbstractString, ver::VersionNumber) = readstrip("METADATA", pkg, "versions", string(ver), "sha1") function available(names=readdir("METADATA")) pkgs = Dict{ByteString,Dict{VersionNumber,Available}}() @@ -26,7 +26,7 @@ function available(names=readdir("METADATA")) end return pkgs end -available(pkg::String) = get(available([pkg]),pkg,Dict{VersionNumber,Available}()) +available(pkg::AbstractString) = get(available([pkg]),pkg,Dict{VersionNumber,Available}()) function latest(names=readdir("METADATA")) pkgs = Dict{ByteString,Available}() @@ -50,10 +50,10 @@ function latest(names=readdir("METADATA")) return pkgs end -isinstalled(pkg::String) = +isinstalled(pkg::AbstractString) = pkg != "METADATA" && pkg != "REQUIRE" && pkg[1] != '.' && isdir(pkg) -function isfixed(pkg::String, avail::Dict=available(pkg)) +function isfixed(pkg::AbstractString, avail::Dict=available(pkg)) isinstalled(pkg) || error("$pkg is not an installed package.") isfile("METADATA", pkg, "url") || return true ispath(pkg, ".git") || return true @@ -78,7 +78,7 @@ function isfixed(pkg::String, avail::Dict=available(pkg)) return true end -function installed_version(pkg::String, avail::Dict=available(pkg)) +function installed_version(pkg::AbstractString, avail::Dict=available(pkg)) ispath(pkg,".git") || return typemin(VersionNumber) head = Git.head(dir=pkg) vers = [keys(filter((ver,info)->info.sha1==head, avail))...] @@ -113,7 +113,7 @@ function installed_version(pkg::String, avail::Dict=available(pkg)) end end -function requires_path(pkg::String, avail::Dict=available(pkg)) +function requires_path(pkg::AbstractString, avail::Dict=available(pkg)) pkgreq = joinpath(pkg,"REQUIRE") ispath(pkg,".git") || return pkgreq Git.dirty("REQUIRE", dir=pkg) && return pkgreq @@ -127,13 +127,13 @@ function requires_path(pkg::String, avail::Dict=available(pkg)) return pkgreq end -function requires_list(pkg::String, avail::Dict=available(pkg)) +function requires_list(pkg::AbstractString, avail::Dict=available(pkg)) reqs = filter!(Reqs.read(requires_path(pkg,avail))) do line isa(line,Reqs.Requirement) end map(req->req.package, reqs) end -requires_dict(pkg::String, avail::Dict=available(pkg)) = +requires_dict(pkg::AbstractString, avail::Dict=available(pkg)) = Reqs.parse(requires_path(pkg,avail)) function installed(avail::Dict=available()) @@ -167,7 +167,7 @@ function free(inst::Dict=installed()) return pkgs end -function issue_url(pkg::String) +function issue_url(pkg::AbstractString) ispath(pkg,".git") || return "" m = match(Git.GITHUB_REGEX, url(pkg)) m == nothing && return "" diff --git a/base/pkg/reqs.jl b/base/pkg/reqs.jl index e901adc3e721d..a55e419b094d3 100644 --- a/base/pkg/reqs.jl +++ b/base/pkg/reqs.jl @@ -6,17 +6,17 @@ using ..Types abstract Line immutable Comment <: Line - content::String + content::AbstractString end immutable Requirement <: Line - content::String - package::String + content::AbstractString + package::AbstractString versions::VersionSet - system::Vector{String} + system::Vector{AbstractString} - function Requirement(content::String) + function Requirement(content::AbstractString) fields = split(replace(content, r"#.*$", "")) - system = String[] + system = AbstractString[] while !isempty(fields) && fields[1][1] == '@' push!(system,shift!(fields)[2:end]) end @@ -28,7 +28,7 @@ immutable Requirement <: Line issorted(versions) || error("invalid requires entry for $package: $content") new(content, package, VersionSet(versions), system) end - function Requirement(package::String, versions::VersionSet, system::Vector{String}=String[]) + function Requirement(package::AbstractString, versions::VersionSet, system::Vector{AbstractString}=AbstractString[]) content = "" for os in system content *= "@$os " @@ -58,7 +58,7 @@ function read(readable::Union(IO,Base.AbstractCmd)) end return lines end -read(file::String) = isfile(file) ? open(read,file) : Line[] +read(file::AbstractString) = isfile(file) ? open(read,file) : Line[] function write(io::IO, lines::Vector{Line}) for line in lines @@ -70,7 +70,7 @@ function write(io::IO, reqs::Requires) println(io, Requirement(pkg, reqs[pkg]).content) end end -write(file::String, r::Union(Vector{Line},Requires)) = open(io->write(io,r), file, "w") +write(file::AbstractString, r::Union(Vector{Line},Requires)) = open(io->write(io,r), file, "w") function parse(lines::Vector{Line}) reqs = Requires() @@ -96,8 +96,8 @@ function parse(lines::Vector{Line}) end parse(x) = parse(read(x)) -function dependents(packagename::String) - pkgs = String[] +function dependents(packagename::AbstractString) + pkgs = AbstractString[] cd(Pkg.dir()) do for (pkg,latest) in Pkg.Read.latest() if haskey(latest.requires, packagename) @@ -110,7 +110,7 @@ end # add & rm – edit the content a requires file -function add(lines::Vector{Line}, pkg::String, versions::VersionSet=VersionSet()) +function add(lines::Vector{Line}, pkg::AbstractString, versions::VersionSet=VersionSet()) v = VersionSet[] filtered = filter(lines) do line if !isa(line,Comment) && line.package == pkg && isempty(line.system) @@ -124,7 +124,7 @@ function add(lines::Vector{Line}, pkg::String, versions::VersionSet=VersionSet() push!(filtered, Requirement(pkg, versions)) end -rm(lines::Vector{Line}, pkg::String) = filter(lines) do line +rm(lines::Vector{Line}, pkg::AbstractString) = filter(lines) do line isa(line,Comment) || line.package != pkg end diff --git a/base/pkg/types.jl b/base/pkg/types.jl index fc3c9793ac842..cfd3390cd3e1c 100644 --- a/base/pkg/types.jl +++ b/base/pkg/types.jl @@ -56,7 +56,7 @@ function merge_requires!(A::Requires, B::Requires) return A end -satisfies(pkg::String, ver::VersionNumber, reqs::Requires) = +satisfies(pkg::AbstractString, ver::VersionNumber, reqs::Requires) = !haskey(reqs, pkg) || in(ver, reqs[pkg]) immutable Available diff --git a/base/pkg/write.jl b/base/pkg/write.jl index 4da65053ee9fd..2ceb10341399e 100644 --- a/base/pkg/write.jl +++ b/base/pkg/write.jl @@ -2,12 +2,12 @@ module Write import ..Git, ..Cache, ..Read -function prefetch(pkg::String, sha1::String) +function prefetch(pkg::AbstractString, sha1::AbstractString) isempty(Cache.prefetch(pkg, Read.url(pkg), sha1)) && return error("$pkg: couldn't find commit $(sha1[1:10])") end -function fetch(pkg::String, sha1::String) +function fetch(pkg::AbstractString, sha1::AbstractString) refspec = "+refs/*:refs/remotes/cache/*" Git.run(`fetch -q $(Cache.path(pkg)) $refspec`, dir=pkg) Git.iscommit(sha1, dir=pkg) && return @@ -20,12 +20,12 @@ function fetch(pkg::String, sha1::String) end end -function checkout(pkg::String, sha1::String) +function checkout(pkg::AbstractString, sha1::AbstractString) Git.set_remote_url(Read.url(pkg), dir=pkg) Git.run(`checkout -q $sha1`, dir=pkg) end -function install(pkg::String, sha1::String) +function install(pkg::AbstractString, sha1::AbstractString) prefetch(pkg, sha1) if isdir(".trash/$pkg") mv(".trash/$pkg", "./$pkg") @@ -36,13 +36,13 @@ function install(pkg::String, sha1::String) checkout(pkg, sha1) end -function update(pkg::String, sha1::String) +function update(pkg::AbstractString, sha1::AbstractString) prefetch(pkg, sha1) fetch(pkg, sha1) checkout(pkg, sha1) end -function remove(pkg::String) +function remove(pkg::AbstractString) isdir(".trash") || mkdir(".trash") ispath(".trash/$pkg") && rm(".trash/$pkg", recursive=true) mv(pkg, ".trash/$pkg") diff --git a/base/poll.jl b/base/poll.jl index f81fa24073b2e..a896149ef144e 100644 --- a/base/poll.jl +++ b/base/poll.jl @@ -67,7 +67,7 @@ abstract UVPollingWatcher type PollingFileWatcher <: UVPollingWatcher handle::Ptr{Void} - file::String + file::AbstractString open::Bool notify::Condition cb::Callback diff --git a/base/precompile.jl b/base/precompile.jl index c1a0dfe708c08..3d85ccbf1340d 100644 --- a/base/precompile.jl +++ b/base/precompile.jl @@ -119,7 +119,7 @@ precompile(Base.getindex, (Dict{Any,Any}, Int32)) precompile(Base.getindex, (Dict{Symbol,Any},Symbol)) precompile(Base.getindex, (Type{ByteString}, ASCIIString, ASCIIString)) precompile(Base.getindex, (Type{Dict{Any, Any}}, Dict{Any, Any}, Dict{Any, Any}, Dict{Any, Any}, Dict{Any, Any}, Dict{Any, Any})) -precompile(Base.getindex, (Type{String},)) +precompile(Base.getindex, (Type{AbstractString},)) precompile(Base.getpid, ()) precompile(Base.hash, (Int,)) precompile(Base.hash, (RemoteRef,)) @@ -209,15 +209,15 @@ precompile(Base.print, (IOStream,ASCIIString)) precompile(Base.print_joined, (IOBuffer, (ASCIIString,), Char)) precompile(Base.print_joined, (IOBuffer, (Int,), Char)) precompile(Base.print_joined, (IOBuffer, Array{ASCIIString,1}, Char)) -precompile(Base.print_joined, (IOBuffer, Array{String,1}, ASCIIString)) +precompile(Base.print_joined, (IOBuffer, Array{AbstractString,1}, ASCIIString)) precompile(Base.print_joined, (IOBuffer, Array{SubString{ASCIIString}, 1}, ASCIIString)) precompile(Base.print_joined, (IOBuffer, Array{UTF8String,1}, Char)) precompile(Base.println, (Base.TTY,)) precompile(Base.println, (Base.Terminals.TTYTerminal,)) precompile(Base.promote_type, (Type{Int}, Bool)) precompile(Base.push!, (Array{Char, 1}, Char)) -precompile(Base.push!, (Array{String, 1}, ASCIIString)) -precompile(Base.push!, (Array{String,1}, UTF8String)) +precompile(Base.push!, (Array{AbstractString, 1}, ASCIIString)) +precompile(Base.push!, (Array{AbstractString,1}, UTF8String)) precompile(Base.push!, (Array{Union(ASCIIString, UTF8String), 1}, ASCIIString)) precompile(Base.pushdisplay, (Base.Multimedia.TextDisplay,)) precompile(Base.pwd, ()) @@ -249,7 +249,7 @@ precompile(Base.setindex!, (Array{Any,1}, WeakRef, Int)) precompile(Base.setindex!, (Array{Base.LineEdit.TextInterface, 1}, Base.LineEdit.HistoryPrompt{Base.REPL.REPLHistoryProvider}, UnitRange{Int})) precompile(Base.setindex!, (Array{Base.LineEdit.TextInterface, 1}, Base.LineEdit.Prompt, UnitRange{Int})) precompile(Base.setindex!, (Array{Char, 1}, Char, Int)) -precompile(Base.setindex!, (Array{String, 1}, ASCIIString, Int)) +precompile(Base.setindex!, (Array{AbstractString, 1}, ASCIIString, Int)) precompile(Base.setindex!, (Array{Symbol, 1}, Symbol, Int)) precompile(Base.setindex!, (Array{Uint8,1}, Uint8, Int)) precompile(Base.setindex!, (BitArray{1}, Bool, Int,)) diff --git a/base/printf.jl b/base/printf.jl index 80be8ff8bcdd2..db6c7919ee146 100644 --- a/base/printf.jl +++ b/base/printf.jl @@ -6,11 +6,11 @@ export @printf, @sprintf const SmallFloatingPoint = Union(Float64,Float32,Float16) const SmallNumber = Union(SmallFloatingPoint,Base.Signed64,Base.Unsigned64,Uint128,Int128) -function gen(s::String) +function gen(s::AbstractString) args = [] blk = Expr(:block, :(local neg, pt, len, exp, do_out, args)) for x in parse(s) - if isa(x,String) + if isa(x,AbstractString) push!(blk.args, :(write(out, $(length(x)==1 ? x[1] : x)))) else c = lowercase(x[end]) @@ -32,7 +32,7 @@ end ### printf format string parsing ### -function parse(s::String) +function parse(s::AbstractString) # parse format string in to stings and format tuples list = [] i = j = start(s) @@ -54,9 +54,9 @@ function parse(s::String) # coalesce adjacent strings i = 1 while i < length(list) - if isa(list[i],String) + if isa(list[i],AbstractString) for j = i+1:length(list) - if !isa(list[j],String) + if !isa(list[j],AbstractString) j -= 1 break end @@ -80,10 +80,10 @@ end # (h|hh|l|ll|L|j|t|z|q)? # modifier (ignored) # [diouxXeEfFgGaAcCsSp%] # conversion -next_or_die(s::String, k) = !done(s,k) ? next(s,k) : +next_or_die(s::AbstractString, k) = !done(s,k) ? next(s,k) : error("invalid printf format string: ", repr(s)) -function parse1(s::String, k::Integer) +function parse1(s::AbstractString, k::Integer) j = k width = 0 precision = -1 @@ -814,7 +814,7 @@ is_str_expr(ex) = endswith(string(ex.args[1]),"str"))) function _printf(macroname, io, fmt, args) - isa(fmt, String) || error("$macroname: format must be a plain static string (no interpolation or prefix)") + isa(fmt, AbstractString) || error("$macroname: format must be a plain static string (no interpolation or prefix)") sym_args, blk = gen(fmt) has_splatting = false @@ -863,10 +863,10 @@ end macro printf(args...) !isempty(args) || error("@printf: called with zero arguments") - if isa(args[1], String) || is_str_expr(args[1]) + if isa(args[1], AbstractString) || is_str_expr(args[1]) _printf("@printf", :STDOUT, args[1], args[2:end]) else - (length(args) >= 2 && (isa(args[2], String) || is_str_expr(args[2]))) || + (length(args) >= 2 && (isa(args[2], AbstractString) || is_str_expr(args[2]))) || error("@printf: first or second argument must be a format string") _printf("@printf", esc(args[1]), args[2], args[3:end]) end @@ -874,7 +874,7 @@ end macro sprintf(args...) !isempty(args) || error("@sprintf: called with zero arguments") - isa(args[1], String) || is_str_expr(args[1]) || + isa(args[1], AbstractString) || is_str_expr(args[1]) || error("@sprintf: first argument must be a format string") blk = _printf("@sprintf", :(IOBuffer()), args[1], args[2:end]) push!(blk.args, :(takebuf_string(out))) diff --git a/base/process.jl b/base/process.jl index ad96ce2304901..0194f8a828b40 100644 --- a/base/process.jl +++ b/base/process.jl @@ -88,7 +88,7 @@ const STDOUT_NO = 1 const STDERR_NO = 2 immutable FileRedirect - filename::String + filename::AbstractString append::Bool function FileRedirect(filename, append) if lowercase(filename) == (@unix? "/dev/null" : "nul") @@ -154,11 +154,11 @@ setenv(cmd::Cmd; dir="") = (cmd.dir = dir; cmd) (.>)(src::AbstractCmd, dest::Redirectable) = CmdRedirect(src, dest, STDERR_NO) # File redirects -(|>)(src::AbstractCmd, dest::String) = CmdRedirect(src, FileRedirect(dest, false), STDOUT_NO) -(|>)(src::String, dest::AbstractCmd) = CmdRedirect(dest, FileRedirect(src, false), STDIN_NO) -(.>)(src::AbstractCmd, dest::String) = CmdRedirect(src, FileRedirect(dest, false), STDERR_NO) -(>>)(src::AbstractCmd, dest::String) = CmdRedirect(src, FileRedirect(dest, true), STDOUT_NO) -(.>>)(src::AbstractCmd, dest::String) = CmdRedirect(src, FileRedirect(dest, true), STDERR_NO) +(|>)(src::AbstractCmd, dest::AbstractString) = CmdRedirect(src, FileRedirect(dest, false), STDOUT_NO) +(|>)(src::AbstractString, dest::AbstractCmd) = CmdRedirect(dest, FileRedirect(src, false), STDIN_NO) +(.>)(src::AbstractCmd, dest::AbstractString) = CmdRedirect(src, FileRedirect(dest, false), STDERR_NO) +(>>)(src::AbstractCmd, dest::AbstractString) = CmdRedirect(src, FileRedirect(dest, true), STDOUT_NO) +(.>>)(src::AbstractCmd, dest::AbstractString) = CmdRedirect(src, FileRedirect(dest, true), STDERR_NO) typealias RawOrBoxedHandle Union(UVHandle,UVStream,Redirectable,IOStream) @@ -423,7 +423,7 @@ end eachline(cmd::AbstractCmd) = eachline(cmd, DevNull) # return a (Pipe,Process) pair to write/read to/from the pipeline -function open(cmds::AbstractCmd, mode::String="r", stdio::AsyncStream=DevNull) +function open(cmds::AbstractCmd, mode::AbstractString="r", stdio::AsyncStream=DevNull) if mode == "r" processes = @tmp_rpipe out tmp spawn(false, cmds, (stdio,tmp,STDERR)) start_reading(out) @@ -467,7 +467,7 @@ function readall(cmd::AbstractCmd, stdin::AsyncStream=DevNull) return bytestring(readbytes(cmd, stdin)) end -function writeall(cmd::AbstractCmd, stdin::String, stdout::AsyncStream=DevNull) +function writeall(cmd::AbstractCmd, stdin::AbstractString, stdout::AsyncStream=DevNull) open(cmd, "w", stdout) do io write(io, stdin) end @@ -578,7 +578,7 @@ end ## implementation of `cmd` syntax ## arg_gen() = ByteString[] -arg_gen(x::String) = ByteString[x] +arg_gen(x::AbstractString) = ByteString[x] arg_gen(cmd::Cmd) = cmd.exec function arg_gen(head) diff --git a/base/random.jl b/base/random.jl index c40ac17e03599..52e8acc1ebbf1 100644 --- a/base/random.jl +++ b/base/random.jl @@ -92,7 +92,7 @@ function make_seed(n::Integer) end end -function make_seed(filename::String, n::Integer) +function make_seed(filename::AbstractString, n::Integer) open(filename) do io a = Array(Uint32, int(n)) read!(io, a) @@ -104,11 +104,11 @@ end srand(r::MersenneTwister) = srand(r, make_seed()) srand(r::MersenneTwister, n::Integer) = srand(r, make_seed(n)) -srand(r::MersenneTwister, filename::String, n::Integer=4) = srand(r, make_seed(filename, n)) +srand(r::MersenneTwister, filename::AbstractString, n::Integer=4) = srand(r, make_seed(filename, n)) srand() = srand(GLOBAL_RNG) srand(seed::Union(Integer, Vector{Uint32})) = srand(GLOBAL_RNG, seed) -srand(filename::String, n::Integer=4) = srand(GLOBAL_RNG, filename, n) +srand(filename::AbstractString, n::Integer=4) = srand(GLOBAL_RNG, filename, n) ## Global RNG @@ -862,7 +862,7 @@ randn(rng::MersenneTwister, dims::Int...) = randn!(rng, Array(Float64, dims...)) immutable UUID value::Uint128 end -UUID(u::String) = convert(UUID, u) +UUID(u::AbstractString) = convert(UUID, u) function uuid4() u = rand(Uint128) @@ -871,7 +871,7 @@ function uuid4() UUID(u) end -function Base.convert(::Type{UUID}, s::String) +function Base.convert(::Type{UUID}, s::AbstractString) s = lowercase(s) if !ismatch(r"^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$", s) diff --git a/base/regex.jl b/base/regex.jl index 8b84a23dcbaa1..c071570693434 100644 --- a/base/regex.jl +++ b/base/regex.jl @@ -12,7 +12,7 @@ type Regex ovec::Vector{Int32} - function Regex(pattern::String, options::Integer) + function Regex(pattern::AbstractString, options::Integer) pattern = bytestring(pattern) options = int32(options) if (options & ~PCRE.OPTIONS_MASK) != 0 @@ -28,7 +28,7 @@ type Regex end end -function Regex(pattern::String, flags::String) +function Regex(pattern::AbstractString, flags::AbstractString) options = DEFAULT_OPTS for f in flags options |= f=='i' ? PCRE.CASELESS : @@ -39,7 +39,7 @@ function Regex(pattern::String, flags::String) end Regex(pattern, options) end -Regex(pattern::String) = Regex(pattern, DEFAULT_OPTS) +Regex(pattern::AbstractString) = Regex(pattern, DEFAULT_OPTS) function compile(regex::Regex) if regex.regex == C_NULL @@ -101,7 +101,7 @@ function show(io::IO, m::RegexMatch) print(io, ")") end -function ismatch(r::Regex, s::String, offset::Integer=0) +function ismatch(r::Regex, s::AbstractString, offset::Integer=0) compile(r) return PCRE.exec(r.regex, r.extra, bytestring(s), offset, r.options & PCRE.EXECUTE_MASK, r.ovec) @@ -130,8 +130,8 @@ end match(re::Regex, str::Union(ByteString,SubString), idx::Integer, add_opts::Uint32=uint32(0)) = match(re, utf8(str), idx, add_opts) -match(r::Regex, s::String) = match(r, s, start(s)) -match(r::Regex, s::String, i::Integer) = +match(r::Regex, s::AbstractString) = match(r, s, start(s)) +match(r::Regex, s::AbstractString, i::Integer) = error("regex matching is only available for bytestrings; use bytestring(s) to convert") function matchall(re::Regex, str::UTF8String, overlap::Bool=false) @@ -186,16 +186,16 @@ function search(str::Union(ByteString,SubString), re::Regex, idx::Integer) PCRE.exec(re.regex, re.extra, str, idx-1, opts, re.ovec) ? ((re.ovec[1]+1):prevind(str,re.ovec[2]+1)) : (0:-1) end -search(s::String, r::Regex, idx::Integer) = +search(s::AbstractString, r::Regex, idx::Integer) = error("regex search is only available for bytestrings; use bytestring(s) to convert") -search(s::String, r::Regex) = search(s,r,start(s)) +search(s::AbstractString, r::Regex) = search(s,r,start(s)) immutable RegexMatchIterator regex::Regex string::UTF8String overlap::Bool - function RegexMatchIterator(regex::Regex, string::String, ovr::Bool=false) + function RegexMatchIterator(regex::Regex, string::AbstractString, ovr::Bool=false) new(regex, string, ovr) end end @@ -238,11 +238,11 @@ function next(itr::RegexMatchIterator, prev_match) (prev_match, nothing) end -function eachmatch(re::Regex, str::String, ovr::Bool=false) +function eachmatch(re::Regex, str::AbstractString, ovr::Bool=false) RegexMatchIterator(re,str,ovr) end -eachmatch(re::Regex, str::String) = RegexMatchIterator(re,str) +eachmatch(re::Regex, str::AbstractString) = RegexMatchIterator(re,str) # miscellaneous methods that depend on Regex being defined diff --git a/base/sharedarray.jl b/base/sharedarray.jl index 74139edc0bba5..b468329765667 100644 --- a/base/sharedarray.jl +++ b/base/sharedarray.jl @@ -5,7 +5,7 @@ type SharedArray{T,N} <: DenseArray{T,N} # The segname is currently used only in the test scripts to ensure that # the shmem segment has been unlinked. - segname::String + segname::AbstractString # Fields below are not to be serialized # Local shmem map. diff --git a/base/show.jl b/base/show.jl index 1cc14d1c07dd2..905a7c38874a2 100644 --- a/base/show.jl +++ b/base/show.jl @@ -248,7 +248,7 @@ const expr_parens = Dict(:tuple=>('(',')'), :vcat=>('[',']'), :cell1d=>("Any["," is_id_start_char(c::Char) = ccall(:jl_id_start_char, Cint, (Uint32,), c) != 0 is_id_char(c::Char) = ccall(:jl_id_char, Cint, (Uint32,), c) != 0 -function isidentifier(s::String) +function isidentifier(s::AbstractString) i = start(s) done(s, i) && return false (c, i) = next(s, i) @@ -588,7 +588,7 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int) print(io, "unless ") show_list(io, args, " goto ", indent) - elseif is(head, :string) && nargs == 1 && isa(args[1], String) + elseif is(head, :string) && nargs == 1 && isa(args[1], AbstractString) show(io, args[1]) elseif is(head, :null) @@ -601,7 +601,7 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int) elseif is(head, :string) a = map(args) do x - if !isa(x,String) + if !isa(x,AbstractString) if isa(x,Symbol) && !(x in quoted_syms) string("\$", x) else @@ -797,7 +797,7 @@ xdump(args...) = with_output_limit(()->xdump(xdump, STDOUT::IO, args...), true) # Here are methods specifically for dump: dump(io::IO, x, n::Int) = dump(io, x, n, "") dump(io::IO, x) = dump(io, x, 5, "") # default is 5 levels -dump(io::IO, x::String, n::Int, indent) = +dump(io::IO, x::AbstractString, n::Int, indent) = (print(io, typeof(x), " "); show(io, x); println(io)) dump(io::IO, x, n::Int, indent) = xdump(dump, io, x, n, indent) @@ -882,7 +882,7 @@ end function print_matrix_row(io::IO, X::AbstractVecOrMat, A::Vector, - i::Integer, cols::AbstractVector, sep::String + i::Integer, cols::AbstractVector, sep::AbstractString ) for k = 1:length(A) j = cols[k] @@ -902,7 +902,7 @@ function print_matrix_row(io::IO, end function print_matrix_vdots(io::IO, - vdots::String, A::Vector, sep::String, M::Integer, m::Integer + vdots::AbstractString, A::Vector, sep::AbstractString, M::Integer, m::Integer ) for k = 1:length(A) w = A[k][1] + A[k][2] @@ -919,12 +919,12 @@ end function print_matrix(io::IO, X::AbstractVecOrMat, sz::(Integer, Integer) = (s = tty_size(); (s[1]-4, s[2])), - pre::String = " ", - sep::String = " ", - post::String = "", - hdots::String = " \u2026 ", - vdots::String = "\u22ee", - ddots::String = " \u22f1 ", + pre::AbstractString = " ", + sep::AbstractString = " ", + post::AbstractString = "", + hdots::AbstractString = " \u2026 ", + vdots::AbstractString = "\u22ee", + ddots::AbstractString = " \u22f1 ", hmod::Integer = 5, vmod::Integer = 5) rows, cols = sz cols -= length(pre) + length(post) @@ -1165,7 +1165,7 @@ end function array_eltype_show_how(X) e = eltype(X) leaf = isleaftype(e) - plain = e<:Number || e<:String + plain = e<:Number || e<:AbstractString if isa(e,DataType) && e === e.name.primary str = string(e.name) else diff --git a/base/socket.jl b/base/socket.jl index 515e057b9e2eb..b7b2da554d79e 100644 --- a/base/socket.jl +++ b/base/socket.jl @@ -537,7 +537,7 @@ function getaddrinfo(cb::Function, host::ASCIIString) uv_error("getaddrinfo",ccall(:jl_getaddrinfo, Int32, (Ptr{Void}, Ptr{Uint8}, Ptr{Uint8}, Any), eventloop(), host, C_NULL, cb)) end -getaddrinfo(cb::Function, host::String) = getaddrinfo(cb,ascii(host)) +getaddrinfo(cb::Function, host::AbstractString) = getaddrinfo(cb,ascii(host)) function getaddrinfo(host::ASCIIString) c = Condition() @@ -548,7 +548,7 @@ function getaddrinfo(host::ASCIIString) isa(ip,UVError) && throw(ip) return ip::IPAddr end -getaddrinfo(host::String) = getaddrinfo(ascii(host)) +getaddrinfo(host::AbstractString) = getaddrinfo(ascii(host)) const _sizeof_uv_interface_address = ccall(:jl_uv_sizeof_interface_address,Int32,()) @@ -609,13 +609,13 @@ connect(sock::TCPSocket, port::Integer) = connect(sock,IPv4(127,0,0,1),port) connect(port::Integer) = connect(IPv4(127,0,0,1),port) # Valid connect signatures for TCP -connect(host::String, port::Integer) = connect(TCPSocket(),host,port) +connect(host::AbstractString, port::Integer) = connect(TCPSocket(),host,port) connect(addr::IPAddr, port::Integer) = connect(TCPSocket(),addr,port) connect(addr::InetAddr) = connect(TCPSocket(),addr) default_connectcb(sock,status) = nothing -function connect!(sock::TCPSocket, host::String, port::Integer) +function connect!(sock::TCPSocket, host::AbstractString, port::Integer) @assert sock.status == StatusInit ipaddr = getaddrinfo(host) sock.status = StatusInit diff --git a/base/stat.jl b/base/stat.jl index 06ed6157d1145..ed0b76743d345 100644 --- a/base/stat.jl +++ b/base/stat.jl @@ -48,8 +48,8 @@ end stat(fd::RawFD) = @stat_call jl_fstat Int32 fd.fd stat(fd::Integer) = @stat_call jl_fstat Int32 fd -stat(path::String) = @stat_call jl_stat Ptr{Uint8} path -lstat(path::String) = @stat_call jl_lstat Ptr{Uint8} path +stat(path::AbstractString) = @stat_call jl_stat Ptr{Uint8} path +lstat(path::AbstractString) = @stat_call jl_lstat Ptr{Uint8} path stat(path...) = stat(joinpath(path...)) lstat(path...) = lstat(joinpath(path...)) @@ -114,4 +114,4 @@ filesize(path...) = stat(path...).size ctime(path...) = stat(path...).ctime samefile(a::StatStruct, b::StatStruct) = a.device==b.device && a.inode==b.inode -samefile(a::String, b::String) = samefile(stat(a),stat(b)) +samefile(a::AbstractString, b::AbstractString) = samefile(stat(a),stat(b)) diff --git a/base/stream.jl b/base/stream.jl index 8cb6938e649d5..65fb93d721a48 100644 --- a/base/stream.jl +++ b/base/stream.jl @@ -817,16 +817,16 @@ end ## Libuv error handling ## type UVError <: Exception - prefix::String + prefix::AbstractString code::Int32 - UVError(p::String,code::Integer)=new(p,int32(code)) + UVError(p::AbstractString,code::Integer)=new(p,int32(code)) end struverror(err::UVError) = bytestring(ccall(:uv_strerror,Ptr{Uint8},(Int32,),err.code)) uverrorname(err::UVError) = bytestring(ccall(:uv_err_name,Ptr{Uint8},(Int32,),err.code)) uv_error(prefix::Symbol, c::Integer) = uv_error(string(prefix),c) -uv_error(prefix::String, c::Integer) = c < 0 ? throw(UVError(prefix,c)) : nothing +uv_error(prefix::AbstractString, c::Integer) = c < 0 ? throw(UVError(prefix,c)) : nothing show(io::IO, e::UVError) = print(io, e.prefix*": "*struverror(e)*" ("*uverrorname(e)*")") @@ -905,7 +905,7 @@ function connect!(sock::Pipe, path::ByteString) sock.status = StatusConnecting sock end -connect!(sock::Pipe, path::String) = connect(sock,bytestring(path)) +connect!(sock::Pipe, path::AbstractString) = connect(sock,bytestring(path)) function connect(sock::AsyncStream, args...) connect!(sock,args...) @@ -913,7 +913,7 @@ function connect(sock::AsyncStream, args...) sock end -connect(path::String) = connect(Pipe(),path) +connect(path::AbstractString) = connect(Pipe(),path) dup(x::RawFD) = RawFD(ccall((@windows? :_dup : :dup),Int32,(Int32,),x.fd)) dup(src::RawFD,target::RawFD) = systemerror("dup",-1== diff --git a/base/string.jl b/base/string.jl index e78bdaedd789e..ce0f0c1f58d79 100644 --- a/base/string.jl +++ b/base/string.jl @@ -9,16 +9,16 @@ println(xs...) = println(STDOUT, xs...) ## core string functions ## -endof(s::String) = error("you must implement endof(", typeof(s), ")") -next(s::String, i::Int) = error("you must implement next(", typeof(s), ",Int)") +endof(s::AbstractString) = error("you must implement endof(", typeof(s), ")") +next(s::AbstractString, i::Int) = error("you must implement next(", typeof(s), ",Int)") next(s::DirectIndexString, i::Int) = (s[i],i+1) -next(s::String, i::Integer) = next(s,int(i)) +next(s::AbstractString, i::Integer) = next(s,int(i)) ## conversion of general objects to strings ## function print_to_string(xs...) # specialized for performance reasons - s = IOBuffer(Array(Uint8,isa(xs[1],String) ? endof(xs[1]) : 0), true, true) + s = IOBuffer(Array(Uint8,isa(xs[1],AbstractString) ? endof(xs[1]) : 0), true, true) truncate(s,0) for x in xs print(s, x) @@ -27,12 +27,12 @@ function print_to_string(xs...) end string() = "" -string(s::String) = s +string(s::AbstractString) = s string(xs...) = print_to_string(xs...) bytestring() = "" bytestring(s::Array{Uint8,1}) = bytestring(pointer(s),length(s)) -bytestring(s::String...) = print_to_string(s...) +bytestring(s::AbstractString...) = print_to_string(s...) function bytestring(p::Union(Ptr{Uint8},Ptr{Int8})) p == C_NULL ? error("cannot convert NULL to string") : @@ -44,40 +44,40 @@ function bytestring(p::Union(Ptr{Uint8},Ptr{Int8}),len::Integer) ccall(:jl_pchar_to_string, ByteString, (Ptr{Uint8},Int), p, len) end -convert(::Type{Array{Uint8,1}}, s::String) = bytestring(s).data -convert(::Type{Array{Uint8}}, s::String) = bytestring(s).data -convert(::Type{ByteString}, s::String) = bytestring(s) -convert(::Type{Array{Char,1}}, s::String) = collect(s) -convert(::Type{Symbol}, s::String) = symbol(s) +convert(::Type{Array{Uint8,1}}, s::AbstractString) = bytestring(s).data +convert(::Type{Array{Uint8}}, s::AbstractString) = bytestring(s).data +convert(::Type{ByteString}, s::AbstractString) = bytestring(s) +convert(::Type{Array{Char,1}}, s::AbstractString) = collect(s) +convert(::Type{Symbol}, s::AbstractString) = symbol(s) ## generic supplied functions ## -start(s::String) = 1 -done(s::String,i) = (i > endof(s)) -getindex(s::String, i::Int) = next(s,i)[1] -getindex(s::String, i::Integer) = s[int(i)] -getindex(s::String, x::Real) = s[to_index(x)] -getindex{T<:Integer}(s::String, r::UnitRange{T}) = s[int(first(r)):int(last(r))] +start(s::AbstractString) = 1 +done(s::AbstractString,i) = (i > endof(s)) +getindex(s::AbstractString, i::Int) = next(s,i)[1] +getindex(s::AbstractString, i::Integer) = s[int(i)] +getindex(s::AbstractString, x::Real) = s[to_index(x)] +getindex{T<:Integer}(s::AbstractString, r::UnitRange{T}) = s[int(first(r)):int(last(r))] # TODO: handle other ranges with stride ±1 specially? -getindex(s::String, v::AbstractVector) = +getindex(s::AbstractString, v::AbstractVector) = sprint(length(v), io->(for i in v write(io,s[i]) end)) -symbol(s::String) = symbol(bytestring(s)) +symbol(s::AbstractString) = symbol(bytestring(s)) -print(io::IO, s::String) = (write(io, s); nothing) -write(io::IO, s::String) = (len = 0; for c in s; len += write(io, c); end; len) -show(io::IO, s::String) = print_quoted(io, s) +print(io::IO, s::AbstractString) = (write(io, s); nothing) +write(io::IO, s::AbstractString) = (len = 0; for c in s; len += write(io, c); end; len) +show(io::IO, s::AbstractString) = print_quoted(io, s) -sizeof(s::String) = error("type $(typeof(s)) has no canonical binary representation") +sizeof(s::AbstractString) = error("type $(typeof(s)) has no canonical binary representation") -eltype(::String) = Char -eltype{T<:String}(::Type{T}) = Char +eltype(::AbstractString) = Char +eltype{T<:AbstractString}(::Type{T}) = Char -(*)(s::String...) = string(s...) -(^)(s::String, r::Integer) = repeat(s,r) +(*)(s::AbstractString...) = string(s...) +(^)(s::AbstractString, r::Integer) = repeat(s,r) length(s::DirectIndexString) = endof(s) -function length(s::String) +function length(s::AbstractString) i = start(s) if done(s,i) return 0 @@ -94,7 +94,7 @@ function length(s::String) end isvalid(s::DirectIndexString, i::Integer) = (start(s) <= i <= endof(s)) -function isvalid(s::String, i::Integer) +function isvalid(s::AbstractString, i::Integer) i < 1 && return false done(s,i) && return false try @@ -110,7 +110,7 @@ prevind(s , i::Integer) = i-1 nextind(s::DirectIndexString, i::Integer) = i+1 nextind(s , i::Integer) = i+1 -function prevind(s::String, i::Integer) +function prevind(s::AbstractString, i::Integer) e = endof(s) if i > e return e @@ -125,7 +125,7 @@ function prevind(s::String, i::Integer) return 0 # out of range end -function nextind(s::String, i::Integer) +function nextind(s::AbstractString, i::Integer) e = endof(s) if i < 1 return 1 @@ -141,15 +141,15 @@ function nextind(s::String, i::Integer) next(s,e)[2] # out of range end -checkbounds(s::String, i::Integer) = start(s) <= i <= endof(s) || throw(BoundsError()) -checkbounds(s::String, i::Real) = checkbounds(s, to_index(i)) -checkbounds{T<:Integer}(s::String, r::Range{T}) = isempty(r) || (minimum(r) >= start(s) && maximum(r) <= endof(s)) || throw(BoundsError()) -checkbounds{T<:Real}(s::String, I::AbstractArray{T}) = all(i -> checkbounds(s, i), I) +checkbounds(s::AbstractString, i::Integer) = start(s) <= i <= endof(s) || throw(BoundsError()) +checkbounds(s::AbstractString, i::Real) = checkbounds(s, to_index(i)) +checkbounds{T<:Integer}(s::AbstractString, r::Range{T}) = isempty(r) || (minimum(r) >= start(s) && maximum(r) <= endof(s)) || throw(BoundsError()) +checkbounds{T<:Real}(s::AbstractString, I::AbstractArray{T}) = all(i -> checkbounds(s, i), I) ind2chr(s::DirectIndexString, i::Integer) = begin checkbounds(s,i); i end chr2ind(s::DirectIndexString, i::Integer) = begin checkbounds(s,i); i end -function ind2chr(s::String, i::Integer) +function ind2chr(s::AbstractString, i::Integer) s[i] # throws error if invalid j = 1 k = start(s) @@ -163,7 +163,7 @@ function ind2chr(s::String, i::Integer) end end -function chr2ind(s::String, i::Integer) +function chr2ind(s::AbstractString, i::Integer) i < start(s) && throw(BoundsError()) j = 1 k = start(s) @@ -179,7 +179,7 @@ end typealias Chars Union(Char,AbstractVector{Char},Set{Char}) -function search(s::String, c::Chars, i::Integer) +function search(s::AbstractString, c::Chars, i::Integer) if isempty(c) return 1 <= i <= nextind(s,endof(s)) ? i : error(BoundsError) @@ -196,9 +196,9 @@ function search(s::String, c::Chars, i::Integer) end return 0 end -search(s::String, c::Chars) = search(s,c,start(s)) +search(s::AbstractString, c::Chars) = search(s,c,start(s)) -in(c::Char, s::String) = (search(s,c)!=0) +in(c::Char, s::AbstractString) = (search(s,c)!=0) function _searchindex(s, t, i) if isempty(t) @@ -297,8 +297,8 @@ function _searchindex(s::Array, t::Array, i) end searchindex(s::Union(Array{Uint8,1},Array{Int8,1}),t::Union(Array{Uint8,1},Array{Int8,1}),i) = _searchindex(s,t,i) -searchindex(s::String, t::String, i::Integer) = _searchindex(s,t,i) -searchindex(s::String, t::String) = searchindex(s,t,start(s)) +searchindex(s::AbstractString, t::AbstractString, i::Integer) = _searchindex(s,t,i) +searchindex(s::AbstractString, t::AbstractString) = searchindex(s,t,start(s)) function searchindex(s::ByteString, t::ByteString, i::Integer=1) if length(t) == 1 @@ -317,7 +317,7 @@ function search(s::Union(Array{Uint8,1},Array{Int8,1}),t::Union(Array{Uint8,1},A end end -function search(s::String, t::String, i::Integer=start(s)) +function search(s::AbstractString, t::AbstractString, i::Integer=start(s)) idx = searchindex(s,t,i) if isempty(t) idx:idx-1 @@ -326,7 +326,7 @@ function search(s::String, t::String, i::Integer=start(s)) end end -function rsearch(s::String, c::Chars, i::Integer=endof(s)) +function rsearch(s::AbstractString, c::Chars, i::Integer=endof(s)) e = endof(s) j = search(RevString(s), c, e-i+1) j == 0 && return 0 @@ -429,8 +429,8 @@ function _rsearchindex(s::Array, t::Array, k) end rsearchindex(s::Union(Array{Uint8,1},Array{Int8,1}),t::Union(Array{Uint8,1},Array{Int8,1}),i) = _rsearchindex(s,t,i) -rsearchindex(s::String, t::String, i::Integer) = _rsearchindex(s,t,i) -rsearchindex(s::String, t::String) = (isempty(s) && isempty(t)) ? 1 : rsearchindex(s,t,endof(s)) +rsearchindex(s::AbstractString, t::AbstractString, i::Integer) = _rsearchindex(s,t,i) +rsearchindex(s::AbstractString, t::AbstractString) = (isempty(s) && isempty(t)) ? 1 : rsearchindex(s,t,endof(s)) function rsearchindex(s::ByteString, t::ByteString) if length(t) == 1 @@ -457,7 +457,7 @@ function rsearch(s::Union(Array{Uint8,1},Array{Int8,1}),t::Union(Array{Uint8,1}, end end -function rsearch(s::String, t::String, i::Integer=endof(s)) +function rsearch(s::AbstractString, t::AbstractString, i::Integer=endof(s)) idx = rsearchindex(s,t,i) if isempty(t) idx:idx-1 @@ -466,11 +466,11 @@ function rsearch(s::String, t::String, i::Integer=endof(s)) end end -contains(haystack::String, needle::String) = searchindex(haystack,needle)!=0 +contains(haystack::AbstractString, needle::AbstractString) = searchindex(haystack,needle)!=0 -in(::String, ::String) = error("use contains(x,y) for string containment") +in(::AbstractString, ::AbstractString) = error("use contains(x,y) for string containment") -function cmp(a::String, b::String) +function cmp(a::AbstractString, b::AbstractString) if a === b return 0 end @@ -487,12 +487,12 @@ function cmp(a::String, b::String) !done(a,i) && done(b,j) ? +1 : 0 end -==(a::String, b::String) = cmp(a,b) == 0 -isless(a::String, b::String) = cmp(a,b) < 0 +==(a::AbstractString, b::AbstractString) = cmp(a,b) == 0 +isless(a::AbstractString, b::AbstractString) = cmp(a,b) < 0 # begins with and ends with predicates -function beginswith(a::String, b::String) +function beginswith(a::AbstractString, b::AbstractString) i = start(a) j = start(b) while !done(a,i) && !done(b,i) @@ -502,9 +502,9 @@ function beginswith(a::String, b::String) end done(b,i) end -beginswith(str::String, chars::Chars) = !isempty(str) && str[start(str)] in chars +beginswith(str::AbstractString, chars::Chars) = !isempty(str) && str[start(str)] in chars -function endswith(a::String, b::String) +function endswith(a::AbstractString, b::AbstractString) i = endof(a) j = endof(b) a1 = start(a) @@ -518,7 +518,7 @@ function endswith(a::String, b::String) end j < b1 end -endswith(str::String, chars::Chars) = !isempty(str) && str[end] in chars +endswith(str::AbstractString, chars::Chars) = !isempty(str) && str[end] in chars # faster comparisons for byte strings and symbols @@ -537,18 +537,18 @@ beginswith(a::Array{Uint8,1}, b::Array{Uint8,1}) = ## character column width function ## charwidth(c::Char) = max(0,int(ccall(:wcwidth, Int32, (Uint32,), c))) -strwidth(s::String) = (w=0; for c in s; w += charwidth(c); end; w) +strwidth(s::AbstractString) = (w=0; for c in s; w += charwidth(c); end; w) strwidth(s::ByteString) = int(ccall(:u8_strwidth, Csize_t, (Ptr{Uint8},), s.data)) # TODO: implement and use u8_strnwidth that takes a length argument isascii(c::Char) = c < char(0x80) -isascii(s::String) = all(isascii, s) +isascii(s::AbstractString) = all(isascii, s) isascii(s::ASCIIString) = true ## generic string uses only endof and next ## -immutable GenericString <: String - string::String +immutable GenericString <: AbstractString + string::AbstractString end endof(s::GenericString) = endof(s.string) @@ -556,7 +556,7 @@ next(s::GenericString, i::Int) = next(s.string, i) ## substrings reference original strings ## -immutable SubString{T<:String} <: String +immutable SubString{T<:AbstractString} <: AbstractString string::T offset::Int endof::Int @@ -578,10 +578,10 @@ immutable SubString{T<:String} <: String end end end -SubString{T<:String}(s::T, i::Int, j::Int) = SubString{T}(s, i, j) +SubString{T<:AbstractString}(s::T, i::Int, j::Int) = SubString{T}(s, i, j) SubString(s::SubString, i::Int, j::Int) = SubString(s.string, s.offset+i, s.offset+j) -SubString(s::String, i::Integer, j::Integer) = SubString(s, int(i), int(j)) -SubString(s::String, i::Integer) = SubString(s, i, endof(s)) +SubString(s::AbstractString, i::Integer, j::Integer) = SubString(s, int(i), int(j)) +SubString(s::AbstractString, i::Integer) = SubString(s, i, endof(s)) write{T<:ByteString}(to::IOBuffer, s::SubString{T}) = s.endof==0 ? 0 : write_sub(to, s.string.data, s.offset+1, next(s,s.endof)[2]-1) @@ -629,7 +629,7 @@ chr2ind{T<:DirectIndexString}(s::SubString{T}, i::Integer) = begin checkbounds(s nextind(s::SubString, i::Integer) = nextind(s.string, i+s.offset)-s.offset prevind(s::SubString, i::Integer) = prevind(s.string, i+s.offset)-s.offset -convert{T<:String}(::Type{SubString{T}}, s::T) = SubString(s, 1, endof(s)) +convert{T<:AbstractString}(::Type{SubString{T}}, s::T) = SubString(s, 1, endof(s)) bytestring{T <: ByteString}(p::SubString{T}) = bytestring(pointer(p.string.data)+p.offset, nextind(p, p.endof)-1) @@ -638,7 +638,7 @@ function serialize{T}(s, ss::SubString{T}) invoke(serialize, (Any,Any), s, convert(SubString{T}, convert(T,ss))) end -function getindex(s::String, r::UnitRange{Int}) +function getindex(s::AbstractString, r::UnitRange{Int}) if first(r) < 1 || endof(s) < last(r) error(BoundsError) end @@ -663,12 +663,12 @@ function hash{T<:ByteString}(s::Union(T,SubString{T}), h::Uint) h += memhash_seed ccall(memhash, Uint, (Ptr{Uint8}, Csize_t, Uint32), s, sizeof(s), h % Uint32) + h end -hash(s::String, h::Uint) = hash(bytestring(s), h) +hash(s::AbstractString, h::Uint) = hash(bytestring(s), h) ## efficient representation of repeated strings ## -immutable RepString <: String - string::String +immutable RepString <: AbstractString + string::AbstractString repeat::Integer end @@ -697,14 +697,14 @@ function next(s::RepString, i::Int) c, k-j+i end -function repeat(s::String, r::Integer) +function repeat(s::AbstractString, r::Integer) r < 0 ? error("can't repeat a string ",r," times") : r == 0 ? "" : r == 1 ? s : RepString(s,r) end -convert(::Type{RepString}, s::String) = RepString(s,1) +convert(::Type{RepString}, s::AbstractString) = RepString(s,1) function repeat(s::ByteString, r::Integer) if r < 0 @@ -720,7 +720,7 @@ end ## reversed strings without data movement ## -immutable RevString{T<:String} <: String +immutable RevString{T<:AbstractString} <: AbstractString string::T end @@ -733,16 +733,16 @@ function next(s::RevString, i::Int) (s.string[j], n-prevind(s.string,j)+1) end -reverse(s::String) = RevString(s) +reverse(s::AbstractString) = RevString(s) reverse(s::RevString) = s.string isascii(s::RevString{ASCIIString}) = true ## ropes for efficient concatenation, etc. ## -immutable RopeString <: String - head::String - tail::String +immutable RopeString <: AbstractString + head::AbstractString + tail::AbstractString depth::Int32 endof::Int @@ -751,22 +751,22 @@ immutable RopeString <: String RopeString(h.head, RopeString(h.tail, t)) : new(h, t, max(h.depth,t.depth)+1, endof(h)+endof(t)) - RopeString(h::RopeString, t::String) = + RopeString(h::RopeString, t::AbstractString) = strdepth(h.tail) < strdepth(h.head) ? RopeString(h.head, RopeString(h.tail, t)) : new(h, t, h.depth+1, endof(h)+endof(t)) - RopeString(h::String, t::RopeString) = + RopeString(h::AbstractString, t::RopeString) = strdepth(t.head) < strdepth(t.tail) ? RopeString(RopeString(h, t.head), t.tail) : new(h, t, t.depth+1, endof(h)+endof(t)) - RopeString(h::String, t::String) = + RopeString(h::AbstractString, t::AbstractString) = new(h, t, 1, endof(h)+endof(t)) end -RopeString(s::String) = RopeString(s,"") +RopeString(s::AbstractString) = RopeString(s,"") -strdepth(s::String) = 0 +strdepth(s::AbstractString) = 0 strdepth(s::RopeString) = s.depth function next(s::RopeString, i::Int) @@ -790,35 +790,35 @@ sizeof(s::RopeString) = sizeof(s.head) + sizeof(s.tail) uppercase(c::Char) = convert(Char, ccall(:towupper, Cwchar_t, (Cwchar_t,), c)) lowercase(c::Char) = convert(Char, ccall(:towlower, Cwchar_t, (Cwchar_t,), c)) -uppercase(s::String) = map(uppercase, s) -lowercase(s::String) = map(lowercase, s) +uppercase(s::AbstractString) = map(uppercase, s) +lowercase(s::AbstractString) = map(lowercase, s) -function ucfirst(s::String) +function ucfirst(s::AbstractString) isempty(s) || isupper(s[1]) ? s : string(uppercase(s[1]),s[nextind(s,1):end]) end -function lcfirst(s::String) +function lcfirst(s::AbstractString) isempty(s) || islower(s[1]) ? s : string(lowercase(s[1]),s[nextind(s,1):end]) end ## string map, filter, has ## -map_result(s::String, a::Vector{Uint8}) = UTF8String(a) +map_result(s::AbstractString, a::Vector{Uint8}) = UTF8String(a) map_result(s::Union(ASCIIString,SubString{ASCIIString}), a::Vector{Uint8}) = bytestring(a) -function map(f::Function, s::String) +function map(f::Function, s::AbstractString) out = IOBuffer(Array(Uint8,endof(s)),true,true) truncate(out,0) for c in s c2 = f(c) if !isa(c2,Char) - error("map(f,s::String) requires f to return Char; try map(f,collect(s)) or a comprehension instead") + error("map(f,s::AbstractString) requires f to return Char; try map(f,collect(s)) or a comprehension instead") end write(out, c2::Char) end map_result(s, takebuf_array(out)) end -function filter(f::Function, s::String) +function filter(f::Function, s::AbstractString) out = IOBuffer(Array(Uint8,endof(s)),true,true) truncate(out,0) for c in s @@ -831,13 +831,13 @@ end ## string promotion rules ## -promote_rule{S<:String,T<:String}(::Type{S}, ::Type{T}) = UTF8String +promote_rule{S<:AbstractString,T<:AbstractString}(::Type{S}, ::Type{T}) = UTF8String ## printing literal quoted string data ## # this is the inverse of print_unescaped_chars(io, s, "\\\") -function print_quoted_literal(io, s::String) +function print_quoted_literal(io, s::AbstractString) print(io, '"') for c = s; c == '"' ? print(io, "\\\"") : print(io, c); end print(io, '"') @@ -845,14 +845,14 @@ end ## string escaping & unescaping ## -escape_nul(s::String, i::Int) = +escape_nul(s::AbstractString, i::Int) = !done(s,i) && '0' <= next(s,i)[1] <= '7' ? "\\x00" : "\\0" isxdigit(c::Char) = '0'<=c<='9' || 'a'<=c<='f' || 'A'<=c<='F' -isxdigit(s::String) = all(isxdigit, s) -need_full_hex(s::String, i::Int) = !done(s,i) && isxdigit(next(s,i)[1]) +isxdigit(s::AbstractString) = all(isxdigit, s) +need_full_hex(s::AbstractString, i::Int) = !done(s,i) && isxdigit(next(s,i)[1]) -function print_escaped(io, s::String, esc::String) +function print_escaped(io, s::AbstractString, esc::AbstractString) i = start(s) while !done(s,i) c, j = next(s,i) @@ -869,8 +869,8 @@ function print_escaped(io, s::String, esc::String) end end -escape_string(s::String) = sprint(endof(s), print_escaped, s, "\"") -function print_quoted(io, s::String) +escape_string(s::AbstractString) = sprint(endof(s), print_escaped, s, "\"") +function print_quoted(io, s::AbstractString) print(io, '"') print_escaped(io, s, "\"\$") #"# work around syntax highlighting problem print(io, '"') @@ -878,7 +878,7 @@ end # bare minimum unescaping function unescapes only given characters -function print_unescaped_chars(io, s::String, esc::String) +function print_unescaped_chars(io, s::AbstractString, esc::AbstractString) if !('\\' in esc) esc = string("\\", esc) end @@ -892,12 +892,12 @@ function print_unescaped_chars(io, s::String, esc::String) end end -unescape_chars(s::String, esc::String) = +unescape_chars(s::AbstractString, esc::AbstractString) = sprint(endof(s), print_unescaped_chars, s, esc) # general unescaping of traditional C and Unicode escape sequences -function print_unescaped(io, s::String) +function print_unescaped(io, s::AbstractString) i = start(s) while !done(s,i) c, i = next(s,i) @@ -950,7 +950,7 @@ function print_unescaped(io, s::String) end end -unescape_string(s::String) = sprint(endof(s), print_unescaped, s) +unescape_string(s::AbstractString) = sprint(endof(s), print_unescaped, s) ## checking UTF-8 & ACSII validity ## @@ -973,7 +973,7 @@ function blank_width(c::Char) end # width of leading blank space, also check if string is blank -function indentation(s::String) +function indentation(s::AbstractString) count = 0 for c in s if c == ' ' || c == '\t' @@ -985,7 +985,7 @@ function indentation(s::String) count, true end -function unindent(s::String, indent::Int) +function unindent(s::AbstractString, indent::Int) indent == 0 && return s buf = IOBuffer(Array(Uint8,endof(s)), true, true) truncate(buf,0) @@ -1064,7 +1064,7 @@ macro mstr(s...); triplequoted(s...); end ## shell-like command parsing ## -function shell_parse(raw::String, interp::Bool) +function shell_parse(raw::AbstractString, interp::Bool) s = strip(raw) last_parse = 0:-1 isempty(s) && return interp ? (Expr(:tuple,:()),last_parse) : ([],last_parse) @@ -1078,7 +1078,7 @@ function shell_parse(raw::String, interp::Bool) j = i function update_arg(x) - if !isa(x,String) || !isempty(x) + if !isa(x,AbstractString) || !isempty(x) push!(arg, x) end end @@ -1159,18 +1159,18 @@ function shell_parse(raw::String, interp::Bool) end (ex,last_parse) end -shell_parse(s::String) = shell_parse(s,true) +shell_parse(s::AbstractString) = shell_parse(s,true) -function shell_split(s::String) +function shell_split(s::AbstractString) parsed = shell_parse(s,false)[1] - args = String[] + args = AbstractString[] for arg in parsed push!(args, string(arg...)) end args end -function print_shell_word(io::IO, word::String) +function print_shell_word(io::IO, word::AbstractString) if isempty(word) print(io, "''") end @@ -1200,7 +1200,7 @@ function print_shell_word(io::IO, word::String) end end -function print_shell_escaped(io::IO, cmd::String, args::String...) +function print_shell_escaped(io::IO, cmd::AbstractString, args::AbstractString...) print_shell_word(io, cmd) for arg in args print(io, ' ') @@ -1209,11 +1209,11 @@ function print_shell_escaped(io::IO, cmd::String, args::String...) end print_shell_escaped(io::IO) = nothing -shell_escape(args::String...) = sprint(print_shell_escaped, args...) +shell_escape(args::AbstractString...) = sprint(print_shell_escaped, args...) ## interface to parser ## -function parse(str::String, pos::Int; greedy::Bool=true, raise::Bool=true) +function parse(str::AbstractString, pos::Int; greedy::Bool=true, raise::Bool=true) # returns (expr, end_pos). expr is () in case of parse error. ex, pos = ccall(:jl_parse_string, Any, (Ptr{Uint8}, Int32, Int32), @@ -1231,7 +1231,7 @@ function parse(str::String, pos::Int; greedy::Bool=true, raise::Bool=true) ex, pos+1 # C is zero-based, Julia is 1-based end -function parse(str::String; raise::Bool=true) +function parse(str::AbstractString; raise::Bool=true) ex, pos = parse(str, start(str), greedy=true, raise=raise) if isa(ex,Expr) && ex.head === :error return ex @@ -1245,7 +1245,7 @@ end ## miscellaneous string functions ## -function lpad(s::String, n::Integer, p::String=" ") +function lpad(s::AbstractString, n::Integer, p::AbstractString=" ") m = n - strwidth(s) if m <= 0; return s; end l = strwidth(p) @@ -1257,7 +1257,7 @@ function lpad(s::String, n::Integer, p::String=" ") bytestring(p^q*p[1:chr2ind(p,r)]*s) end -function rpad(s::String, n::Integer, p::String=" ") +function rpad(s::AbstractString, n::Integer, p::AbstractString=" ") m = n - strwidth(s) if m <= 0; return s; end l = strwidth(p) @@ -1274,11 +1274,11 @@ rpad(s, n::Integer, p=" ") = rpad(string(s),n,string(p)) cpad(s, n::Integer, p=" ") = rpad(lpad(s,div(n+strwidth(s),2),p),n,p) -# splitter can be a Char, Vector{Char}, String, Regex, ... -# any splitter that provides search(s::String, splitter) +# splitter can be a Char, Vector{Char}, AbstractString, Regex, ... +# any splitter that provides search(s::AbstractString, splitter) split{T<:SubString}(str::T, splitter; limit::Integer=0, keep::Bool=true) = _split(str, splitter, limit, keep, T[]) -split{T<:String}(str::T, splitter; limit::Integer=0, keep::Bool=true) = _split(str, splitter, limit, keep, SubString{T}[]) -function _split{T<:String,U<:Array}(str::T, splitter, limit::Integer, keep_empty::Bool, strs::U) +split{T<:AbstractString}(str::T, splitter; limit::Integer=0, keep::Bool=true) = _split(str, splitter, limit, keep, SubString{T}[]) +function _split{T<:AbstractString,U<:Array}(str::T, splitter, limit::Integer, keep_empty::Bool, strs::U) i = start(str) n = endof(str) r = search(str,splitter,i) @@ -1302,11 +1302,11 @@ end # a bit oddball, but standard behavior in Perl, Ruby & Python: const _default_delims = [' ','\t','\n','\v','\f','\r'] -split(str::String) = split(str, _default_delims; limit=0, keep=false) +split(str::AbstractString) = split(str, _default_delims; limit=0, keep=false) rsplit{T<:SubString}(str::T, splitter; limit::Integer=0, keep::Bool=true) = _rsplit(str, splitter, limit, keep, T[]) -rsplit{T<:String}(str::T, splitter ; limit::Integer=0, keep::Bool=true) = _rsplit(str, splitter, limit, keep, SubString{T}[]) -function _rsplit{T<:String,U<:Array}(str::T, splitter, limit::Integer, keep_empty::Bool, strs::U) +rsplit{T<:AbstractString}(str::T, splitter ; limit::Integer=0, keep::Bool=true) = _rsplit(str, splitter, limit, keep, SubString{T}[]) +function _rsplit{T<:AbstractString,U<:Array}(str::T, splitter, limit::Integer, keep_empty::Bool, strs::U) i = start(str) n = endof(str) r = rsearch(str,splitter) @@ -1325,7 +1325,7 @@ function _rsplit{T<:String,U<:Array}(str::T, splitter, limit::Integer, keep_empt (keep_empty || (n > 0)) && unshift!(strs, SubString(str,1,n)) return strs end -#rsplit(str::String) = rsplit(str, _default_delims, 0, false) +#rsplit(str::AbstractString) = rsplit(str, _default_delims, 0, false) function replace(str::ByteString, pattern, repl::Function, limit::Integer) n = 1 @@ -1356,9 +1356,9 @@ function replace(str::ByteString, pattern, repl::Function, limit::Integer) write(out, SubString(str,i)) takebuf_string(out) end -replace(s::String, pat, f::Function, n::Integer) = replace(bytestring(s), pat, f, n) -replace(s::String, pat, r, n::Integer) = replace(s, pat, x->r, n) -replace(s::String, pat, r) = replace(s, pat, r, 0) +replace(s::AbstractString, pat, f::Function, n::Integer) = replace(bytestring(s), pat, f, n) +replace(s::AbstractString, pat, r, n::Integer) = replace(s, pat, x->r, n) +replace(s::AbstractString, pat, r) = replace(s, pat, r, 0) function print_joined(io, strings, delim, last) i = start(strings) @@ -1388,9 +1388,9 @@ print_joined(io, strings) = print_joined(io, strings, "") join(args...) = sprint(print_joined, args...) -chop(s::String) = s[1:end-1] +chop(s::AbstractString) = s[1:end-1] -function chomp(s::String) +function chomp(s::AbstractString) i = endof(s) if (i < 1 || s[i] != '\n') return s end j = prevind(s,i) @@ -1409,9 +1409,9 @@ function chomp!(s::ByteString) end return s end -chomp!(s::String) = chomp(s) # copying fallback for other string types +chomp!(s::AbstractString) = chomp(s) # copying fallback for other string types -function lstrip(s::String, chars::Chars=_default_delims) +function lstrip(s::AbstractString, chars::Chars=_default_delims) i = start(s) while !done(s,i) c, j = next(s,i) @@ -1423,7 +1423,7 @@ function lstrip(s::String, chars::Chars=_default_delims) "" end -function rstrip(s::String, chars::Chars=_default_delims) +function rstrip(s::AbstractString, chars::Chars=_default_delims) r = RevString(s) i = start(r) while !done(r,i) @@ -1436,8 +1436,8 @@ function rstrip(s::String, chars::Chars=_default_delims) "" end -strip(s::String) = lstrip(rstrip(s)) -strip(s::String, chars::Chars) = lstrip(rstrip(s, chars), chars) +strip(s::AbstractString) = lstrip(rstrip(s)) +strip(s::AbstractString, chars::Chars) = lstrip(rstrip(s, chars), chars) ## string to integer functions ## @@ -1452,14 +1452,14 @@ end parseint{T<:Integer}(::Type{T}, c::Char, base::Integer) = convert(T,parseint(c,base)) parseint{T<:Integer}(::Type{T}, c::Char) = convert(T,parseint(c)) -function parseint_next(s::String, i::Int=start(s)) +function parseint_next(s::AbstractString, i::Int=start(s)) done(s,i) && error("premature end of integer: $(repr(s))") j = i c, i = next(s,i) c, i, j end -function parseint_preamble(signed::Bool, s::String, base::Int) +function parseint_preamble(signed::Bool, s::AbstractString, base::Int) c, i, j = parseint_next(s) while isspace(c) c, i, j = parseint_next(s,i) @@ -1488,7 +1488,7 @@ function parseint_preamble(signed::Bool, s::String, base::Int) return sgn, base, j end -function parseint_nocheck{T<:Integer}(::Type{T}, s::String, base::Int, a::Int) +function parseint_nocheck{T<:Integer}(::Type{T}, s::AbstractString, base::Int, a::Int) sgn, base, i = parseint_preamble(T<:Signed,s,base) c, i = parseint_next(s,i) base = convert(T,base) @@ -1527,29 +1527,29 @@ function parseint_nocheck{T<:Integer}(::Type{T}, s::String, base::Int, a::Int) end return n end -parseint_nocheck{T<:Integer}(::Type{T}, s::String, base::Int) = +parseint_nocheck{T<:Integer}(::Type{T}, s::AbstractString, base::Int) = parseint_nocheck(T, s, base, base <= 36 ? 10 : 36) -parseint{T<:Integer}(::Type{T}, s::String, base::Integer) = +parseint{T<:Integer}(::Type{T}, s::AbstractString, base::Integer) = 2 <= base <= 62 ? parseint_nocheck(T,s,int(base)) : error("invalid base: $base") -parseint{T<:Integer}(::Type{T}, s::String) = parseint_nocheck(T,s,0) -parseint(s::String, base::Integer) = parseint(Int,s,base) -parseint(s::String) = parseint_nocheck(Int,s,0) - -integer (s::String) = int(s) -unsigned(s::String) = uint(s) -int (s::String) = parseint(Int,s) -uint (s::String) = parseint(Uint,s) -int8 (s::String) = parseint(Int8,s) -uint8 (s::String) = parseint(Uint8,s) -int16 (s::String) = parseint(Int16,s) -uint16 (s::String) = parseint(Uint16,s) -int32 (s::String) = parseint(Int32,s) -uint32 (s::String) = parseint(Uint32,s) -int64 (s::String) = parseint(Int64,s) -uint64 (s::String) = parseint(Uint64,s) -int128 (s::String) = parseint(Int128,s) -uint128 (s::String) = parseint(Uint128,s) +parseint{T<:Integer}(::Type{T}, s::AbstractString) = parseint_nocheck(T,s,0) +parseint(s::AbstractString, base::Integer) = parseint(Int,s,base) +parseint(s::AbstractString) = parseint_nocheck(Int,s,0) + +integer (s::AbstractString) = int(s) +unsigned(s::AbstractString) = uint(s) +int (s::AbstractString) = parseint(Int,s) +uint (s::AbstractString) = parseint(Uint,s) +int8 (s::AbstractString) = parseint(Int8,s) +uint8 (s::AbstractString) = parseint(Uint8,s) +int16 (s::AbstractString) = parseint(Int16,s) +uint16 (s::AbstractString) = parseint(Uint16,s) +int32 (s::AbstractString) = parseint(Int32,s) +uint32 (s::AbstractString) = parseint(Uint32,s) +int64 (s::AbstractString) = parseint(Int64,s) +uint64 (s::AbstractString) = parseint(Uint64,s) +int128 (s::AbstractString) = parseint(Int128,s) +uint128 (s::AbstractString) = parseint(Uint128,s) ## stringifying integers more efficiently ## @@ -1557,9 +1557,9 @@ string(x::Union(Int8,Int16,Int32,Int64,Int128)) = dec(x) ## string to float functions ## -float64_isvalid(s::String, out::Array{Float64,1}) = +float64_isvalid(s::AbstractString, out::Array{Float64,1}) = ccall(:jl_strtod, Int32, (Ptr{Uint8},Ptr{Float64}), s, out) == 0 -float32_isvalid(s::String, out::Array{Float32,1}) = +float32_isvalid(s::AbstractString, out::Array{Float32,1}) = ccall(:jl_strtof, Int32, (Ptr{Uint8},Ptr{Float32}), s, out) == 0 float64_isvalid(s::SubString, out::Array{Float64,1}) = @@ -1571,30 +1571,30 @@ begin local tmp::Array{Float64,1} = Array(Float64,1) local tmpf::Array{Float32,1} = Array(Float32,1) global float64, float32 - function float64(s::String) + function float64(s::AbstractString) if !float64_isvalid(s, tmp) - throw(ArgumentError("float64(String): invalid number format")) + throw(ArgumentError("float64(AbstractString): invalid number format")) end return tmp[1] end - function float32(s::String) + function float32(s::AbstractString) if !float32_isvalid(s, tmpf) - throw(ArgumentError("float32(String): invalid number format")) + throw(ArgumentError("float32(AbstractString): invalid number format")) end return tmpf[1] end end -float(x::String) = float64(x) -parsefloat(x::String) = float64(x) -parsefloat(::Type{Float64}, x::String) = float64(x) -parsefloat(::Type{Float32}, x::String) = float32(x) +float(x::AbstractString) = float64(x) +parsefloat(x::AbstractString) = float64(x) +parsefloat(::Type{Float64}, x::AbstractString) = float64(x) +parsefloat(::Type{Float32}, x::AbstractString) = float32(x) for conv in (:float, :float32, :float64, :int, :int8, :int16, :int32, :int64, :uint, :uint8, :uint16, :uint32, :uint64) - @eval ($conv){S<:String}(a::AbstractArray{S}) = map($conv, a) + @eval ($conv){S<:AbstractString}(a::AbstractArray{S}) = map($conv, a) end # find the index of the first occurrence of a value in a byte array diff --git a/base/sysinfo.jl b/base/sysinfo.jl index 23debdbaf5017..5930f3abe02f7 100644 --- a/base/sysinfo.jl +++ b/base/sysinfo.jl @@ -56,7 +56,7 @@ CPUinfo(info::UV_cpu_info_t) = CPUinfo(bytestring(info.model), info.speed, info.cpu_times!user, info.cpu_times!nice, info.cpu_times!sys, info.cpu_times!idle, info.cpu_times!irq) -function show(io::IO, info::CPUinfo, header::Bool=true, prefix::String=" ") +function show(io::IO, info::CPUinfo, header::Bool=true, prefix::AbstractString=" ") tck = SC_CLK_TCK if header println(io, info.model, ": ") @@ -167,7 +167,7 @@ const shlib_ext = dlext end # This callback function called by dl_iterate_phdr() on Linux - function dl_phdr_info_callback( di_ptr::Ptr{dl_phdr_info}, size::Csize_t, dynamic_libraries_ptr::Ptr{Array{String,1}} ) + function dl_phdr_info_callback( di_ptr::Ptr{dl_phdr_info}, size::Csize_t, dynamic_libraries_ptr::Ptr{Array{AbstractString,1}} ) di = unsafe_load(di_ptr) # Skip over objects without a path (as they represent this own object) @@ -181,10 +181,10 @@ const shlib_ext = dlext end #@linux_only function dllist() - dynamic_libraries = Array(String,0) + dynamic_libraries = Array(AbstractString,0) @linux_only begin - const callback = cfunction(dl_phdr_info_callback, Cint, (Ptr{dl_phdr_info}, Csize_t, Ptr{Array{String,1}} )) + const callback = cfunction(dl_phdr_info_callback, Cint, (Ptr{dl_phdr_info}, Csize_t, Ptr{Array{AbstractString,1}} )) ccall( cglobal("dl_iterate_phdr"), Cint, (Ptr{Void}, Ptr{Void}), callback, pointer_from_objref(dynamic_libraries) ) end @@ -212,7 +212,7 @@ function dlpath( handle::Ptr{Void} ) return s end -function dlpath{T<:Union(String, Symbol)}(libname::T) +function dlpath{T<:Union(AbstractString, Symbol)}(libname::T) handle = dlopen(libname) path = dlpath(handle) dlclose(handle) diff --git a/base/utf16.jl b/base/utf16.jl index d775fe189d879..cb093cca8effe 100644 --- a/base/utf16.jl +++ b/base/utf16.jl @@ -1,4 +1,4 @@ -immutable UTF16String <: String +immutable UTF16String <: AbstractString data::Array{Uint16,1} # includes 16-bit NULL termination after string chars function UTF16String(data::Vector{Uint16}) if length(data) < 1 || data[end] != 0 @@ -29,7 +29,7 @@ function next(s::UTF16String, i::Int) end # TODO: optmize this -function encode16(s::String) +function encode16(s::AbstractString) buf = Uint16[] for ch in s c = reinterpret(Uint32, ch) @@ -46,7 +46,7 @@ end utf16(x) = convert(UTF16String, x) convert(::Type{UTF16String}, s::UTF16String) = s -convert(::Type{UTF16String}, s::String) = encode16(s) +convert(::Type{UTF16String}, s::AbstractString) = encode16(s) convert(::Type{Array{Uint16,1}}, s::UTF16String) = s.data convert(::Type{Array{Uint16}}, s::UTF16String) = s.data diff --git a/base/utf32.jl b/base/utf32.jl index 3ed60425838fb..6dee962c930dd 100644 --- a/base/utf32.jl +++ b/base/utf32.jl @@ -28,7 +28,7 @@ utf32(x) = convert(UTF32String, x) convert(::Type{UTF32String}, c::Char) = UTF32String(Char[c, char(0)]) convert(::Type{UTF32String}, s::UTF32String) = s -function convert(::Type{UTF32String}, s::String) +function convert(::Type{UTF32String}, s::AbstractString) a = Array(Char, length(s) + 1) i = 0 for c in s @@ -48,7 +48,7 @@ end convert{T<:Union(Int32,Uint32)}(::Type{UTF32String}, data::AbstractVector{T}) = convert(UTF32String, reinterpret(Char, data)) -convert{T<:String}(::Type{T}, v::AbstractVector{Char}) = convert(T, utf32(v)) +convert{T<:AbstractString}(::Type{T}, v::AbstractVector{Char}) = convert(T, utf32(v)) # specialize for performance reasons: function convert{T<:ByteString}(::Type{T}, data::AbstractVector{Char}) @@ -106,7 +106,7 @@ function map(f::Function, s::UTF32String) for i = 1:(length(d)-1) c2 = f(d[i]) if !isa(c2, Char) - error("map(f,s::String) requires f to return Char; try map(f,collect(s)) or a comprehension instead") + error("map(f,s::AbstractString) requires f to return Char; try map(f,collect(s)) or a comprehension instead") end out[i] = (c2::Char) end diff --git a/base/utf8.jl b/base/utf8.jl index e44e15e5737a2..0faac7066f713 100644 --- a/base/utf8.jl +++ b/base/utf8.jl @@ -1,6 +1,6 @@ ## from base/boot.jl: # -# immutable UTF8String <: String +# immutable UTF8String <: AbstractString # data::Array{Uint8,1} # end # @@ -161,7 +161,7 @@ utf8(x) = convert(UTF8String, x) convert(::Type{UTF8String}, s::UTF8String) = s convert(::Type{UTF8String}, s::ASCIIString) = UTF8String(s.data) convert(::Type{UTF8String}, a::Array{Uint8,1}) = is_valid_utf8(a) ? UTF8String(a) : error("invalid UTF-8 sequence") -function convert(::Type{UTF8String}, a::Array{Uint8,1}, invalids_as::String) +function convert(::Type{UTF8String}, a::Array{Uint8,1}, invalids_as::AbstractString) l = length(a) idx = 1 iscopy = false @@ -182,7 +182,7 @@ function convert(::Type{UTF8String}, a::Array{Uint8,1}, invalids_as::String) end UTF8String(a) end -convert(::Type{UTF8String}, s::String) = utf8(bytestring(s)) +convert(::Type{UTF8String}, s::AbstractString) = utf8(bytestring(s)) # The last case is the replacement character 0xfffd (3 bytes) utf8sizeof(c::Char) = c < char(0x80) ? 1 : c < char(0x800) ? 2 : c < char(0x10000) ? 3 : c < char(0x110000) ? 4 : 3 diff --git a/base/utf8proc.jl b/base/utf8proc.jl index f4669640ec2e9..53d11a8f02b41 100644 --- a/base/utf8proc.jl +++ b/base/utf8proc.jl @@ -63,7 +63,7 @@ const UTF8PROC_STRIPMARK = (1<<13) let const p = Array(Ptr{Uint8}, 1) global utf8proc_map - function utf8proc_map(s::String, flags::Integer) + function utf8proc_map(s::AbstractString, flags::Integer) result = ccall(:utf8proc_map, Cssize_t, (Ptr{Uint8}, Cssize_t, Ptr{Ptr{Uint8}}, Cint), s, 0, p, flags | UTF8PROC_NULLTERM) @@ -76,7 +76,7 @@ let end end -function normalize_string(s::String; stable::Bool=false, compat::Bool=false, compose::Bool=true, decompose::Bool=false, stripignore::Bool=false, rejectna::Bool=false, newline2ls::Bool=false, newline2ps::Bool=false, newline2lf::Bool=false, stripcc::Bool=false, casefold::Bool=false, lump::Bool=false, stripmark::Bool=false) +function normalize_string(s::AbstractString; stable::Bool=false, compat::Bool=false, compose::Bool=true, decompose::Bool=false, stripignore::Bool=false, rejectna::Bool=false, newline2ls::Bool=false, newline2ps::Bool=false, newline2lf::Bool=false, stripcc::Bool=false, casefold::Bool=false, lump::Bool=false, stripmark::Bool=false) flags = 0 stable && (flags = flags | UTF8PROC_STABLE) compat && (flags = flags | UTF8PROC_COMPAT) @@ -100,7 +100,7 @@ function normalize_string(s::String; stable::Bool=false, compat::Bool=false, com utf8proc_map(s, flags) end -function normalize_string(s::String, nf::Symbol) +function normalize_string(s::AbstractString, nf::Symbol) utf8proc_map(s, nf == :NFC ? (UTF8PROC_STABLE | UTF8PROC_COMPOSE) : nf == :NFD ? (UTF8PROC_STABLE | UTF8PROC_DECOMPOSE) : nf == :NFKC ? (UTF8PROC_STABLE | UTF8PROC_COMPOSE @@ -167,7 +167,7 @@ for name = ("alnum", "alpha", "cntrl", "digit", "number", "graph", "lower", "print", "punct", "space", "upper") f = symbol(string("is",name)) @eval begin - function $f(s::String) + function $f(s::AbstractString) for c in s if !$f(c) return false diff --git a/base/util.jl b/base/util.jl index f62f19108b2a5..e817380bdd187 100644 --- a/base/util.jl +++ b/base/util.jl @@ -201,27 +201,27 @@ function with_output_color(f::Function, color::Symbol, io::IO, args...) end end -print_with_color(color::Symbol, io::IO, msg::String...) = +print_with_color(color::Symbol, io::IO, msg::AbstractString...) = with_output_color(print, color, io, msg...) -print_with_color(color::Symbol, msg::String...) = +print_with_color(color::Symbol, msg::AbstractString...) = print_with_color(color, STDOUT, msg...) -println_with_color(color::Symbol, io::IO, msg::String...) = +println_with_color(color::Symbol, io::IO, msg::AbstractString...) = with_output_color(println, color, io, msg...) -println_with_color(color::Symbol, msg::String...) = +println_with_color(color::Symbol, msg::AbstractString...) = println_with_color(color, STDOUT, msg...) ## warnings and messages ## -function info(msg::String...; prefix="INFO: ") +function info(msg::AbstractString...; prefix="INFO: ") println_with_color(:blue, STDERR, prefix, chomp(string(msg...))) end # print a warning only once const have_warned = Set() -warn_once(msg::String...) = warn(msg..., once=true) +warn_once(msg::AbstractString...) = warn(msg..., once=true) -function warn(msg::String...; prefix="WARNING: ", once=false, key=nothing, bt=nothing) +function warn(msg::AbstractString...; prefix="WARNING: ", once=false, key=nothing, bt=nothing) str = chomp(bytestring(msg...)) if once if key === nothing diff --git a/base/version.jl b/base/version.jl index 6c822d6c52627..3ba27f29a2864 100644 --- a/base/version.jl +++ b/base/version.jl @@ -71,7 +71,7 @@ const VERSION_REGEX = r"^ )) $"ix -function split_idents(s::String) +function split_idents(s::AbstractString) idents = split(s, '.') ntuple(length(idents)) do i ident = idents[i] @@ -79,7 +79,7 @@ function split_idents(s::String) end end -VersionNumber(v::String) = begin +VersionNumber(v::AbstractString) = begin m = match(VERSION_REGEX, v) if m == nothing error("invalid version string: $v") end major, minor, patch, minus, prerl, plus, build = m.captures @@ -94,7 +94,7 @@ VersionNumber(v::String) = begin VersionNumber(major, minor, patch, prerl, build) end -convert(::Type{VersionNumber}, v::String) = VersionNumber(v) +convert(::Type{VersionNumber}, v::AbstractString) = VersionNumber(v) macro v_str(v); VersionNumber(v); end diff --git a/base/version_git.sh b/base/version_git.sh index 8ed4f28e0adc6..593becc95d231 100644 --- a/base/version_git.sh +++ b/base/version_git.sh @@ -2,11 +2,11 @@ echo "# This file was autogenerated in base/version_git.sh" echo "immutable GitVersionInfo" -echo " commit::String" -echo " commit_short::String" -echo " branch::String" +echo " commit::AbstractString" +echo " commit_short::AbstractString" +echo " branch::AbstractString" echo " build_number::Int" -echo " date_string::String" +echo " date_string::AbstractString" echo " tagged_commit::Bool" echo " fork_master_distance::Int" echo " fork_master_timestamp::Float64" diff --git a/doc/DocCheck.jl b/doc/DocCheck.jl index ed9e3e41f701c..d7e9918f8cef3 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::String, f::String) = beginswith(f, '@') ? "@$m.$(f[2:end])" : "$m.$f" +modfuncjoin(m::AbstractString, f::AbstractString) = beginswith(f, '@') ? "@$m.$(f[2:end])" : "$m.$f" modfuncjoin(m, f) = modfuncjoin(string(m), string(f)) # return a list of undefined exports in a module @@ -33,7 +33,7 @@ undefined_exports(m::Module) = sort(filter(x->!isdefined(x), names(m))) undefined_exports() = undefined(Base) # Check for exported names that aren't documented, -# and return a Dict with (fn::Symbol, fullname::String) pairs +# and return a Dict with (fn::Symbol, fullname::AbstractString) pairs function undocumented(m::Module) init_help() undoc = Dict{Symbol, Array}() @@ -51,7 +51,7 @@ undocumented() = undocumented(Base) # return the file, function names, and line numbers, if available function undocumented_by_file(m::Module) init_help() - undocf = Dict{String, Dict}() + undocf = Dict{AbstractString, Dict}() for (f,_) in undocumented(m) s = string(f) try @@ -60,7 +60,7 @@ function undocumented_by_file(m::Module) file = replace(file, JULIA_HOME, "\$JULIA_HOME", 1) end if !haskey(undocf, file) - undocf[file] = Dict{String, Vector{Integer}}() + undocf[file] = Dict{AbstractString, Vector{Integer}}() end if !haskey(undocf[file], s) undocf[file][s] = [line] @@ -70,7 +70,7 @@ function undocumented_by_file(m::Module) end catch if !haskey(undocf, "UNKNOWN_FILE") - undocf["UNKNOWN_FILE"] = Dict{String, Vector{Integer}}() + undocf["UNKNOWN_FILE"] = Dict{AbstractString, Vector{Integer}}() end undocf["UNKNOWN_FILE"][s] = Integer[-1] end @@ -90,7 +90,7 @@ undocumented_by_file() = undocumented_by_file(Base) function _undocumented_rst() init_help() depdoc = havecount = total = 0 - out = String["The following exports are not documented:"] + out = AbstractString["The following exports are not documented:"] undoc_exports = Set() exports=[strip(x) for x in split(replace(open(readall, "$JULIA_HOME/../../base/exports.jl"),",",""),"\n")] for line in exports @@ -116,7 +116,7 @@ function _undocumented_rst() push!(out, line) end - append!(out, String["", "Documented and deprecated functions/exports (please update docs)", ""]) + append!(out, AbstractString["", "Documented and deprecated functions/exports (please update docs)", ""]) deprecated=[strip(x) for x in split(replace(open(readall, "$JULIA_HOME/../../base/deprecated.jl"),",",""),"\n")] for line in deprecated @@ -129,7 +129,7 @@ function _undocumented_rst() end end end - prepend!(out, String["$havecount/$total exports have been documented", + prepend!(out, AbstractString["$havecount/$total exports have been documented", "(Additionally, $depdoc deprecated functions are still documentated)", ""]) (join(out, "\n"), undoc_exports) diff --git a/doc/helpdb.jl b/doc/helpdb.jl index 6899af03d435b..19bacb35ac350 100644 --- a/doc/helpdb.jl +++ b/doc/helpdb.jl @@ -35,7 +35,7 @@ Any[ "), -("Base","edit","edit(file::String[, line]) +("Base","edit","edit(file::AbstractString[, line]) Edit a file optionally providing a line number to edit at. Returns to the julia prompt when you quit the editor. @@ -56,7 +56,7 @@ Any[ "), -("Base","less","less(file::String[, line]) +("Base","less","less(file::AbstractString[, line]) Show a file using the default pager, optionally providing a starting line number. Returns to the julia prompt when you quit the @@ -86,14 +86,14 @@ Any[ "), -("Base","clipboard","clipboard() -> String +("Base","clipboard","clipboard() -> AbstractString Return a string with the contents of the operating system clipboard (\"paste\"). "), -("Base","require","require(file::String...) +("Base","require","require(file::AbstractString...) Load source files once, in the context of the \"Main\" module, on every active node, searching standard locations for files. @@ -109,7 +109,7 @@ Any[ "), -("Base","reload","reload(file::String) +("Base","reload","reload(file::AbstractString) Like \"require\", except forces loading of files regardless of whether they have been loaded before. Typically used when @@ -117,7 +117,7 @@ Any[ "), -("Base","include","include(path::String) +("Base","include","include(path::AbstractString) Evaluate the contents of a source file in the current context. During including, a task-local include path is set to the directory @@ -130,7 +130,7 @@ Any[ "), -("Base","include_string","include_string(code::String) +("Base","include_string","include_string(code::AbstractString) Like \"include\", except reads code from the given string rather than from a file. Since there is no file path involved, no path @@ -698,7 +698,7 @@ Any[ "), -("Base","evalfile","evalfile(path::String) +("Base","evalfile","evalfile(path::AbstractString) Evaluate all expressions in the given file, and return the value of the last one. No other processing (path searching, fetching from @@ -1665,7 +1665,7 @@ Any[ "), -("Base","sizeof","sizeof(s::String) +("Base","sizeof","sizeof(s::AbstractString) The number of bytes in string \"s\". @@ -1827,14 +1827,14 @@ Any[ "), -("Base","ismatch","ismatch(r::Regex, s::String) -> Bool +("Base","ismatch","ismatch(r::Regex, s::AbstractString) -> Bool Test whether a string contains a match of the given regular expression. "), -("Base","match","match(r::Regex, s::String[, idx::Integer[, addopts]]) +("Base","match","match(r::Regex, s::AbstractString[, idx::Integer[, addopts]]) Search for the first match of the regular expression \"r\" in \"s\" and return a RegexMatch object containing the match, or nothing if @@ -1845,7 +1845,7 @@ Any[ "), -("Base","eachmatch","eachmatch(r::Regex, s::String[, overlap::Bool=false]) +("Base","eachmatch","eachmatch(r::Regex, s::AbstractString[, overlap::Bool=false]) Search for all matches of a the regular expression \"r\" in \"s\" and return a iterator over the matches. If overlap is true, the @@ -1854,7 +1854,7 @@ Any[ "), -("Base","matchall","matchall(r::Regex, s::String[, overlap::Bool=false]) -> Vector{String} +("Base","matchall","matchall(r::Regex, s::AbstractString[, overlap::Bool=false]) -> Vector{AbstractString} Return a vector of the matching substrings from eachmatch. @@ -2086,7 +2086,7 @@ Any[ "), -("Base","isalnum","isalnum(c::Union(Char, String)) -> Bool +("Base","isalnum","isalnum(c::Union(Char, AbstractString)) -> Bool Tests whether a character is alphanumeric, or whether this is true for all elements of a string. A character is classified as @@ -2096,7 +2096,7 @@ Any[ "), -("Base","isalpha","isalpha(c::Union(Char, String)) -> Bool +("Base","isalpha","isalpha(c::Union(Char, AbstractString)) -> Bool Tests whether a character is alphabetic, or whether this is true for all elements of a string. A character is classified as @@ -2105,14 +2105,14 @@ Any[ "), -("Base","isascii","isascii(c::Union(Char, String)) -> Bool +("Base","isascii","isascii(c::Union(Char, AbstractString)) -> Bool Tests whether a character belongs to the ASCII character set, or whether this is true for all elements of a string. "), -("Base","iscntrl","iscntrl(c::Union(Char, String)) -> Bool +("Base","iscntrl","iscntrl(c::Union(Char, AbstractString)) -> Bool Tests whether a character is a control character, or whether this is true for all elements of a string. Control characters are the @@ -2120,14 +2120,14 @@ Any[ "), -("Base","isdigit","isdigit(c::Union(Char, String)) -> Bool +("Base","isdigit","isdigit(c::Union(Char, AbstractString)) -> Bool Tests whether a character is a numeric digit (0-9), or whether this is true for all elements of a string. "), -("Base","isgraph","isgraph(c::Union(Char, String)) -> Bool +("Base","isgraph","isgraph(c::Union(Char, AbstractString)) -> Bool Tests whether a character is printable, and not a space, or whether this is true for all elements of a string. Any character that @@ -2136,7 +2136,7 @@ Any[ "), -("Base","islower","islower(c::Union(Char, String)) -> Bool +("Base","islower","islower(c::Union(Char, AbstractString)) -> Bool Tests whether a character is a lowercase letter, or whether this is true for all elements of a string. A character is classified as @@ -2144,7 +2144,7 @@ Any[ "), -("Base","isnumber","isnumber(c::Union(Char, String)) -> Bool +("Base","isnumber","isnumber(c::Union(Char, AbstractString)) -> Bool Tests whether a character is numeric, or whether this is true for all elements of a string. A character is classified as numeric if @@ -2153,7 +2153,7 @@ Any[ "), -("Base","isprint","isprint(c::Union(Char, String)) -> Bool +("Base","isprint","isprint(c::Union(Char, AbstractString)) -> Bool Tests whether a character is printable, including spaces, but not a control character. For strings, tests whether this is true for all @@ -2161,7 +2161,7 @@ Any[ "), -("Base","ispunct","ispunct(c::Union(Char, String)) -> Bool +("Base","ispunct","ispunct(c::Union(Char, AbstractString)) -> Bool Tests whether a character belongs to the Unicode general category Punctuation, i.e. a character whose category code begins with 'P'. @@ -2170,7 +2170,7 @@ Any[ "), -("Base","isspace","isspace(c::Union(Char, String)) -> Bool +("Base","isspace","isspace(c::Union(Char, AbstractString)) -> Bool Tests whether a character is any whitespace character. Includes ASCII characters '\\t', '\\n', '\\v', '\\f', '\\r', and ' ', @@ -2180,7 +2180,7 @@ Any[ "), -("Base","isupper","isupper(c::Union(Char, String)) -> Bool +("Base","isupper","isupper(c::Union(Char, AbstractString)) -> Bool Tests whether a character is an uppercase letter, or whether this is true for all elements of a string. A character is classified @@ -2189,7 +2189,7 @@ Any[ "), -("Base","isxdigit","isxdigit(c::Union(Char, String)) -> Bool +("Base","isxdigit","isxdigit(c::Union(Char, AbstractString)) -> Bool Tests whether a character is a valid hexadecimal digit, or whether this is true for all elements of a string. @@ -2202,14 +2202,14 @@ Any[ "), -("Base","escape_string","escape_string(str::String) -> String +("Base","escape_string","escape_string(str::AbstractString) -> AbstractString General escaping of traditional C and Unicode escape sequences. See \"print_escaped()\" for more general escaping. "), -("Base","unescape_string","unescape_string(s::String) -> String +("Base","unescape_string","unescape_string(s::AbstractString) -> AbstractString General unescaping of traditional C and Unicode escape sequences. Reverse of \"escape_string()\". See also \"print_unescaped()\". @@ -2389,7 +2389,7 @@ Any[ "), -("Base","fdio","fdio([name::String], fd::Integer[, own::Bool]) -> IOStream +("Base","fdio","fdio([name::AbstractString], fd::Integer[, own::Bool]) -> IOStream Create an \"IOStream\" object from an integer file descriptor. If \"own\" is true, closing this object will close the underlying @@ -2606,14 +2606,14 @@ Any[ "), -("Base","print_escaped","print_escaped(io, str::String, esc::String) +("Base","print_escaped","print_escaped(io, str::AbstractString, esc::AbstractString) General escaping of traditional C and Unicode escape sequences, plus any characters in esc are also escaped (with a backslash). "), -("Base","print_unescaped","print_unescaped(io, s::String) +("Base","print_unescaped","print_unescaped(io, s::AbstractString) General unescaping of traditional C and Unicode escape sequences. Reverse of \"print_escaped()\". @@ -2833,7 +2833,7 @@ Any[ "), -("Base","cp","cp(src::String, dst::String) +("Base","cp","cp(src::AbstractString, dst::AbstractString) Copy a file from *src* to *dest*. @@ -2850,13 +2850,13 @@ Any[ "), -("Base","mv","mv(src::String, dst::String) +("Base","mv","mv(src::AbstractString, dst::AbstractString) Move a file from *src* to *dst*. "), -("Base","rm","rm(path::String; recursive=false) +("Base","rm","rm(path::AbstractString; recursive=false) Delete the file, link, or empty directory at the given path. If \"recursive=true\" is passed and the path is a directory, then all @@ -2864,7 +2864,7 @@ Any[ "), -("Base","touch","touch(path::String) +("Base","touch","touch(path::AbstractString) Update the last-modified timestamp on a file to the current time. @@ -3089,7 +3089,7 @@ Any[ "), -("Base","readall","readall(filename::String) +("Base","readall","readall(filename::AbstractString) Open \"filename\", read the entire contents as a string, then close the file. Equivalent to \"open(readall, filename)\". @@ -3133,7 +3133,7 @@ Any[ If \"T\" is a numeric type, the result is an array of that type, with any non-numeric elements as \"NaN\" for floating-point types, or zero. Other useful values of \"T\" include \"ASCIIString\", - \"String\", and \"Any\". + \"AbstractString\", and \"Any\". If \"header\" is \"true\", the first row of data will be read as header and the tuple \"(data_cells, header_cells)\" is returned @@ -3213,7 +3213,7 @@ Any[ rows) as text to \"f\" (either a filename string or an \"IO\" stream) using the given delimeter \"delim\" (which defaults to tab, but can be any printable Julia object, typically a \"Char\" or - \"String\"). + \"AbstractString\"). For example, two vectors \"x\" and \"y\" of the same length can be written as two columns of tab-delimited text to \"f\" by either @@ -3273,9 +3273,10 @@ display(d::Display, mime, x) using the requested MIME type *only*, throwing a \"MethodError\" if this type is not supported by either the display(s) or by \"x\". With these variants, one can also supply the \"raw\" data in the - requested MIME type by passing \"x::String\" (for MIME types with - text-based storage, such as text/html or application/postscript) or - \"x::Vector{Uint8}\" (for binary MIME types). + requested MIME type by passing \"x::AbstractString\" (for MIME + types with text-based storage, such as text/html or + application/postscript) or \"x::Vector{Uint8}\" (for binary MIME + types). "), @@ -3342,17 +3343,17 @@ displayable(d::Display, mime) -> Bool ("Base","reprmime","reprmime(mime, x) - Returns a \"String\" or \"Vector{Uint8}\" containing the + Returns a \"AbstractString\" or \"Vector{Uint8}\" containing the representation of \"x\" in the requested \"mime\" type, as written by \"writemime\" (throwing a \"MethodError\" if no appropriate - \"writemime\" is available). A \"String\" is returned for MIME - types with textual representations (such as \"\"text/html\"\" or - \"\"application/postscript\"\"), whereas binary data is returned as - \"Vector{Uint8}\". (The function \"istext(mime)\" returns whether - or not Julia treats a given \"mime\" type as text.) - - As a special case, if \"x\" is a \"String\" (for textual MIME - types) or a \"Vector{Uint8}\" (for binary MIME types), the + \"writemime\" is available). A \"AbstractString\" is returned for + MIME types with textual representations (such as \"\"text/html\"\" + or \"\"application/postscript\"\"), whereas binary data is returned + as \"Vector{Uint8}\". (The function \"istext(mime)\" returns + whether or not Julia treats a given \"mime\" type as text.) + + As a special case, if \"x\" is a \"AbstractString\" (for textual + MIME types) or a \"Vector{Uint8}\" (for binary MIME types), the \"reprmime\" function assumes that \"x\" is already in the requested \"mime\" format and simply returns \"x\". @@ -3360,9 +3361,9 @@ displayable(d::Display, mime) -> Bool ("Base","stringmime","stringmime(mime, x) - Returns a \"String\" containing the representation of \"x\" in the - requested \"mime\" type. This is similar to \"reprmime\" except - that binary data is base64-encoded as an ASCII string. + Returns a \"AbstractString\" containing the representation of \"x\" + in the requested \"mime\" type. This is similar to \"reprmime\" + except that binary data is base64-encoded as an ASCII string. "), @@ -5503,21 +5504,22 @@ popdisplay(d::Display) ("Base","BigInt","BigInt(x) Create an arbitrary precision integer. \"x\" may be an \"Int\" (or - anything that can be converted to an \"Int\") or a \"String\". The - usual mathematical operators are defined for this type, and results - are promoted to a \"BigInt\". + anything that can be converted to an \"Int\") or a + \"AbstractString\". The usual mathematical operators are defined + for this type, and results are promoted to a \"BigInt\". "), ("Base","BigFloat","BigFloat(x) Create an arbitrary precision floating point number. \"x\" may be - an \"Integer\", a \"Float64\", a \"String\" or a \"BigInt\". The - usual mathematical operators are defined for this type, and results - are promoted to a \"BigFloat\". Note that because floating-point - numbers are not exactly-representable in decimal notation, - \"BigFloat(2.1)\" may not yield what you expect. You may prefer to - initialize constants using strings, e.g., \"BigFloat(\"2.1\")\". + an \"Integer\", a \"Float64\", a \"AbstractString\" or a + \"BigInt\". The usual mathematical operators are defined for this + type, and results are promoted to a \"BigFloat\". Note that because + floating-point numbers are not exactly-representable in decimal + notation, \"BigFloat(2.1)\" may not yield what you expect. You may + prefer to initialize constants using strings, e.g., + \"BigFloat(\"2.1\")\". "), @@ -7630,7 +7632,7 @@ popdisplay(d::Display) "), -("Base","open","open(command, mode::String=\"r\", stdio=DevNull) +("Base","open","open(command, mode::AbstractString=\"r\", stdio=DevNull) Start running \"command\" asynchronously, and return a tuple \"(stream,process)\". If \"mode\" is \"\"r\"\", then \"stream\" @@ -7642,7 +7644,7 @@ popdisplay(d::Display) "), -("Base","open","open(f::Function, command, mode::String=\"r\", stdio=DevNull) +("Base","open","open(f::Function, command, mode::AbstractString=\"r\", stdio=DevNull) Similar to \"open(command, mode, stdio)\", but calls \"f(stream)\" on the resulting read or write stream, then closes the stream and @@ -7715,26 +7717,26 @@ popdisplay(d::Display) "), -("Base","gethostname","gethostname() -> String +("Base","gethostname","gethostname() -> AbstractString Get the local machine's host name. "), -("Base","getipaddr","getipaddr() -> String +("Base","getipaddr","getipaddr() -> AbstractString Get the IP address of the local machine, as a string of the form \"x.x.x.x\". "), -("Base","pwd","pwd() -> String +("Base","pwd","pwd() -> AbstractString Get the current working directory. "), -("Base","cd","cd(dir::String) +("Base","cd","cd(dir::AbstractString) Set the current working directory. @@ -7924,8 +7926,8 @@ popdisplay(d::Display) Call function in C-exported shared library, specified by \"(function name, library)\" tuple, where each component is a - String or :Symbol. Alternatively, ccall may be used to call a - function pointer returned by dlsym, but note that this usage is + AbstractString or :Symbol. Alternatively, ccall may be used to call + a function pointer returned by dlsym, but note that this usage is generally discouraged to facilitate future static compilation. Note that the argument type tuple must be a literal tuple, and not a tuple-valued variable or expression. @@ -7961,7 +7963,7 @@ popdisplay(d::Display) "), -("Base","dlopen","dlopen(libfile::String[, flags::Integer]) +("Base","dlopen","dlopen(libfile::AbstractString[, flags::Integer]) Load a shared library, returning an opaque handle. @@ -7980,7 +7982,7 @@ popdisplay(d::Display) "), -("Base","dlopen_e","dlopen_e(libfile::String[, flags::Integer]) +("Base","dlopen_e","dlopen_e(libfile::AbstractString[, flags::Integer]) Similar to \"dlopen()\", except returns a \"NULL\" pointer instead of raising errors. @@ -8355,7 +8357,7 @@ popdisplay(d::Display) "), -("Base","error","error(message::String) +("Base","error","error(message::AbstractString) Raise an error with the given message @@ -9037,7 +9039,7 @@ popdisplay(d::Display) "), -("Dates","DateTime","DateTime(dt::String, format::String; locale=\"english\") -> DateTime +("Dates","DateTime","DateTime(dt::AbstractString, format::AbstractString; locale=\"english\") -> DateTime Construct a DateTime type by parsing the \"dt\" date string following the pattern given in the \"format\" string. The following @@ -9114,7 +9116,7 @@ popdisplay(d::Display) "), -("Dates","Date","Date(dt::String, format::String; locale=\"english\") -> Date +("Dates","Date","Date(dt::AbstractString, format::AbstractString; locale=\"english\") -> Date Construct a Date type by parsing a \"dt\" date string following the pattern given in the \"format\" string. Follows the same @@ -9183,14 +9185,14 @@ Millisecond(dt::TimeType) -> Millisecond "), -("Dates","dayname","dayname(dt::TimeType; locale=\"english\") -> String +("Dates","dayname","dayname(dt::TimeType; locale=\"english\") -> AbstractString Return the full day name corresponding to the day of the week of the Date or DateTime in the given \"locale\". "), -("Dates","dayabbr","dayabbr(dt::TimeType; locale=\"english\") -> String +("Dates","dayabbr","dayabbr(dt::TimeType; locale=\"english\") -> AbstractString Return the abbreviated name corresponding to the day of the week of the Date or DateTime in the given \"locale\". @@ -9223,14 +9225,14 @@ Millisecond(dt::TimeType) -> Millisecond "), -("Dates","monthname","monthname(dt::TimeType; locale=\"english\") -> String +("Dates","monthname","monthname(dt::TimeType; locale=\"english\") -> AbstractString Return the full name of the month of the Date or DateTime in the given \"locale\". "), -("Dates","monthabbr","monthabbr(dt::TimeType; locale=\"english\") -> String +("Dates","monthabbr","monthabbr(dt::TimeType; locale=\"english\") -> AbstractString Return the abbreviated month name of the Date or DateTime in the given \"locale\". @@ -9563,25 +9565,25 @@ Millisecond(v) "), -("Base","homedir","homedir() -> String +("Base","homedir","homedir() -> AbstractString Return the current user's home directory. "), -("Base","dirname","dirname(path::String) -> String +("Base","dirname","dirname(path::AbstractString) -> AbstractString Get the directory part of a path. "), -("Base","basename","basename(path::String) -> String +("Base","basename","basename(path::AbstractString) -> AbstractString Get the file name part of a path. "), -("Base","@__FILE__","@__FILE__() -> String +("Base","@__FILE__","@__FILE__() -> AbstractString \"@__FILE__\" expands to a string with the absolute path and file name of the script being run. Returns \"nothing\" if run from a @@ -9589,61 +9591,61 @@ Millisecond(v) "), -("Base","isabspath","isabspath(path::String) -> Bool +("Base","isabspath","isabspath(path::AbstractString) -> Bool Determines whether a path is absolute (begins at the root directory). "), -("Base","isdirpath","isdirpath(path::String) -> Bool +("Base","isdirpath","isdirpath(path::AbstractString) -> Bool Determines whether a path refers to a directory (for example, ends with a path separator). "), -("Base","joinpath","joinpath(parts...) -> String +("Base","joinpath","joinpath(parts...) -> AbstractString Join path components into a full path. If some argument is an absolute path, then prior components are dropped. "), -("Base","abspath","abspath(path::String) -> String +("Base","abspath","abspath(path::AbstractString) -> AbstractString Convert a path to an absolute path by adding the current directory if necessary. "), -("Base","normpath","normpath(path::String) -> String +("Base","normpath","normpath(path::AbstractString) -> AbstractString Normalize a path, removing \".\" and \"..\" entries. "), -("Base","realpath","realpath(path::String) -> String +("Base","realpath","realpath(path::AbstractString) -> AbstractString Canonicalize a path by expanding symbolic links and removing \".\" and \"..\" entries. "), -("Base","expanduser","expanduser(path::String) -> String +("Base","expanduser","expanduser(path::AbstractString) -> AbstractString On Unix systems, replace a tilde character at the start of a path with the current user's home directory. "), -("Base","splitdir","splitdir(path::String) -> (String, String) +("Base","splitdir","splitdir(path::AbstractString) -> (AbstractString, AbstractString) Split a path into a tuple of the directory name and file name. "), -("Base","splitdrive","splitdrive(path::String) -> (String, String) +("Base","splitdrive","splitdrive(path::AbstractString) -> (AbstractString, AbstractString) On Windows, split a path into the drive letter part and the path part. On Unix systems, the first component is always the empty @@ -9651,7 +9653,7 @@ Millisecond(v) "), -("Base","splitext","splitext(path::String) -> (String, String) +("Base","splitext","splitext(path::AbstractString) -> (AbstractString, AbstractString) If the last component of a path contains a dot, split the path into everything before the dot and everything including and after the @@ -11183,7 +11185,7 @@ Millisecond(v) "), -("Base.Pkg","dir","dir() -> String +("Base.Pkg","dir","dir() -> AbstractString Returns the absolute path of the package directory. This defaults to \"joinpath(homedir(),\".julia\")\" on all platforms (i.e. @@ -11194,7 +11196,7 @@ Millisecond(v) "), -("Base.Pkg","dir","dir(names...) -> String +("Base.Pkg","dir","dir(names...) -> AbstractString Equivalent to \"normpath(Pkg.dir(),names...)\" – i.e. it appends path components to the package directory and normalizes the @@ -11203,7 +11205,7 @@ Millisecond(v) "), -("Base.Pkg","init","init(meta::String=DEFAULT_META, branch::String=META_BRANCH) +("Base.Pkg","init","init(meta::AbstractString=DEFAULT_META, branch::AbstractString=META_BRANCH) Initialize \"Pkg.dir()\" as a package directory. This will be done automatically when the \"JULIA_PKGDIR\" is not set and diff --git a/doc/manual/calling-c-and-fortran-code.rst b/doc/manual/calling-c-and-fortran-code.rst index 597c518bd55f8..839b4a666e93a 100644 --- a/doc/manual/calling-c-and-fortran-code.rst +++ b/doc/manual/calling-c-and-fortran-code.rst @@ -95,7 +95,7 @@ inconsistent about how they indicate error conditions. For example, the in `env.jl `_:: - function getenv(var::String) + function getenv(var::AbstractString) val = ccall( (:getenv, "libc"), Ptr{Uint8}, (Ptr{Uint8},), var) if val == C_NULL diff --git a/doc/manual/integers-and-floating-point-numbers.rst b/doc/manual/integers-and-floating-point-numbers.rst index 324621edd65ba..0f83bc8d7855a 100644 --- a/doc/manual/integers-and-floating-point-numbers.rst +++ b/doc/manual/integers-and-floating-point-numbers.rst @@ -563,7 +563,7 @@ Julia wraps the `GNU Multiple Precision Arithmetic Library (GMP) `. : diff --git a/doc/manual/interacting-with-julia.rst b/doc/manual/interacting-with-julia.rst index 5900e518c92e0..f70ae683f2089 100644 --- a/doc/manual/interacting-with-julia.rst +++ b/doc/manual/interacting-with-julia.rst @@ -66,10 +66,10 @@ In addition to function names, complete function calls may be entered to see whi string. Optionally, an IOStream may be passed as the first argument to redirect output. - help> String - DataType : String + help> AbstractString + DataType : AbstractString supertype: Any - subtypes : {DirectIndexString,GenericString,RepString,RevString{T<:String},RopeString,SubString{T<:String},UTF16String,UTF8String} + subtypes : {DirectIndexString,GenericString,RepString,RevString{T<:AbstractString},RopeString,SubString{T<:AbstractString},UTF16String,UTF8String} Help mode can be exited by pressing backspace at the beginning of the line. @@ -189,7 +189,7 @@ In both the Julian and help modes of the REPL, one can enter the first few chara stride strides string stringmime strip julia> Stri - StridedArray StridedVecOrMat String + StridedArray StridedVecOrMat AbstractString StridedMatrix StridedVector The tab key can also be used to substitute LaTeX math symbols with their Unicode equivalents, diff --git a/doc/manual/metaprogramming.rst b/doc/manual/metaprogramming.rst index 08ed06b8f329b..200a4ca3622d0 100644 --- a/doc/manual/metaprogramming.rst +++ b/doc/manual/metaprogramming.rst @@ -538,7 +538,7 @@ is occasionally quite handy. .. _man-non-standard-string-literals2: -Non-Standard String Literals +Non-Standard AbstractString Literals ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Recall from :ref:`Strings ` that diff --git a/doc/manual/parallel-computing.rst b/doc/manual/parallel-computing.rst index b86e65a9568dd..7cb08a4ee7f0a 100644 --- a/doc/manual/parallel-computing.rst +++ b/doc/manual/parallel-computing.rst @@ -711,16 +711,16 @@ the following forms:: (io::IO, config::Dict) - (io::IO, host::String, config::Dict) + (io::IO, host::AbstractString, config::Dict) - (io::IO, host::String, port::Integer, config::Dict) + (io::IO, host::AbstractString, port::Integer, config::Dict) - (host::String, port::Integer, config::Dict) + (host::AbstractString, port::Integer, config::Dict) where: - ``io::IO`` is the output stream of the worker. - - ``host::String`` and ``port::Integer`` are the host:port to connect to. If not provided + - ``host::AbstractString`` and ``port::Integer`` are the host:port to connect to. If not provided they are read from the ``io`` stream provided. - ``config::Dict`` is the configuration dictionary for the worker. The ``launch`` function can add/modify any data that may be required for managing diff --git a/doc/manual/strings.rst b/doc/manual/strings.rst index 9ed533fadb161..af2069561a58f 100644 --- a/doc/manual/strings.rst +++ b/doc/manual/strings.rst @@ -32,15 +32,15 @@ handle non-ASCII data is straightforward. There are a few noteworthy high-level features about Julia's strings: -- ``String`` is an abstraction, not a concrete type — many different - representations can implement the ``String`` interface, but they can +- ``AbstractString`` is an abstraction, not a concrete type — many different + representations can implement the ``AbstractString`` interface, but they can easily be used together and interact transparently. Any string type - can be used in any function expecting a ``String``. + can be used in any function expecting a ``AbstractString``. - Like C and Java, but unlike most dynamic languages, Julia has a first-class type representing a single character, called ``Char``. This is just a special kind of 32-bit bitstype whose numeric value represents a Unicode code point. -- As in Java, strings are immutable: the value of a ``String`` object +- As in Java, strings are immutable: the value of a ``AbstractString`` object cannot be changed. To construct a different string value, you construct a new string from parts of other strings. - Conceptually, a string is a *partial function* from indices to @@ -181,10 +181,10 @@ You can do comparisons and a limited amount of arithmetic with julia> 'A' + 1 'B' -String Basics +AbstractString Basics ------------- -String literals are delimited by double quotes or triple double quotes: +AbstractString literals are delimited by double quotes or triple double quotes: .. doctest:: @@ -408,7 +408,7 @@ can interpolate any expression into a string using parentheses: "1 + 2 = 3" Both concatenation and string interpolation call the generic ``string`` -function to convert objects into ``String`` form. Most non-``String`` +function to convert objects into ``AbstractString`` form. Most non-``AbstractString`` objects are converted to strings as they are shown in interactive sessions: @@ -423,7 +423,7 @@ sessions: julia> "v: $v" "v: [1,2,3]" -The ``string`` function is the identity for ``String`` and ``Char`` +The ``string`` function is the identity for ``AbstractString`` and ``Char`` values, so these are interpolated into strings as themselves, unquoted and unescaped: @@ -516,7 +516,7 @@ Some other useful functions include: .. _man-non-standard-string-literals: -Non-Standard String Literals +Non-Standard AbstractString Literals ---------------------------- There are situations when you want to construct a string or use string diff --git a/doc/manual/style-guide.rst b/doc/manual/style-guide.rst index 7425366c8a54e..1a678d4babbac 100644 --- a/doc/manual/style-guide.rst +++ b/doc/manual/style-guide.rst @@ -116,7 +116,7 @@ such functions to also return the modified array for convenience. Avoid strange type Unions ------------------------- -Types such as ``Union(Function,String)`` are often a sign that some design +Types such as ``Union(Function,AbstractString)`` are often a sign that some design could be cleaner. Try to avoid nullable fields @@ -137,7 +137,7 @@ Avoid elaborate container types It is usually not much help to construct arrays like the following:: - a = Array(Union(Int,String,Tuple,Array), n) + a = Array(Union(Int,AbstractString,Tuple,Array), n) In this case ``cell(n)`` is better. It is also more helpful to the compiler to annotate specific uses (e.g. ``a[i]::Int``) than to try to pack many diff --git a/doc/manual/types.rst b/doc/manual/types.rst index 9d62ab9e0889c..6103c6a0768ec 100644 --- a/doc/manual/types.rst +++ b/doc/manual/types.rst @@ -564,18 +564,18 @@ Accordingly, a tuple of types can be used anywhere a type is expected: .. doctest:: - julia> (1,"foo",2.5) :: (Int64,String,Any) + julia> (1,"foo",2.5) :: (Int64,AbstractString,Any) (1,"foo",2.5) - julia> (1,"foo",2.5) :: (Int64,String,Float32) - ERROR: type: typeassert: expected (Int64,String,Float32), got (Int64,ASCIIString,Float64) + julia> (1,"foo",2.5) :: (Int64,AbstractString,Float32) + ERROR: type: typeassert: expected (Int64,AbstractString,Float32), got (Int64,ASCIIString,Float64) If one of the components of the tuple is not a type, however, you will get an error: .. doctest:: - julia> (1,"foo",2.5) :: (Int64,String,3) + julia> (1,"foo",2.5) :: (Int64,AbstractString,3) ERROR: type: typeassert: expected Type{T<:Top}, got (DataType,DataType,Int64) Note that the empty tuple ``()`` is its own type: @@ -592,13 +592,13 @@ example: .. doctest:: - julia> (Int,String) <: (Real,Any) + julia> (Int,AbstractString) <: (Real,Any) true - julia> (Int,String) <: (Real,Real) + julia> (Int,AbstractString) <: (Real,Real) false - julia> (Int,String) <: (Real,) + julia> (Int,AbstractString) <: (Real,) false Intuitively, this corresponds to the type of a function's arguments @@ -611,8 +611,8 @@ A type union is a special abstract type which includes as objects all instances of any of its argument types, constructed using the special ``Union`` function:: - julia> IntOrString = Union(Int,String) - Union(String,Int64) + julia> IntOrString = Union(Int,AbstractString) + Union(AbstractString,Int64) julia> 1 :: IntOrString 1 @@ -621,7 +621,7 @@ instances of any of its argument types, constructed using the special "Hello!" julia> 1.0 :: IntOrString - ERROR: type: typeassert: expected Union(String,Int64), got Float64 + ERROR: type: typeassert: expected Union(AbstractString,Int64), got Float64 The compilers for many languages have an internal union construct for reasoning about types; Julia simply exposes it to the programmer. The @@ -694,7 +694,7 @@ all (or an integer, actually, although here it's clearly used as a type). ``Point{Float64}`` is a concrete type equivalent to the type defined by replacing ``T`` in the definition of ``Point`` with ``Float64``. Thus, this single declaration actually declares an -unlimited number of types: ``Point{Float64}``, ``Point{String}``, +unlimited number of types: ``Point{Float64}``, ``Point{AbstractString}``, ``Point{Int64}``, etc. Each of these is now a usable concrete type: .. doctest:: @@ -702,11 +702,11 @@ unlimited number of types: ``Point{Float64}``, ``Point{String}``, julia> Point{Float64} Point{Float64} (constructor with 1 method) - julia> Point{String} - Point{String} (constructor with 1 method) + julia> Point{AbstractString} + Point{AbstractString} (constructor with 1 method) The type ``Point{Float64}`` is a point whose coordinates are 64-bit -floating-point values, while the type ``Point{String}`` is a "point" +floating-point values, while the type ``Point{AbstractString}`` is a "point" whose "coordinates" are string objects (see :ref:`man-strings`). However, ``Point`` itself is also a valid type object: @@ -718,14 +718,14 @@ However, ``Point`` itself is also a valid type object: Here the ``T`` is the dummy type symbol used in the original declaration of ``Point``. What does ``Point`` by itself mean? It is an abstract type that contains all the specific instances ``Point{Float64}``, -``Point{String}``, etc.: +``Point{AbstractString}``, etc.: .. doctest:: julia> Point{Float64} <: Point true - julia> Point{String} <: Point + julia> Point{AbstractString} <: Point true Other types, of course, are not subtypes of it: @@ -735,7 +735,7 @@ Other types, of course, are not subtypes of it: julia> Float64 <: Point false - julia> String <: Point + julia> AbstractString <: Point false Concrete ``Point`` types with different values of ``T`` are never @@ -899,7 +899,7 @@ as a subtype of ``Pointy{T}``: julia> Point{Real} <: Pointy{Real} true - julia> Point{String} <: Pointy{String} + julia> Point{AbstractString} <: Pointy{AbstractString} true This relationship is also invariant: @@ -947,8 +947,8 @@ subtypes of ``Real``: julia> Pointy{Real} Pointy{Real} - julia> Pointy{String} - ERROR: type: Pointy: in T, expected T<:Real, got Type{String} + julia> Pointy{AbstractString} + ERROR: type: Pointy: in T, expected T<:Real, got Type{AbstractString} julia> Pointy{1} ERROR: type: Pointy: in T, expected T<:Real, got Int64 @@ -1212,7 +1212,7 @@ Only declared types (``DataType``) have unambiguous supertypes: julia> super(Number) Any - julia> super(String) + julia> super(AbstractString) Any julia> super(Any) diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index 622b6633b4241..cd775e60a4eab 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -41,7 +41,7 @@ Getting Around Print information about exported global variables in a module, optionally restricted to those matching ``pattern``. -.. function:: edit(file::String, [line]) +.. function:: edit(file::AbstractString, [line]) Edit a file optionally providing a line number to edit at. Returns to the julia prompt when you quit the editor. @@ -53,7 +53,7 @@ Getting Around Evaluates the arguments to the function call, determines their types, and calls the ``edit`` function on the resulting expression -.. function:: less(file::String, [line]) +.. function:: less(file::AbstractString, [line]) Show a file using the default pager, optionally providing a starting line number. Returns to the julia prompt when you quit the pager. @@ -69,25 +69,25 @@ Getting Around Send a printed form of ``x`` to the operating system clipboard ("copy"). -.. function:: clipboard() -> String +.. function:: clipboard() -> AbstractString Return a string with the contents of the operating system clipboard ("paste"). -.. function:: require(file::String...) +.. function:: require(file::AbstractString...) Load source files once, in the context of the ``Main`` module, on every active node, searching standard locations for files. ``require`` is considered a top-level operation, so it sets the current ``include`` path but does not use it to search for files (see help for ``include``). This function is typically used to load library code, and is implicitly called by ``using`` to load packages. When searching for files, ``require`` first looks in the current working directory, then looks for package code under ``Pkg.dir()``, then tries paths in the global array ``LOAD_PATH``. -.. function:: reload(file::String) +.. function:: reload(file::AbstractString) Like ``require``, except forces loading of files regardless of whether they have been loaded before. Typically used when interactively developing libraries. -.. function:: include(path::String) +.. function:: include(path::AbstractString) Evaluate the contents of a source file in the current context. During including, a task-local include path is set to the directory containing the file. Nested calls to ``include`` will search relative to that path. All paths refer to files on node 1 when running in parallel, and files will be fetched from node 1. This function is typically used to load source interactively, or to combine files in packages that are broken into multiple source files. -.. function:: include_string(code::String) +.. function:: include_string(code::AbstractString) Like ``include``, except reads code from the given string rather than from a file. Since there is no file path involved, no path processing or fetching from node 1 is done. @@ -471,7 +471,7 @@ Syntax Evaluate an expression and return the value. -.. function:: evalfile(path::String) +.. function:: evalfile(path::AbstractString) Evaluate all expressions in the given file, and return the value of the last one. No other processing (path searching, fetching from node 1, etc.) is performed. @@ -550,7 +550,7 @@ The ``state`` object may be anything, and should be chosen appropriately for eac 3 c -Fully implemented by: ``Range``, ``UnitRange``, ``NDRange``, ``Tuple``, ``Real``, ``AbstractArray``, ``IntSet``, ``ObjectIdDict``, ``Dict``, ``WeakKeyDict``, ``EachLine``, ``String``, ``Set``, ``Task``. +Fully implemented by: ``Range``, ``UnitRange``, ``NDRange``, ``Tuple``, ``Real``, ``AbstractArray``, ``IntSet``, ``ObjectIdDict``, ``Dict``, ``WeakKeyDict``, ``EachLine``, ``AbstractString``, ``Set``, ``Task``. General Collections ------------------- @@ -584,7 +584,7 @@ General Collections julia> endof([1,2,4]) 3 -Fully implemented by: ``Range``, ``UnitRange``, ``Tuple``, ``Number``, ``AbstractArray``, ``IntSet``, ``Dict``, ``WeakKeyDict``, ``String``, ``Set``. +Fully implemented by: ``Range``, ``UnitRange``, ``Tuple``, ``Number``, ``AbstractArray``, ``IntSet``, ``Dict``, ``WeakKeyDict``, ``AbstractString``, ``Set``. Iterable Collections -------------------- @@ -947,7 +947,7 @@ Indexable Collections The syntax ``a[i,j,...] = x`` is converted by the compiler to ``setindex!(a, x, i, j, ...)``. -Fully implemented by: ``Array``, ``DArray``, ``BitArray``, ``AbstractArray``, ``SubArray``, ``ObjectIdDict``, ``Dict``, ``WeakKeyDict``, ``String``. +Fully implemented by: ``Array``, ``DArray``, ``BitArray``, ``AbstractArray``, ``SubArray``, ``ObjectIdDict``, ``Dict``, ``WeakKeyDict``, ``AbstractString``. Partially implemented by: ``Range``, ``UnitRange``, ``Tuple``. @@ -1208,7 +1208,7 @@ Strings The number of characters in string ``s``. -.. function:: sizeof(s::String) +.. function:: sizeof(s::AbstractString) The number of bytes in string ``s``. @@ -1309,19 +1309,19 @@ Strings Returns true if the given char or integer is an assigned Unicode code point. -.. function:: ismatch(r::Regex, s::String) -> Bool +.. function:: ismatch(r::Regex, s::AbstractString) -> Bool Test whether a string contains a match of the given regular expression. -.. function:: match(r::Regex, s::String[, idx::Integer[, addopts]]) +.. function:: match(r::Regex, s::AbstractString[, idx::Integer[, addopts]]) Search for the first match of the regular expression ``r`` in ``s`` and return a RegexMatch object containing the match, or nothing if the match failed. The matching substring can be retrieved by accessing ``m.match`` and the captured sequences can be retrieved by accessing ``m.captures`` The optional ``idx`` argument specifies an index at which to start the search. -.. function:: eachmatch(r::Regex, s::String[, overlap::Bool=false]) +.. function:: eachmatch(r::Regex, s::AbstractString[, overlap::Bool=false]) Search for all matches of a the regular expression ``r`` in ``s`` and return a iterator over the matches. If overlap is true, the matching sequences are allowed to overlap indices in the original string, otherwise they must be from distinct character ranges. -.. function:: matchall(r::Regex, s::String[, overlap::Bool=false]) -> Vector{String} +.. function:: matchall(r::Regex, s::AbstractString[, overlap::Bool=false]) -> Vector{AbstractString} Return a vector of the matching substrings from eachmatch. @@ -1451,74 +1451,74 @@ Strings Gives the number of columns needed to print a string. -.. function:: isalnum(c::Union(Char,String)) -> Bool +.. function:: isalnum(c::Union(Char,AbstractString)) -> Bool Tests whether a character is alphanumeric, or whether this is true for all elements of a string. A character is classified as alphabetic if it belongs to the Unicode general category Letter or Number, i.e. a character whose category code begins with 'L' or 'N'. -.. function:: isalpha(c::Union(Char,String)) -> Bool +.. function:: isalpha(c::Union(Char,AbstractString)) -> Bool Tests whether a character is alphabetic, or whether this is true for all elements of a string. A character is classified as alphabetic if it belongs to the Unicode general category Letter, i.e. a character whose category code begins with 'L'. -.. function:: isascii(c::Union(Char,String)) -> Bool +.. function:: isascii(c::Union(Char,AbstractString)) -> Bool Tests whether a character belongs to the ASCII character set, or whether this is true for all elements of a string. -.. function:: iscntrl(c::Union(Char,String)) -> Bool +.. function:: iscntrl(c::Union(Char,AbstractString)) -> Bool Tests whether a character is a control character, or whether this is true for all elements of a string. Control characters are the non-printing characters of the Latin-1 subset of Unicode. -.. function:: isdigit(c::Union(Char,String)) -> Bool +.. function:: isdigit(c::Union(Char,AbstractString)) -> Bool Tests whether a character is a numeric digit (0-9), or whether this is true for all elements of a string. -.. function:: isgraph(c::Union(Char,String)) -> Bool +.. function:: isgraph(c::Union(Char,AbstractString)) -> Bool Tests whether a character is printable, and not a space, or whether this is true for all elements of a string. Any character that would cause a printer to use ink should be classified with isgraph(c)==true. -.. function:: islower(c::Union(Char,String)) -> Bool +.. function:: islower(c::Union(Char,AbstractString)) -> Bool Tests whether a character is a lowercase letter, or whether this is true for all elements of a string. A character is classified as lowercase if it belongs to Unicode category Ll, Letter: Lowercase. -.. function:: isnumber(c::Union(Char,String)) -> Bool +.. function:: isnumber(c::Union(Char,AbstractString)) -> Bool Tests whether a character is numeric, or whether this is true for all elements of a string. A character is classified as numeric if it belongs to the Unicode general category Number, i.e. a character whose category code begins with 'N'. -.. function:: isprint(c::Union(Char,String)) -> Bool +.. function:: isprint(c::Union(Char,AbstractString)) -> Bool Tests whether a character is printable, including spaces, but not a control character. For strings, tests whether this is true for all elements of the string. -.. function:: ispunct(c::Union(Char,String)) -> Bool +.. function:: ispunct(c::Union(Char,AbstractString)) -> Bool Tests whether a character belongs to the Unicode general category Punctuation, i.e. a character whose category code begins with 'P'. For strings, tests whether this is true for all elements of the string. -.. function:: isspace(c::Union(Char,String)) -> Bool +.. function:: isspace(c::Union(Char,AbstractString)) -> Bool Tests whether a character is any whitespace character. Includes ASCII characters '\\t', '\\n', '\\v', '\\f', '\\r', and ' ', Latin-1 character U+0085, and characters in Unicode category Zs. For strings, tests whether this is true for all elements of the string. -.. function:: isupper(c::Union(Char,String)) -> Bool +.. function:: isupper(c::Union(Char,AbstractString)) -> Bool Tests whether a character is an uppercase letter, or whether this is true for all elements of a string. A character is classified as uppercase if it belongs to Unicode category Lu, Letter: Uppercase, or Lt, Letter: Titlecase. -.. function:: isxdigit(c::Union(Char,String)) -> Bool +.. function:: isxdigit(c::Union(Char,AbstractString)) -> Bool Tests whether a character is a valid hexadecimal digit, or whether this is true for all elements of a string. @@ -1527,11 +1527,11 @@ Strings Convert a string to a ``Symbol``. -.. function:: escape_string(str::String) -> String +.. function:: escape_string(str::AbstractString) -> AbstractString General escaping of traditional C and Unicode escape sequences. See :func:`print_escaped` for more general escaping. -.. function:: unescape_string(s::String) -> String +.. function:: unescape_string(s::AbstractString) -> AbstractString General unescaping of traditional C and Unicode escape sequences. Reverse of :func:`escape_string`. See also :func:`print_unescaped`. @@ -1655,7 +1655,7 @@ I/O Obtain the contents of an ``IOBuffer`` as a string, without copying. Afterwards, the IOBuffer is reset to its initial state. -.. function:: fdio([name::String, ]fd::Integer[, own::Bool]) -> IOStream +.. function:: fdio([name::AbstractString, ]fd::Integer[, own::Bool]) -> IOStream Create an ``IOStream`` object from an integer file descriptor. If ``own`` is true, closing this object will close the underlying descriptor. By default, an ``IOStream`` is closed when it is garbage collected. ``name`` allows you to associate the descriptor with a named file. @@ -1801,11 +1801,11 @@ I/O Read a value written by ``serialize``. -.. function:: print_escaped(io, str::String, esc::String) +.. function:: print_escaped(io, str::AbstractString, esc::AbstractString) General escaping of traditional C and Unicode escape sequences, plus any characters in esc are also escaped (with a backslash). -.. function:: print_unescaped(io, s::String) +.. function:: print_unescaped(io, s::AbstractString) General unescaping of traditional C and Unicode escape sequences. Reverse of :func:`print_escaped`. @@ -1937,7 +1937,7 @@ I/O Like uperm but gets the permissions for people who neither own the file nor are a member of the group owning the file -.. function:: cp(src::String,dst::String) +.. function:: cp(src::AbstractString,dst::AbstractString) Copy a file from `src` to `dest`. @@ -1949,16 +1949,16 @@ I/O use or situations in which more options are need, please use a package that provides the desired functionality instead. -.. function:: mv(src::String,dst::String) +.. function:: mv(src::AbstractString,dst::AbstractString) Move a file from `src` to `dst`. -.. function:: rm(path::String; recursive=false) +.. function:: rm(path::AbstractString; recursive=false) Delete the file, link, or empty directory at the given path. If ``recursive=true`` is passed and the path is a directory, then all contents are removed recursively. -.. function:: touch(path::String) +.. function:: touch(path::AbstractString) Update the last-modified timestamp on a file to the current time. @@ -2103,7 +2103,7 @@ Text I/O Read the entire contents of an I/O stream as a string. -.. function:: readall(filename::String) +.. function:: readall(filename::AbstractString) Open ``filename``, read the entire contents as a string, then close the file. Equivalent to ``open(readall, filename)``. @@ -2128,7 +2128,7 @@ Text I/O Read a matrix from the source where each line (separated by ``eol``) gives one row, with elements separated by the given delimeter. The source can be a text file, stream or byte array. Memory mapped files can be used by passing the byte array representation of the mapped segment as source. - If ``T`` is a numeric type, the result is an array of that type, with any non-numeric elements as ``NaN`` for floating-point types, or zero. Other useful values of ``T`` include ``ASCIIString``, ``String``, and ``Any``. + If ``T`` is a numeric type, the result is an array of that type, with any non-numeric elements as ``NaN`` for floating-point types, or zero. Other useful values of ``T`` include ``ASCIIString``, ``AbstractString``, and ``Any``. If ``header`` is ``true``, the first row of data will be read as header and the tuple ``(data_cells, header_cells)`` is returned instead of only ``data_cells``. @@ -2168,7 +2168,7 @@ Text I/O .. function:: writedlm(f, A, delim='\t') - Write ``A`` (a vector, matrix or an iterable collection of iterable rows) as text to ``f`` (either a filename string or an ``IO`` stream) using the given delimeter ``delim`` (which defaults to tab, but can be any printable Julia object, typically a ``Char`` or ``String``). + Write ``A`` (a vector, matrix or an iterable collection of iterable rows) as text to ``f`` (either a filename string or an ``IO`` stream) using the given delimeter ``delim`` (which defaults to tab, but can be any printable Julia object, typically a ``Char`` or ``AbstractString``). For example, two vectors ``x`` and ``y`` of the same length can be written as two columns of tab-delimited text to ``f`` by @@ -2237,7 +2237,7 @@ Julia environments (such as the IPython-based IJulia notebook). requested MIME type *only*, throwing a ``MethodError`` if this type is not supported by either the display(s) or by ``x``. With these variants, one can also supply the "raw" data in the requested MIME - type by passing ``x::String`` (for MIME types with text-based storage, + type by passing ``x::AbstractString`` (for MIME types with text-based storage, such as text/html or application/postscript) or ``x::Vector{Uint8}`` (for binary MIME types). @@ -2295,23 +2295,23 @@ Julia environments (such as the IPython-based IJulia notebook). .. function:: reprmime(mime, x) - Returns a ``String`` or ``Vector{Uint8}`` containing the + Returns a ``AbstractString`` or ``Vector{Uint8}`` containing the representation of ``x`` in the requested ``mime`` type, as written by ``writemime`` (throwing a ``MethodError`` if no appropriate - ``writemime`` is available). A ``String`` is returned for MIME + ``writemime`` is available). A ``AbstractString`` is returned for MIME types with textual representations (such as ``"text/html"`` or ``"application/postscript"``), whereas binary data is returned as ``Vector{Uint8}``. (The function ``istext(mime)`` returns whether or not Julia treats a given ``mime`` type as text.) - As a special case, if ``x`` is a ``String`` (for textual MIME types) + As a special case, if ``x`` is a ``AbstractString`` (for textual MIME types) or a ``Vector{Uint8}`` (for binary MIME types), the ``reprmime`` function assumes that ``x`` is already in the requested ``mime`` format and simply returns ``x``. .. function:: stringmime(mime, x) - Returns a ``String`` containing the representation of ``x`` in the + Returns a ``AbstractString`` containing the representation of ``x`` in the requested ``mime`` type. This is similar to ``reprmime`` except that binary data is base64-encoded as an ASCII string. @@ -3771,13 +3771,13 @@ Numbers .. function:: BigInt(x) - Create an arbitrary precision integer. ``x`` may be an ``Int`` (or anything that can be converted to an ``Int``) or a ``String``. + Create an arbitrary precision integer. ``x`` may be an ``Int`` (or anything that can be converted to an ``Int``) or a ``AbstractString``. The usual mathematical operators are defined for this type, and results are promoted to a ``BigInt``. .. function:: BigFloat(x) Create an arbitrary precision floating point number. ``x`` may be - an ``Integer``, a ``Float64``, a ``String`` or a ``BigInt``. The + an ``Integer``, a ``Float64``, a ``AbstractString`` or a ``BigInt``. The usual mathematical operators are defined for this type, and results are promoted to a ``BigFloat``. Note that because floating-point numbers are not exactly-representable in decimal notation, @@ -5348,7 +5348,7 @@ System Send a signal to a process. The default is to terminate the process. -.. function:: open(command, mode::String="r", stdio=DevNull) +.. function:: open(command, mode::AbstractString="r", stdio=DevNull) Start running ``command`` asynchronously, and return a tuple ``(stream,process)``. If ``mode`` is ``"r"``, then ``stream`` @@ -5358,7 +5358,7 @@ System and ``stdio`` optionally specifies the process's standard output stream. -.. function:: open(f::Function, command, mode::String="r", stdio=DevNull) +.. function:: open(f::Function, command, mode::AbstractString="r", stdio=DevNull) Similar to ``open(command, mode, stdio)``, but calls ``f(stream)`` on the resulting read or write stream, then closes the stream @@ -5408,19 +5408,19 @@ System Redirect the standard error stream of a process. -.. function:: gethostname() -> String +.. function:: gethostname() -> AbstractString Get the local machine's host name. -.. function:: getipaddr() -> String +.. function:: getipaddr() -> AbstractString Get the IP address of the local machine, as a string of the form "x.x.x.x". -.. function:: pwd() -> String +.. function:: pwd() -> AbstractString Get the current working directory. -.. function:: cd(dir::String) +.. function:: cd(dir::AbstractString) Set the current working directory. @@ -5533,7 +5533,7 @@ C Interface .. function:: ccall((symbol, library) or fptr, RetType, (ArgType1, ...), ArgVar1, ...) - Call function in C-exported shared library, specified by ``(function name, library)`` tuple, where each component is a String or :Symbol. Alternatively, + Call function in C-exported shared library, specified by ``(function name, library)`` tuple, where each component is a AbstractString or :Symbol. Alternatively, ccall may be used to call a function pointer returned by dlsym, but note that this usage is generally discouraged to facilitate future static compilation. Note that the argument type tuple must be a literal tuple, and not a tuple-valued variable or expression. @@ -5557,7 +5557,7 @@ C Interface bar = cfunction(foo, Float64, ()) -.. function:: dlopen(libfile::String [, flags::Integer]) +.. function:: dlopen(libfile::AbstractString [, flags::Integer]) Load a shared library, returning an opaque handle. @@ -5573,7 +5573,7 @@ C Interface symbols to be available for usage in other shared libraries, in situations where there are dependencies between shared libraries. -.. function:: dlopen_e(libfile::String [, flags::Integer]) +.. function:: dlopen_e(libfile::AbstractString [, flags::Integer]) Similar to :func:`dlopen`, except returns a ``NULL`` pointer instead of raising errors. @@ -5820,7 +5820,7 @@ C Interface Errors ------ -.. function:: error(message::String) +.. function:: error(message::AbstractString) Raise an error with the given message diff --git a/doc/stdlib/dates.rst b/doc/stdlib/dates.rst index d6bd8bc07b96d..0481a8347f566 100644 --- a/doc/stdlib/dates.rst +++ b/doc/stdlib/dates.rst @@ -67,7 +67,7 @@ alternatively, you could call ``using Dates`` to bring all exported functions in Converts a ``Date`` type to a ``DateTime``. The hour, minute, second, and millisecond parts of the new ``DateTime`` are assumed to be zero. -.. function:: DateTime(dt::String, format::String; locale="english") -> DateTime +.. function:: DateTime(dt::AbstractString, format::AbstractString; locale="english") -> DateTime Construct a DateTime type by parsing the ``dt`` date string following the pattern given in the ``format`` string. The following codes can be used for constructing format strings: @@ -117,7 +117,7 @@ alternatively, you could call ``using Dates`` to bring all exported functions in Converts a ``DateTime`` type to a ``Date``. The hour, minute, second, and millisecond parts of the ``DateTime`` are truncated, so only the year, month and day parts are used in construction. -.. function:: Date(dt::String, format::String; locale="english") -> Date +.. function:: Date(dt::AbstractString, format::AbstractString; locale="english") -> Date Construct a Date type by parsing a ``dt`` date string following the pattern given in the ``format`` string. Follows the same conventions as ``DateTime`` above. @@ -172,12 +172,12 @@ Accessor Functions Query Functions ~~~~~~~~~~~~~~~ -.. function:: dayname(dt::TimeType; locale="english") -> String +.. function:: dayname(dt::TimeType; locale="english") -> AbstractString Return the full day name corresponding to the day of the week of the Date or DateTime in the given ``locale``. -.. function:: dayabbr(dt::TimeType; locale="english") -> String +.. function:: dayabbr(dt::TimeType; locale="english") -> AbstractString Return the abbreviated name corresponding to the day of the week of the Date or DateTime in the given ``locale``. @@ -199,11 +199,11 @@ Query Functions the last day of a week in a month by including ``dayofweekofmonth(dt) == daysofweekinmonth(dt)`` in the adjuster function. -.. function:: monthname(dt::TimeType; locale="english") -> String +.. function:: monthname(dt::TimeType; locale="english") -> AbstractString Return the full name of the month of the Date or DateTime in the given ``locale``. -.. function:: monthabbr(dt::TimeType; locale="english") -> String +.. function:: monthabbr(dt::TimeType; locale="english") -> AbstractString Return the abbreviated month name of the Date or DateTime in the given ``locale``. diff --git a/doc/stdlib/file.rst b/doc/stdlib/file.rst index e38620c1f1b3a..9b4d73aedfbd4 100644 --- a/doc/stdlib/file.rst +++ b/doc/stdlib/file.rst @@ -63,64 +63,64 @@ Filesystem Returns ``true`` if the current user has permission to write to ``path``, ``false`` otherwise. -.. function:: homedir() -> String +.. function:: homedir() -> AbstractString Return the current user's home directory. -.. function:: dirname(path::String) -> String +.. function:: dirname(path::AbstractString) -> AbstractString Get the directory part of a path. -.. function:: basename(path::String) -> String +.. function:: basename(path::AbstractString) -> AbstractString Get the file name part of a path. -.. function:: @__FILE__() -> String +.. function:: @__FILE__() -> AbstractString ``@__FILE__`` expands to a string with the absolute path and file name of the script being run. Returns ``nothing`` if run from a REPL or an empty string if evaluated by ``julia -e ``. -.. function:: isabspath(path::String) -> Bool +.. function:: isabspath(path::AbstractString) -> Bool Determines whether a path is absolute (begins at the root directory). -.. function:: isdirpath(path::String) -> Bool +.. function:: isdirpath(path::AbstractString) -> Bool Determines whether a path refers to a directory (for example, ends with a path separator). -.. function:: joinpath(parts...) -> String +.. function:: joinpath(parts...) -> AbstractString Join path components into a full path. If some argument is an absolute path, then prior components are dropped. -.. function:: abspath(path::String) -> String +.. function:: abspath(path::AbstractString) -> AbstractString Convert a path to an absolute path by adding the current directory if necessary. -.. function:: normpath(path::String) -> String +.. function:: normpath(path::AbstractString) -> AbstractString Normalize a path, removing "." and ".." entries. -.. function:: realpath(path::String) -> String +.. function:: realpath(path::AbstractString) -> AbstractString Canonicalize a path by expanding symbolic links and removing "." and ".." entries. -.. function:: expanduser(path::String) -> String +.. function:: expanduser(path::AbstractString) -> AbstractString On Unix systems, replace a tilde character at the start of a path with the current user's home directory. -.. function:: splitdir(path::String) -> (String,String) +.. function:: splitdir(path::AbstractString) -> (AbstractString,AbstractString) Split a path into a tuple of the directory name and file name. -.. function:: splitdrive(path::String) -> (String,String) +.. function:: splitdrive(path::AbstractString) -> (AbstractString,AbstractString) On Windows, split a path into the drive letter part and the path part. On Unix systems, the first component is always the empty string. -.. function:: splitext(path::String) -> (String,String) +.. function:: splitext(path::AbstractString) -> (AbstractString,AbstractString) If the last component of a path contains a dot, split the path into everything before the dot and everything including and after the dot. Otherwise, return diff --git a/doc/stdlib/pkg.rst b/doc/stdlib/pkg.rst index 13ebb6266852e..564291f6749b4 100644 --- a/doc/stdlib/pkg.rst +++ b/doc/stdlib/pkg.rst @@ -6,19 +6,19 @@ Package Manager Functions All package manager functions are defined in the ``Pkg`` module. None of the ``Pkg`` module's functions are exported; to use them, you'll need to prefix each function call with an explicit ``Pkg.``, e.g. ``Pkg.status()`` or ``Pkg.dir()``. -.. function:: dir() -> String +.. function:: dir() -> AbstractString Returns the absolute path of the package directory. This defaults to ``joinpath(homedir(),".julia")`` on all platforms (i.e. ``~/.julia`` in UNIX shell syntax). If the ``JULIA_PKGDIR`` environment variable is set, that path is used instead. If ``JULIA_PKGDIR`` is a relative path, it is interpreted relative to whatever the current working directory is. -.. function:: dir(names...) -> String +.. function:: dir(names...) -> AbstractString Equivalent to ``normpath(Pkg.dir(),names...)`` – i.e. it appends path components to the package directory and normalizes the resulting path. In particular, ``Pkg.dir(pkg)`` returns the path to the package ``pkg``. -.. function:: init(meta::String=DEFAULT_META, branch::String=META_BRANCH) +.. function:: init(meta::AbstractString=DEFAULT_META, branch::AbstractString=META_BRANCH) Initialize ``Pkg.dir()`` as a package directory. This will be done automatically when the ``JULIA_PKGDIR`` is not set and ``Pkg.dir()`` uses its default value. diff --git a/doc/stdlib/sparse.rst b/doc/stdlib/sparse.rst index 486694e15447c..3033e31bdf686 100644 --- a/doc/stdlib/sparse.rst +++ b/doc/stdlib/sparse.rst @@ -97,4 +97,4 @@ Sparse matrices support much of the same set of operations as dense matrices. Th val = vals[j] # perform sparse wizardry... end - end \ No newline at end of file + end diff --git a/doc/tabcomplete.jl b/doc/tabcomplete.jl index eec469153c15d..a584ab39129b9 100644 --- a/doc/tabcomplete.jl +++ b/doc/tabcomplete.jl @@ -10,7 +10,7 @@ include("../base/latex_symbols.jl") #Sometimes there is more than one way... latexvals = Dict() for (key, val) in latex_symbols - latexvals[val] = push!(get(latexvals, val, String[]), "\\"*key) + latexvals[val] = push!(get(latexvals, val, AbstractString[]), "\\"*key) end #Join with Unicode names to aid in lookup diff --git a/test/collections.jl b/test/collections.jl index cee54e6b34ae1..41867d3448a4f 100644 --- a/test/collections.jl +++ b/test/collections.jl @@ -96,14 +96,14 @@ let d = Dict{UTF8String, Vector{Int}}() d["a"] = [1, 2] @test_throws MethodError d["b"] = 1 - @test isa(repr(d), String) # check that printable without error + @test isa(repr(d), AbstractString) # check that printable without error end # issue #2344 let local bar bestkey(d, key) = key - bestkey{K<:String,V}(d::Associative{K,V}, key) = string(key) + bestkey{K<:AbstractString,V}(d::Associative{K,V}, key) = string(key) bar(x) = bestkey(x, :y) @test bar(Dict(:x => [1,2,5])) == :y @test bar(Dict("x" => [1,2,5])) == "y" @@ -143,7 +143,7 @@ end data_in = [ (rand(1:1000), randstring(2)) for _ in 1:1001 ] # Populate the first dict -d1 = Dict{Int, String}() +d1 = Dict{Int, AbstractString}() for (k,v) in data_in d1[k] = v end @@ -155,7 +155,7 @@ for i in 1:length(data_in) end # Inserting data in different (shuffled) order should result in # equivalent dict. -d2 = Dict{Int, String}() +d2 = Dict{Int, AbstractString}() for (k,v) in data_in d2[k] = v end @@ -179,7 +179,7 @@ d4[1001] = randstring(3) # are compared. This is not necessarily desirable. These tests are # descriptive rather than proscriptive. @test !isequal(Dict(1 => 2), Dict("dog" => "bone")) -@test isequal(Dict{Int,Int}(), Dict{String,String}()) +@test isequal(Dict{Int,Int}(), Dict{AbstractString,AbstractString}()) # get! (get with default values assigned to the given location) @@ -242,7 +242,7 @@ d = Dict{Any,Any}([x => 1 for x in ['a', 'b', 'c']]) @test d == Dict('a'=>1, 'b'=>1, 'c'=> 1) # issue #2629 -d = Dict{String,String}([ a => "foo" for a in ["a","b","c"]]) +d = Dict{AbstractString,AbstractString}([ a => "foo" for a in ["a","b","c"]]) @test d == Dict("a"=>"foo","b"=>"foo","c"=>"foo") # issue #5886 @@ -316,7 +316,7 @@ data_out = collect(s) # eltype @test is(eltype(Set([1,"hello"])), Any) -@test is(eltype(Set{String}()), String) +@test is(eltype(Set{AbstractString}()), AbstractString) # no duplicates s = Set([1,2,3]) @@ -473,10 +473,10 @@ s3 = Set{ASCIIString}(["baz"]) # Comparison of unrelated types seems rather inconsistent -@test isequal(Set{Int}(), Set{String}()) -@test !isequal(Set{Int}(), Set{String}([""])) -@test !isequal(Set{String}(), Set{Int}([0])) -@test !isequal(Set{Int}([1]), Set{String}()) +@test isequal(Set{Int}(), Set{AbstractString}()) +@test !isequal(Set{Int}(), Set{AbstractString}([""])) +@test !isequal(Set{AbstractString}(), Set{Int}([0])) +@test !isequal(Set{Int}([1]), Set{AbstractString}()) @test isequal(Set{Any}([1,2,3]), Set{Int}([1,2,3])) @test isequal(Set{Int}([1,2,3]), Set{Any}([1,2,3])) diff --git a/test/core.jl b/test/core.jl index f18e4a7d512dd..d7f2d27279592 100644 --- a/test/core.jl +++ b/test/core.jl @@ -154,21 +154,21 @@ end # join @test typejoin(Int8,Int16) === Signed -@test typejoin(Int,String) === Any +@test typejoin(Int,AbstractString) === Any @test typejoin(Array{Float64},BitArray) <: AbstractArray @test typejoin(Array{Bool},BitArray) <: AbstractArray{Bool} @test typejoin((Int,Int8),(Int8,Float64)) === (Signed,Real) @test Base.typeseq(typejoin((ASCIIString,ASCIIString),(UTF8String,ASCIIString), (ASCIIString,UTF8String),(Int,ASCIIString,Int)), - (Any,String,Int...)) + (Any,AbstractString,Int...)) @test Base.typeseq(typejoin((Int8,Int...),(Int8,Int8)), (Int8,Signed...)) @test Base.typeseq(typejoin((Int8,Int...),(Int8,Int8...)), (Int8,Signed...)) @test Base.typeseq(typejoin((Int8,Uint8,Int...),(Int8,Int8...)), (Int8,Integer...)) -@test Base.typeseq(typejoin(Union(Int,String),Int), Union(Int,String)) -@test Base.typeseq(typejoin(Union(Int,String),Int8), Any) +@test Base.typeseq(typejoin(Union(Int,AbstractString),Int), Union(Int,AbstractString)) +@test Base.typeseq(typejoin(Union(Int,AbstractString),Int8), Any) @test promote_type(Bool,Bottom) === Bool @@ -232,7 +232,7 @@ end type FooFoo{A,B} y::FooFoo{A} end -@test FooFoo{Int} <: FooFoo{Int,String}.types[1] +@test FooFoo{Int} <: FooFoo{Int,AbstractString}.types[1] x = (2,3) @@ -929,7 +929,7 @@ begin Y(::Type{X1474}) = 3 @test Y(X1474) == 3 @test Y(X1474{Int}) == 2 - @test Y(X1474{Int,String}) == 1 + @test Y(X1474{Int,AbstractString}) == 1 end # issue #2562 @@ -1063,7 +1063,7 @@ function foo(x) end return ret end -x = Array(Union(Dict{Int64,String},Array{Int64,3},Number,String,Void), 3) +x = Array(Union(Dict{Int64,AbstractString},Array{Int64,3},Number,AbstractString,Void), 3) x[1] = 1.0 x[2] = 2.0 x[3] = 3.0 @@ -1146,7 +1146,7 @@ end @test isa(Foo4376{Float32}(Foo4376{Int}(2)), Foo4376{Float32}) type _0_test_ctor_syntax_ - _0_test_ctor_syntax_{T<:String}(files::Vector{T},step) = 0 + _0_test_ctor_syntax_{T<:AbstractString}(files::Vector{T},step) = 0 end # issue #4413 @@ -1625,8 +1625,8 @@ end # issue #5577 f5577(::Any) = false f5577(::Type) = true -@test !f5577((Int,String,2)) -@test f5577(((Int,String),String)) +@test !f5577((Int,AbstractString,2)) +@test f5577(((Int,AbstractString),AbstractString)) @test f5577(Int) @test !f5577(2) @@ -1764,7 +1764,7 @@ f6980(::Union(Int, Float64), ::B6980) = true # issue #7049 typealias Maybe7049{T} Union(T,Void) -function ttt7049(;init::Maybe7049{Union(String,(Int,Char))} = nothing) +function ttt7049(;init::Maybe7049{Union(AbstractString,(Int,Char))} = nothing) string("init=", init) end @test ttt7049(init="a") == "init=a" diff --git a/test/dates.jl b/test/dates.jl index 711a31db4c24b..96f397b2df2dd 100644 --- a/test/dates.jl +++ b/test/dates.jl @@ -13,4 +13,4 @@ include("dates/ranges.jl") include("dates/adjusters.jl") include("dates/io.jl") -end \ No newline at end of file +end diff --git a/test/dates/accessors.jl b/test/dates/accessors.jl index 85f7f01251ce5..3d441d45e7a0f 100644 --- a/test/dates/accessors.jl +++ b/test/dates/accessors.jl @@ -189,4 +189,4 @@ dr = [a,a,a,a,a,a,a,a,a,a] @test Dates.hour(dr) == repmat([0],10) @test Dates.minute(dr) == repmat([0],10) @test Dates.second(dr) == repmat([0],10) -@test Dates.millisecond(dr) == repmat([0],10) \ No newline at end of file +@test Dates.millisecond(dr) == repmat([0],10) diff --git a/test/dates/adjusters.jl b/test/dates/adjusters.jl index 00b93e7df7ba0..4dcdae83eaa52 100644 --- a/test/dates/adjusters.jl +++ b/test/dates/adjusters.jl @@ -442,4 +442,4 @@ end) == 251 dt += Dates.Day(1) end return sum == 15 -end) == 15 # On average, there's one of those months every year \ No newline at end of file +end) == 15 # On average, there's one of those months every year diff --git a/test/dates/arithmetic.jl b/test/dates/arithmetic.jl index 127df38f0df35..4663a24db55c2 100644 --- a/test/dates/arithmetic.jl +++ b/test/dates/arithmetic.jl @@ -327,4 +327,4 @@ dt2 = dt + Dates.Year(1) @test Dates.hour(dt2) == 12 @test Dates.minute(dt2) == 30 @test Dates.second(dt2) == 45 -@test Dates.millisecond(dt2) == 500 \ No newline at end of file +@test Dates.millisecond(dt2) == 500 diff --git a/test/dates/conversions.jl b/test/dates/conversions.jl index d5b138f1f86f5..bb6750172ac4f 100644 --- a/test/dates/conversions.jl +++ b/test/dates/conversions.jl @@ -43,4 +43,4 @@ @test typeof(Dates.now()) <: Dates.DateTime @test typeof(Dates.today()) <: Dates.Date -@test typeof(Dates.now(Dates.UTC)) <: Dates.DateTime \ No newline at end of file +@test typeof(Dates.now(Dates.UTC)) <: Dates.DateTime diff --git a/test/gitutils.jl b/test/gitutils.jl index 1c6655905bb9b..abd494af6bea4 100644 --- a/test/gitutils.jl +++ b/test/gitutils.jl @@ -9,7 +9,7 @@ end function mktree(d::Dict) lstree = "" for (name, data) in d - if isa(data, String) + if isa(data, AbstractString) sha1 = write_and_readchomp(data, `git hash-object -w --stdin`) lstree *= "100644 blob $sha1\t$name\n" elseif isa(data, Dict) @@ -24,7 +24,7 @@ function mktree(d::Dict) write_and_readchomp(lstree, `git mktree`) end -function verify_tree(d::Dict, tree::String) +function verify_tree(d::Dict, tree::AbstractString) # check that tree matches d seen = Set() for line in eachline(`git ls-tree $tree`) @@ -33,7 +33,7 @@ function verify_tree(d::Dict, tree::String) perm, kind, sha1, name = m.captures @test haskey(d,name) data = d[name] - if isa(data, String) + if isa(data, AbstractString) @test kind == "blob" @test data == readall(`git cat-file blob $sha1`) elseif isa(data, Dict) @@ -58,7 +58,7 @@ function verify_work(d::Dict) continue end @test ispath(name) - if isa(data, String) + if isa(data, AbstractString) @test isfile(name) @test readall(name) == data elseif isa(data, Dict) @@ -82,7 +82,7 @@ function git_verify(h::Dict, i::Dict, w::Dict) verify_work(w) end -function git_setup(h::Dict, i::Dict, w::Dict, parents::String...) +function git_setup(h::Dict, i::Dict, w::Dict, parents::AbstractString...) # create tree objects headt = mktree(h) index = mktree(i) diff --git a/test/linalg/lapack.jl b/test/linalg/lapack.jl index 3fac7bd044fe2..713189f04d3a9 100644 --- a/test/linalg/lapack.jl +++ b/test/linalg/lapack.jl @@ -51,4 +51,4 @@ let # Issue #7886 x, r = LAPACK.gelsy!([0 1; 0 2; 0 3.], [2, 4, 6.]) @test_approx_eq x [0,2] @test r == 1 -end \ No newline at end of file +end diff --git a/test/linalg/tridiag.jl b/test/linalg/tridiag.jl index 45445546606f7..8c00a8a7e4581 100644 --- a/test/linalg/tridiag.jl +++ b/test/linalg/tridiag.jl @@ -121,4 +121,4 @@ for relty in (Float32, Float64), elty in (relty, Complex{relty}) for op in (+, -, *) @test_approx_eq full(op(A, B)) op(fA, fB) end -end \ No newline at end of file +end diff --git a/test/netload/memtest.jl b/test/netload/memtest.jl index 9950cac4cc798..dbef7f2ea7171 100644 --- a/test/netload/memtest.jl +++ b/test/netload/memtest.jl @@ -60,4 +60,4 @@ end run_mtest("create_strings", () -> mtest_create_strings()) run_mtest("remotecall_fetch", () -> mtest_remotecall_fetch()) - \ No newline at end of file + diff --git a/test/perf/blas/perf.jl b/test/perf/blas/perf.jl index c3ab979dc2d0f..88563e04b953f 100644 --- a/test/perf/blas/perf.jl +++ b/test/perf/blas/perf.jl @@ -2,4 +2,4 @@ include("../perfutil.jl") include("level1.jl") include("level2.jl") -include("level3.jl") \ No newline at end of file +include("level3.jl") diff --git a/test/perf/kernel/json.jl b/test/perf/kernel/json.jl index 48329a5a78ed8..a7844b0d6a80f 100644 --- a/test/perf/kernel/json.jl +++ b/test/perf/kernel/json.jl @@ -2,15 +2,15 @@ #Adapted from http://www.mathworks.com/matlabcentral/fileexchange/23393 #Original BSD Licence, (c) 2011, François Glineur -function parse_json(strng::String) +function parse_json(strng::AbstractString) pos = 1 len = length(strng) - # String delimiters and escape characters are identified beforehand to improve speed + # AbstractString delimiters and escape characters are identified beforehand to improve speed # esc = regexp(str, "[\"\\\\]"); index_esc = 1; len_esc = length(esc); #TODO Enable for speed function parse_object() parse_char('{') - object = Dict{String, Any}() + object = Dict{AbstractString, Any}() if next_char() != '}' while true str = parse_string() @@ -74,7 +74,7 @@ function parse_json(strng::String) function parse_string() if strng[pos] != '"' - error("String starting with quotation expected at position $pos") + error("AbstractString starting with quotation expected at position $pos") else pos = pos + 1 end diff --git a/test/perf/shootout/k_nucleotide.jl b/test/perf/shootout/k_nucleotide.jl index 9aabd77945ba1..e4c75121e869e 100644 --- a/test/perf/shootout/k_nucleotide.jl +++ b/test/perf/shootout/k_nucleotide.jl @@ -6,8 +6,8 @@ import Base.isless -function count(data::String, n::Int) - counts = Dict{String, Int}() +function count(data::AbstractString, n::Int) + counts = Dict{AbstractString, Int}() top = length(data) - n + 1 for i = 1:top s = data[i : i+n-1] @@ -20,12 +20,12 @@ function count(data::String, n::Int) counts end -function count_one(data::String, s::String) +function count_one(data::AbstractString, s::AbstractString) count(data, length(s))[s] end type KNuc - name::String + name::AbstractString count::Int end @@ -37,7 +37,7 @@ function isless(x::KNuc, y::KNuc) x.count > y.count end -function sorted_array(m::Dict{String, Int}) +function sorted_array(m::Dict{AbstractString, Int}) kn = Array(KNuc, length(m)) i = 1 for elem in m diff --git a/test/perf/shootout/perf.jl b/test/perf/shootout/perf.jl index ce62be5b35c2c..94a9612042a33 100644 --- a/test/perf/shootout/perf.jl +++ b/test/perf/shootout/perf.jl @@ -1,7 +1,7 @@ include("../perfutil.jl") #If running from .. directory, include "shootout/" path to data file -rpath(filename::String) = string(contains(pwd(), "shootout") ? "" : "shootout/", filename) +rpath(filename::AbstractString) = string(contains(pwd(), "shootout") ? "" : "shootout/", filename) include("binary_trees.jl") @timeit binary_trees(10) "binary_trees" "Allocate and deallocate many many binary trees" diff --git a/test/perf/sort/perf.jl b/test/perf/sort/perf.jl index 25b0e296ddb8e..5f8c46d3c85b5 100644 --- a/test/perf/sort/perf.jl +++ b/test/perf/sort/perf.jl @@ -13,7 +13,7 @@ randint_fn!(m::Int) = d -> rand!(1:m,d) # If we're reporting to codespeed, only do a few tests. if codespeed for (T, typename, randfn!) in [(Int, string(Int), randint_fn!(10)), - (String, "String_10", randstr_fn!(10))] + (AbstractString, "String_10", randstr_fn!(10))] for size in [2^6,2^16] for s in sorts if s == InsertionSort && size != 2^6; continue; end @@ -34,14 +34,14 @@ if codespeed else for (T, typename, randfn!) in [(Int, string(Int), randint_fn!(10)), (Float64, string(Float64), rand!), - (String, "String_05", randstr_fn!(5)), - (String, "String_10", randstr_fn!(10))] + (AbstractString, "String_05", randstr_fn!(5)), + (AbstractString, "String_10", randstr_fn!(10))] for logsize = 6:2:18 size = 2^logsize for s in sorts - if s == RadixSort && T == String continue end #Radix sort not implemented + if s == RadixSort && T == AbstractString continue end #Radix sort not implemented if s == InsertionSort && logsize >=14 continue end #Too slow - println(s, s==RadixSort, s, typename, typename==String, logsize) + println(s, s==RadixSort, s, typename, typename==AbstractString, logsize) data = Array(T, size) gc() diff --git a/test/perf/spell/perf.jl b/test/perf/spell/perf.jl index 7c85f5cf259b6..37b08666e144e 100644 --- a/test/perf/spell/perf.jl +++ b/test/perf/spell/perf.jl @@ -21,7 +21,7 @@ include("../perfutil.jl") words(text) = eachmatch(r"[a-z]+", lowercase(text)) function train(features) - model = DefaultDict(String, Int, 1) + model = DefaultDict(AbstractString, Int, 1) for f in features model[f.match] += 1 end @@ -32,7 +32,7 @@ const NWORDS = train(words(bytestring(get("http://norvig.com/big.txt").body))) const alphabet = "abcdefghijklmnopqrstuvwxyz" -function edits1(word::String) +function edits1(word::AbstractString) splits = [(word[1:i], word[i+1:end]) for i=0:length(word) ] deletes = ["$a$(b[2:end])" for (a,b) in splits[1:end-1]] transposes = ["$a$(b[2])$(b[1])$(b[3:end])" for (a,b) in splits[1:end-2]] @@ -41,8 +41,8 @@ function edits1(word::String) return Set([deletes; transposes; replaces[:]; inserts[:]]) end -function known_edits2(word::String) - xs = Set{String}() +function known_edits2(word::AbstractString) + xs = Set{AbstractString}() for e1 in edits1(word) for e2 in edits1(e1) haskey(NWORDS, e2) && push!(xs, e2) @@ -52,14 +52,14 @@ function known_edits2(word::String) end function known(words) - xs = Set{String}() + xs = Set{AbstractString}() for word in words haskey(NWORDS, word) && push!(xs, word) end xs end -function correct(word::String) +function correct(word::AbstractString) candidates = known([word]) length(candidates) == 0 && (candidates = known(edits1(word))) length(candidates) == 0 && (candidates = known_edits2(word) ) diff --git a/test/reflection.jl b/test/reflection.jl index bc49a18f47e32..d93e7affa686b 100644 --- a/test/reflection.jl +++ b/test/reflection.jl @@ -8,11 +8,11 @@ redirect_stderr() # It's hard to really test these, but just running them should be # sufficient to catch segfault bugs. -@test code_native(ismatch, (Regex, String)) == nothing +@test code_native(ismatch, (Regex, AbstractString)) == nothing @test code_native(+, (Int, Int)) == nothing @test code_native(+, (Array{Float32}, Array{Float32})) == nothing -@test code_llvm(ismatch, (Regex, String)) == nothing +@test code_llvm(ismatch, (Regex, AbstractString)) == nothing @test code_llvm(+, (Int, Int)) == nothing @test code_llvm(+, (Array{Float32}, Array{Float32})) == nothing @@ -30,4 +30,4 @@ redirect_stderr(olderr) @test !isbits(Array{Int}) @test isbits(Float32) @test isbits(Int) -@test !isbits(String) +@test !isbits(AbstractString) diff --git a/test/replcompletions.jl b/test/replcompletions.jl index 4423921146a22..ea1f372d1947d 100644 --- a/test/replcompletions.jl +++ b/test/replcompletions.jl @@ -181,4 +181,4 @@ end @test file in c end rm(tmp) -end \ No newline at end of file +end diff --git a/test/strings.jl b/test/strings.jl index dabbded9b4762..4d6eb8d9549fd 100644 --- a/test/strings.jl +++ b/test/strings.jl @@ -905,8 +905,8 @@ bin_val = hex2bytes("07bf") @test (@sprintf "%s %s %s %d %d %d %f %f %f" Any[10^x+y for x=1:3,y=1:3 ]...) == "11 101 1001 12 102 1002 13.000000 103.000000 1003.000000" # issue #4183 -@test split(SubString(ascii("x"), 2, 0), "y") == String[""] -@test split(SubString(utf8("x"), 2, 0), "y") == String[""] +@test split(SubString(ascii("x"), 2, 0), "y") == AbstractString[""] +@test split(SubString(utf8("x"), 2, 0), "y") == AbstractString[""] # issue #4586 @test rsplit(RevString("ailuj"),'l') == ["ju","ia"]