Skip to content

Commit

Permalink
replace bytestring with String
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed May 19, 2016
1 parent 1873dd9 commit 24efdf7
Show file tree
Hide file tree
Showing 79 changed files with 399 additions and 390 deletions.
12 changes: 6 additions & 6 deletions base/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type PromptState <: ModeState
indent::Int
end

input_string(s::PromptState) = bytestring(s.input_buffer)
input_string(s::PromptState) = String(s.input_buffer)

input_string_newlines(s::PromptState) = count(c->(c == '\n'), input_string(s))
function input_string_newlines_aftercursor(s::PromptState)
Expand Down Expand Up @@ -386,7 +386,7 @@ function edit_move_up(buf::IOBuffer)
npos = rsearch(buf.data, '\n', position(buf))
npos == 0 && return false # we're in the first line
# We're interested in character count, not byte count
offset = length(bytestring(buf.data[(npos+1):(position(buf))]))
offset = length(String(buf.data[(npos+1):(position(buf))]))
npos2 = rsearch(buf.data, '\n', npos-1)
seek(buf, npos2)
for _ = 1:offset
Expand All @@ -407,7 +407,7 @@ end
function edit_move_down(buf::IOBuffer)
npos = rsearch(buf.data[1:buf.size], '\n', position(buf))
# We're interested in character count, not byte count
offset = length(bytestring(buf.data[(npos+1):(position(buf))]))
offset = length(String(buf.data[(npos+1):(position(buf))]))
npos2 = search(buf.data[1:buf.size], '\n', position(buf)+1)
if npos2 == 0 #we're in the last line
return false
Expand Down Expand Up @@ -986,7 +986,7 @@ function history_set_backward(s::SearchState, backward)
s.backward = backward
end

input_string(s::SearchState) = bytestring(s.query_buffer)
input_string(s::SearchState) = String(s.query_buffer)

function reset_state(s::SearchState)
if s.query_buffer.size != 0
Expand Down Expand Up @@ -1035,7 +1035,7 @@ refresh_multi_line(termbuf::TerminalBuffer, terminal::UnixTerminal,
s::Union{PromptState,PrefixSearchState}) = s.ias =
refresh_multi_line(termbuf, terminal, buffer(s), s.ias, s, indent = s.indent)

input_string(s::PrefixSearchState) = bytestring(s.response_buffer)
input_string(s::PrefixSearchState) = String(s.response_buffer)

# a meta-prompt that presents itself as parent_prompt, but which has an independent keymap
# for prefix searching
Expand Down Expand Up @@ -1153,7 +1153,7 @@ function enter_prefix_search(s::MIState, p::PrefixHistoryPrompt, backward::Bool)
pss = state(s, p)
pss.parent = parent
pss.histprompt.parent_prompt = parent
pss.prefix = bytestring(pointer(buf.data), position(buf))
pss.prefix = String(pointer(buf.data), position(buf))
copybuf!(pss.response_buffer, buf)
pss.indent = state(s, parent).indent
pss.mi = s
Expand Down
18 changes: 9 additions & 9 deletions base/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,25 +271,25 @@ end

immutable LatexCompletions <: CompletionProvider; end

bytestring_beforecursor(buf::IOBuffer) = bytestring(buf.data[1:buf.ptr-1])
beforecursor(buf::IOBuffer) = String(buf.data[1:buf.ptr-1])

function complete_line(c::REPLCompletionProvider, s)
partial = bytestring_beforecursor(s.input_buffer)
partial = beforecursor(s.input_buffer)
full = LineEdit.input_string(s)
ret, range, should_complete = completions(full, endof(partial))
return ret, partial[range], should_complete
end

function complete_line(c::ShellCompletionProvider, s)
# First parse everything up to the current position
partial = bytestring_beforecursor(s.input_buffer)
partial = beforecursor(s.input_buffer)
full = LineEdit.input_string(s)
ret, range, should_complete = shell_completions(full, endof(partial))
return ret, partial[range], should_complete
end

function complete_line(c::LatexCompletions, s)
partial = bytestring_beforecursor(LineEdit.buffer(s))
partial = beforecursor(LineEdit.buffer(s))
full = LineEdit.input_string(s)
ret, range, should_complete = bslash_completions(full, endof(partial))[2]
return ret, partial[range], should_complete
Expand Down Expand Up @@ -383,7 +383,7 @@ function mode_idx(hist::REPLHistoryProvider, mode)
end

function add_history(hist::REPLHistoryProvider, s)
str = rstrip(bytestring(s.input_buffer))
str = rstrip(String(s.input_buffer))
isempty(strip(str)) && return
mode = mode_idx(hist, LineEdit.mode(s))
!isempty(hist.history) &&
Expand Down Expand Up @@ -497,7 +497,7 @@ function history_move_prefix(s::LineEdit.PrefixSearchState,
prefix::AbstractString,
backwards::Bool,
cur_idx = hist.cur_idx)
cur_response = bytestring(LineEdit.buffer(s))
cur_response = String(LineEdit.buffer(s))
# when searching forward, start at last_idx
if !backwards && hist.last_idx > 0
cur_idx = hist.last_idx
Expand Down Expand Up @@ -537,8 +537,8 @@ function history_search(hist::REPLHistoryProvider, query_buffer::IOBuffer, respo

qpos = position(query_buffer)
qpos > 0 || return true
searchdata = bytestring_beforecursor(query_buffer)
response_str = bytestring(response_buffer)
searchdata = beforecursor(query_buffer)
response_str = String(response_buffer)

# Alright, first try to see if the current match still works
a = position(response_buffer) + 1
Expand Down Expand Up @@ -589,7 +589,7 @@ const julia_green = "\033[1m\033[32m"

function return_callback(s)
ast = Base.syntax_deprecation_warnings(false) do
Base.parse_input_line(bytestring(LineEdit.buffer(s)))
Base.parse_input_line(String(LineEdit.buffer(s)))
end
if !isa(ast, Expr) || (ast.head != :continue && ast.head != :incomplete)
return true
Expand Down
2 changes: 0 additions & 2 deletions base/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ finalize(o::ANY) = ccall(:jl_finalize, Void, (Any,), o)
gc(full::Bool=true) = ccall(:jl_gc_collect, Void, (Cint,), full)
gc_enable(on::Bool) = ccall(:jl_gc_enable, Cint, (Cint,), on)!=0

bytestring(str::String) = str

# used by { } syntax
function cell_1d(xs::ANY...)
n = length(xs)
Expand Down
4 changes: 2 additions & 2 deletions base/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pointer(p::Cwstring) = convert(Ptr{Cwchar_t}, p)
pointer_to_string(p::Cstring, own::Bool=false) = pointer_to_string(convert(Ptr{UInt8}, p), own)

# convert strings to String etc. to pass as pointers
cconvert(::Type{Cstring}, s::AbstractString) = bytestring(s)
cconvert(::Type{Cstring}, s::AbstractString) = String(s)
cconvert(::Type{Cwstring}, s::AbstractString) = wstring(s)

containsnul(p::Ptr, len) = C_NULL != ccall(:memchr, Ptr{Cchar}, (Ptr{Cchar}, Cint, Csize_t), p, 0, len)
Expand All @@ -96,7 +96,7 @@ convert(::Type{Cstring}, s::Symbol) = Cstring(unsafe_convert(Ptr{Cchar}, s))

# FIXME: this should be handled by implicit conversion to Cwstring, but good luck with that
@windows_only function cwstring(s::AbstractString)
bytes = bytestring(s).data
bytes = String(s).data
0 in bytes && throw(ArgumentError("embedded NULs are not allowed in C strings: $(repr(s))"))
return push!(utf8to16(bytes), 0)
end
Expand Down
14 changes: 7 additions & 7 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function parse_input_line(s::String; filename::String="none")
ccall(:jl_parse_input_line, Any, (Ptr{UInt8}, Csize_t, Ptr{UInt8}, Csize_t),
s, sizeof(s), filename, sizeof(filename))
end
parse_input_line(s::AbstractString) = parse_input_line(bytestring(s))
parse_input_line(s::AbstractString) = parse_input_line(String(s))

function parse_input_line(io::IO)
s = ""
Expand Down Expand Up @@ -218,38 +218,38 @@ function process_options(opts::JLOptions)

# startup worker
if opts.worker != C_NULL
start_worker(bytestring(opts.worker)) # does not return
start_worker(String(opts.worker)) # does not return
end
# add processors
if opts.nprocs > 0
addprocs(opts.nprocs)
end
# load processes from machine file
if opts.machinefile != C_NULL
addprocs(load_machine_file(bytestring(opts.machinefile)))
addprocs(load_machine_file(String(opts.machinefile)))
end
# load file immediately on all processors
if opts.load != C_NULL
@sync for p in procs()
@async remotecall_fetch(include, p, bytestring(opts.load))
@async remotecall_fetch(include, p, String(opts.load))
end
end
# eval expression
if opts.eval != C_NULL
repl = false
eval(Main, parse_input_line(bytestring(opts.eval)))
eval(Main, parse_input_line(String(opts.eval)))
break
end
# eval expression and show result
if opts.print != C_NULL
repl = false
show(eval(Main, parse_input_line(bytestring(opts.print))))
show(eval(Main, parse_input_line(String(opts.print))))
println()
break
end
# eval expression but don't disable interactive mode
if opts.postboot != C_NULL
eval(Main, parse_input_line(bytestring(opts.postboot)))
eval(Main, parse_input_line(String(opts.postboot)))
end
# load file
if !isempty(ARGS) && !isempty(ARGS[1])
Expand Down
2 changes: 1 addition & 1 deletion base/dSFMT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function dsfmt_get_idstring()
idstring = ccall((:dsfmt_get_idstring,:libdSFMT),
Ptr{UInt8},
())
return bytestring(idstring)
return String(idstring)
end

function dsfmt_get_min_array_size()
Expand Down
2 changes: 1 addition & 1 deletion base/datafmt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function readdlm_auto(input, dlm::Char, T::Type, eol::Char, auto::Bool; opts...)
input = readstring(input)
end
end
sinp = isa(input, Vector{UInt8}) ? bytestring(input) :
sinp = isa(input, Vector{UInt8}) ? String(input) :
isa(input, IO) ? readstring(input) :
input
readdlm_string(sinp, dlm, T, eol, auto, optsd)
Expand Down
13 changes: 10 additions & 3 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function depwarn(msg, funcsym)
opts = JLOptions()
if opts.depwarn > 0
ln = Int(unsafe_load(cglobal(:jl_lineno, Cint)))
fn = bytestring(unsafe_load(cglobal(:jl_filename, Ptr{Cchar})))
fn = String(unsafe_load(cglobal(:jl_filename, Ptr{Cchar})))
bt = backtrace()
caller = firstcaller(bt, funcsym)
if opts.depwarn == 1 # raise a warning
Expand Down Expand Up @@ -1160,10 +1160,17 @@ end
@deprecate_binding UTF8String String
@deprecate_binding ByteString String

@deprecate ascii(p::Ptr{UInt8}, len::Integer) ascii(bytestring(p, len))
@deprecate ascii(p::Ptr{UInt8}) ascii(bytestring(p))
@deprecate ascii(p::Ptr{UInt8}, len::Integer) ascii(String(p, len))
@deprecate ascii(p::Ptr{UInt8}) ascii(String(p))
@deprecate ascii(x) ascii(string(x))

@deprecate bytestring(s::Cstring) String(s)
@deprecate bytestring(v::Vector{UInt8}) String(v)
@deprecate bytestring(io::Base.AbstractIOBuffer) String(io)
@deprecate bytestring(p::Union{Ptr{Int8},Ptr{UInt8}}) String(p)
@deprecate bytestring(p::Union{Ptr{Int8},Ptr{UInt8}}, len::Integer) String(p,len)
@deprecate bytestring(s::AbstractString...) string(s...)

@deprecate ==(x::Char, y::Integer) UInt32(x) == y
@deprecate ==(x::Integer, y::Char) x == UInt32(y)
@deprecate isless(x::Char, y::Integer) UInt32(x) < y
Expand Down
4 changes: 2 additions & 2 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ function _truncate_at_width_or_chars(str, width, chars="", truncmark="…")
lastidx != 0 && str[lastidx] in chars && (lastidx = prevind(str, lastidx))
truncidx == 0 && (truncidx = lastidx)
if lastidx < endof(str)
return bytestring(SubString(str, 1, truncidx) * truncmark)
return String(SubString(str, 1, truncidx) * truncmark)
else
return bytestring(str)
return String(str)
end
end

Expand Down
16 changes: 0 additions & 16 deletions base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9705,22 +9705,6 @@ modified by the current file creation mask.
"""
mkdir

"""
bytestring(::Ptr{UInt8}, [length])
Create a string from the address of a C (0-terminated) string encoded in ASCII or UTF-8. A
copy is made; the ptr can be safely freed. If `length` is specified, the string does not
have to be 0-terminated.
"""
bytestring(::Ptr{UInt8},?)

"""
bytestring(s)
Convert a string to a contiguous byte array representation appropriate for passing it to C
functions. The string will be encoded as either ASCII or UTF-8.
"""
bytestring(s)

"""
midpoints(e)
Expand Down
2 changes: 1 addition & 1 deletion base/env.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ _hasenv(s::AbstractString) = _getenv(s) != C_NULL

function access_env(onError::Function, var::AbstractString)
val = _getenv(var)
val == C_NULL ? onError(var) : bytestring(val)
val == C_NULL ? onError(var) : String(val)
end

function _setenv(var::AbstractString, val::AbstractString, overwrite::Bool=true)
Expand Down
1 change: 0 additions & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,6 @@ export
bin,
bits,
bytes2hex,
bytestring,
charwidth,
chomp,
chop,
Expand Down
2 changes: 1 addition & 1 deletion base/fft/FFTW.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export export_wisdom, import_wisdom, import_system_wisdom, forget_wisdom,
const libfftw = Base.libfftw_name
const libfftwf = Base.libfftwf_name

const version = convert(VersionNumber, split(bytestring(cglobal((:fftw_version,Base.DFT.FFTW.libfftw), UInt8)), ['-', ' '])[2])
const version = convert(VersionNumber, split(String(cglobal((:fftw_version,Base.DFT.FFTW.libfftw), UInt8)), ['-', ' '])[2])

## Direction of FFT

Expand Down
10 changes: 5 additions & 5 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function pwd()
b = Array(UInt8,1024)
len = Ref{Csize_t}(length(b))
uv_error(:getcwd, ccall(:uv_cwd, Cint, (Ptr{UInt8}, Ptr{Csize_t}), b, len))
bytestring(b[1:len[]])
String(b[1:len[]])
end

function cd(dir::AbstractString)
Expand Down Expand Up @@ -187,7 +187,7 @@ function tempname()
d = get(ENV, "TMPDIR", C_NULL) # tempnam ignores TMPDIR on darwin
p = ccall(:tempnam, Cstring, (Cstring,Cstring), d, :julia)
systemerror(:tempnam, p == C_NULL)
s = bytestring(p)
s = String(p)
Libc.free(p)
return s
end
Expand All @@ -208,7 +208,7 @@ function mktempdir(parent=tempdir())
b = joinpath(parent, "tmpXXXXXX")
p = ccall(:mkdtemp, Cstring, (Cstring,), b)
systemerror(:mktempdir, p == C_NULL)
return bytestring(p)
return String(p)
end
end

Expand Down Expand Up @@ -293,7 +293,7 @@ function readdir(path::AbstractString)
entries = String[]
ent = Ref{uv_dirent_t}()
while Base.UV_EOF != ccall(:uv_fs_scandir_next, Cint, (Ptr{Void}, Ptr{uv_dirent_t}), uv_readdir_req, ent)
push!(entries, bytestring(ent[].name))
push!(entries, String(ent[].name))
end

# Clean up the request string
Expand Down Expand Up @@ -430,7 +430,7 @@ function readlink(path::AbstractString)
uv_error("readlink", ret)
assert(false)
end
tgt = bytestring(ccall(:jl_uv_fs_t_ptr, Ptr{Cchar}, (Ptr{Void}, ), req))
tgt = String(ccall(:jl_uv_fs_t_ptr, Ptr{Cchar}, (Ptr{Void}, ), req))
ccall(:uv_fs_req_cleanup, Void, (Ptr{Void}, ), req)
return tgt
finally
Expand Down
6 changes: 3 additions & 3 deletions base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ else
end
typealias CdoubleMax Union{Float16, Float32, Float64}

gmp_version() = VersionNumber(bytestring(unsafe_load(cglobal((:__gmp_version, :libgmp), Ptr{Cchar}))))
gmp_version() = VersionNumber(String(unsafe_load(cglobal((:__gmp_version, :libgmp), Ptr{Cchar}))))
gmp_bits_per_limb() = Int(unsafe_load(cglobal((:__gmp_bits_per_limb, :libgmp), Cint)))

const GMP_VERSION = gmp_version()
Expand Down Expand Up @@ -84,8 +84,8 @@ convert(::Type{BigInt}, x::BigInt) = x
function tryparse_internal(::Type{BigInt}, s::AbstractString, startpos::Int, endpos::Int, base::Int, raise::Bool)
_n = Nullable{BigInt}()

# don't make a copy in the common case where we are parsing a whole bytestring
bstr = startpos == start(s) && endpos == endof(s) ? bytestring(s) : bytestring(SubString(s,startpos,endpos))
# don't make a copy in the common case where we are parsing a whole String
bstr = startpos == start(s) && endpos == endof(s) ? String(s) : String(SubString(s,startpos,endpos))

sgn, base, i = Base.parseint_preamble(true,base,bstr,start(bstr),endof(bstr))
if i == 0
Expand Down
2 changes: 1 addition & 1 deletion base/hashing2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,4 @@ function hash(s::Union{String,SubString{String}}, h::UInt)
# note: use pointer(s) here (see #6058).
ccall(memhash, UInt, (Ptr{UInt8}, Csize_t, UInt32), pointer(s), sizeof(s), h % UInt32) + h
end
hash(s::AbstractString, h::UInt) = hash(bytestring(s), h)
hash(s::AbstractString, h::UInt) = hash(String(s), h)
2 changes: 1 addition & 1 deletion base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ end
function init_bind_addr()
opts = JLOptions()
if opts.bindto != C_NULL
bind_to = split(bytestring(opts.bindto), ":")
bind_to = split(String(opts.bindto), ":")
bind_addr = string(parse(IPAddr, bind_to[1]))
if length(bind_to) > 1
bind_port = parse(Int,bind_to[2])
Expand Down
2 changes: 1 addition & 1 deletion base/interactiveutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function versioninfo(io::IO=STDOUT, verbose::Bool=false)
if verbose
println(io, "Environment:")
for (k,v) in ENV
if !is(match(r"JULIA|PATH|FLAG|^TERM$|HOME", bytestring(k)), nothing)
if !is(match(r"JULIA|PATH|FLAG|^TERM$|HOME", String(k)), nothing)
println(io, " $(k) = $(v)")
end
end
Expand Down
Loading

0 comments on commit 24efdf7

Please sign in to comment.