Skip to content

Commit

Permalink
replace ASCIIString & ByteString with String
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Apr 26, 2016
1 parent 893f7e3 commit 74bb1af
Show file tree
Hide file tree
Showing 145 changed files with 766 additions and 1,016 deletions.
10 changes: 5 additions & 5 deletions base/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type MIState
current_mode
aborted::Bool
mode_state
kill_buffer::ByteString
kill_buffer::String
previous_key::Array{Char,1}
key_repeats::Int
end
Expand Down Expand Up @@ -624,7 +624,7 @@ function write_prompt(terminal, p::Prompt)
write(terminal, Base.text_colors[:normal])
write(terminal, suffix)
end
write_prompt(terminal, s::ByteString) = write(terminal, s)
write_prompt(terminal, s::String) = write(terminal, s)

### Keymap Support

Expand Down Expand Up @@ -703,11 +703,11 @@ end
# This is different from the default eager redirect, which only looks at the current and lower
# layers of the stack.
immutable KeyAlias
seq::ASCIIString
seq::String
KeyAlias(seq) = new(normalize_key(seq))
end

match_input(k::Function, s, term, cs, keymap) = (update_key_repeats(s, cs); return keymap_fcn(k, ByteString(cs)))
match_input(k::Function, s, term, cs, keymap) = (update_key_repeats(s, cs); return keymap_fcn(k, String(cs)))
match_input(k::Void, s, term, cs, keymap) = (s,p) -> return :ok
match_input(k::KeyAlias, s, term, cs, keymap) = match_input(keymap, s, IOBuffer(k.seq), Char[], keymap)
function match_input(k::Dict, s, term=terminal(s), cs=Char[], keymap = k)
Expand Down Expand Up @@ -1013,7 +1013,7 @@ init_state(terminal, p::HistoryPrompt) = SearchState(terminal, p, true, IOBuffer
type PrefixSearchState <: ModeState
terminal
histprompt
prefix::ByteString
prefix::String
response_buffer::IOBuffer
ias::InputAreaState
indent::Int
Expand Down
2 changes: 1 addition & 1 deletion base/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ function hist_from_file(hp, file)
error(munged_history_message, countlines)
line[1] != '\t' &&
error(invalid_history_message, repr(line[1]), " at line ", countlines)
lines = UTF8String[]
lines = String[]
while !isempty(line)
push!(lines, chomp(line[2:end]))
eof(file) && break
Expand Down
40 changes: 20 additions & 20 deletions base/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ end
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]
syms = String[string(s) for s in ssyms]
filter!(x->completes_global(x, name), syms)
end

Expand Down Expand Up @@ -47,12 +47,12 @@ function complete_symbol(sym, ffunc)
lookup_module = false
t, found = get_type(ex, context_module)
end
found || return UTF8String[]
found || return String[]
# Ensure REPLCompletion do not crash when asked to complete a tuple, #15329
!lookup_module && t <: Tuple && return UTF8String[]
!lookup_module && t <: Tuple && return String[]
end

suggestions = UTF8String[]
suggestions = String[]
if lookup_module
# We will exclude the results that the user does not want, as well
# as excluding Main.Main.Main, etc., because that's most likely not what
Expand Down Expand Up @@ -82,7 +82,7 @@ function complete_symbol(sym, ffunc)
suggestions
end

function complete_keyword(s::ByteString)
function complete_keyword(s::String)
const sorted_keywords = [
"abstract", "baremodule", "begin", "bitstype", "break", "catch", "ccall",
"const", "continue", "do", "else", "elseif", "end", "export", "false",
Expand Down Expand Up @@ -117,13 +117,13 @@ function complete_path(path::AbstractString, pos; use_envpath=false)
elseif isdir(dir)
files = readdir(dir)
else
return UTF8String[], 0:-1, false
return String[], 0:-1, false
end
catch
return UTF8String[], 0:-1, false
return String[], 0:-1, false
end

matches = Set{UTF8String}()
matches = Set{String}()
for file in files
if startswith(file, prefix)
id = try isdir(joinpath(dir, file)) catch; false end
Expand Down Expand Up @@ -174,7 +174,7 @@ function complete_path(path::AbstractString, pos; use_envpath=false)
end
end

matchList = UTF8String[replace(s, r"\s", "\\ ") for s in matches]
matchList = String[replace(s, r"\s", "\\ ") for s in matches]
startpos = pos - endof(prefix) + 1 - length(matchall(r" ", prefix))
# The pos - endof(prefix) + 1 is correct due to `endof(prefix)-endof(prefix)==0`,
# hence we need to add one to get the first index. This is also correct when considering
Expand Down Expand Up @@ -289,7 +289,7 @@ function get_type_call(expr::Expr)
(tree, return_type) = Core.Inference.typeinf(linfo, m[1], m[2])
return return_type, true
end
# Returns the return type. example: get_type(:(Base.strip("",' ')),Main) returns (ASCIIString,true)
# Returns the return type. example: get_type(:(Base.strip("",' ')),Main) returns (String,true)
function get_type(sym::Expr, fn)
sym=expand(sym)
val, found = get_value(sym, fn)
Expand All @@ -313,12 +313,12 @@ end
function complete_methods(ex_org::Expr)
args_ex = DataType[]
func, found = get_value(ex_org.args[1], Main)
!found && return UTF8String[]
!found && return String[]
for ex in ex_org.args[2:end]
val, found = get_type(ex, Main)
push!(args_ex, val)
end
out = UTF8String[]
out = String[]
t_in = Tuple{Core.Typeof(func), args_ex...} # Input types
na = length(args_ex)+1
Base.visit(methods(func)) do method
Expand All @@ -341,7 +341,7 @@ const bslash_separators = [whitespace_chars..., "\"'`"...]

# Aux function to detect whether we're right after a
# using or import keyword
function afterusing(string::ByteString, startpos::Int)
function afterusing(string::String, startpos::Int)
(isempty(string) || startpos == 0) && return false
str = string[1:prevind(string,startpos)]
isempty(str) && return false
Expand Down Expand Up @@ -376,7 +376,7 @@ function bslash_completions(string, pos)
return (true, (sort!(collect(latex_names)), slashpos:pos, true))
end
end
return (false, (UTF8String[], 0:-1, false))
return (false, (String[], 0:-1, false))
end

function completions(string, pos)
Expand Down Expand Up @@ -404,7 +404,7 @@ function completions(string, pos)
ok && return ret

# Make sure that only bslash_completions is working on strings
inc_tag==:string && return UTF8String[], 0:-1, false
inc_tag==:string && return String[], 0:-1, false

if inc_tag == :other && should_method_complete(partial)
frange, method_name_end = find_start_brace(partial)
Expand All @@ -415,14 +415,14 @@ function completions(string, pos)
return complete_methods(ex), start(frange):method_name_end, false
end
elseif inc_tag == :comment
return UTF8String[], 0:-1, false
return String[], 0:-1, false
end

dotpos = rsearch(string, '.', pos)
startpos = nextind(string, rsearch(string, non_identifier_chars, pos))

ffunc = (mod,x)->true
suggestions = UTF8String[]
suggestions = String[]
comp_keywords = true
if afterusing(string, startpos)
# We're right after using or import. Let's look only for packages
Expand Down Expand Up @@ -500,10 +500,10 @@ function shell_completions(string, pos)
try
args, last_parse = Base.shell_parse(scs, true)
catch
return UTF8String[], 0:-1, false
return String[], 0:-1, false
end
# Now look at the last thing we parsed
isempty(args.args[end].args) && return UTF8String[], 0:-1, false
isempty(args.args[end].args) && return String[], 0:-1, false
arg = args.args[end].args[end]
if all(s -> isa(s, AbstractString), args.args[end].args)
# Treat this as a path
Expand All @@ -525,7 +525,7 @@ function shell_completions(string, pos)
range += first(r) - 1
return ret, range, true
end
return UTF8String[], 0:-1, false
return String[], 0:-1, false
end

end # module
2 changes: 1 addition & 1 deletion base/Terminals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type TerminalBuffer <: UnixTerminal
end

type TTYTerminal <: UnixTerminal
term_type::ASCIIString
term_type::String
in_stream::Base.TTY
out_stream::Base.TTY
err_stream::Base.TTY
Expand Down
144 changes: 5 additions & 139 deletions base/ascii.jl
Original file line number Diff line number Diff line change
@@ -1,141 +1,7 @@
# This file is a part of Julia. License is MIT: http:https://julialang.org/license

## from base/boot.jl:
#
# immutable ASCIIString <: DirectIndexString
# data::Array{UInt8,1}
# end
#

## required core functionality ##

endof(s::ASCIIString) = length(s.data)
getindex(s::ASCIIString, i::Int) = (x=s.data[i]; ifelse(x < 0x80, Char(x), '\ufffd'))

## overload methods for efficiency ##

sizeof(s::ASCIIString) = sizeof(s.data)

getindex(s::ASCIIString, r::Vector) = ASCIIString(getindex(s.data,r))
getindex(s::ASCIIString, r::UnitRange{Int}) = ASCIIString(getindex(s.data,r))
getindex(s::ASCIIString, indx::AbstractVector{Int}) = ASCIIString(s.data[indx])
function search(s::ASCIIString, c::Char, i::Integer)
i == sizeof(s) + 1 && return 0
(i < 1 || i > sizeof(s)) && throw(BoundsError(s, i))
return c < Char(0x80) ? search(s.data,c%UInt8,i) : 0
end
rsearch(s::ASCIIString, c::Char, i::Integer) = c < Char(0x80) ? rsearch(s.data,c%UInt8,i) : 0

function string(c::ASCIIString...)
if length(c) == 1
return c[1]
end
n = 0
for s in c
n += length(s.data)
end
v = Array(UInt8,n)
o = 1
for s in c
ls = length(s.data)
unsafe_copy!(v, o, s.data, 1, ls)
o += ls
end
ASCIIString(v)
end

function ucfirst(s::ASCIIString)
if !isempty(s) && 'a' <= s[1] <= 'z'
t = ASCIIString(copy(s.data))
t.data[1] -= 32
return t
end
return s
end
function lcfirst(s::ASCIIString)
if !isempty(s) && 'A' <= s[1] <= 'Z'
t = ASCIIString(copy(s.data))
t.data[1] += 32
return t
end
return s
end

function uppercase(s::ASCIIString)
d = s.data
for i = 1:length(d)
if 'a' <= Char(d[i]) <= 'z'
td = copy(d)
for j = i:length(td)
if 'a' <= Char(td[j]) <= 'z'
td[j] -= 32
end
end
return ASCIIString(td)
end
end
return s
end
function lowercase(s::ASCIIString)
d = s.data
for i = 1:length(d)
if 'A' <= Char(d[i]) <= 'Z'
td = copy(d)
for j = i:length(td)
if 'A' <= Char(td[j]) <= 'Z'
td[j] += 32
end
end
return ASCIIString(td)
end
end
return s
end

reverse(s::ASCIIString) = ASCIIString(reverse(s.data))

## outputing ASCII strings ##

write(io::IO, s::ASCIIString) = write(io, s.data)

## transcoding to ASCII ##

ascii(x) = convert(ASCIIString, x)
convert(::Type{ASCIIString}, s::ASCIIString) = s
convert(::Type{ASCIIString}, s::UTF8String) = ascii(s.data)
convert(::Type{ASCIIString}, a::Vector{UInt8}) = begin
isvalid(ASCIIString,a) || throw(ArgumentError("invalid ASCII sequence"))
return ASCIIString(a)
end

ascii(p::Ptr{UInt8}) =
ascii(p, p == C_NULL ? Csize_t(0) : ccall(:strlen, Csize_t, (Ptr{UInt8},), p))
function ascii(p::Ptr{UInt8}, len::Integer)
p == C_NULL && throw(ArgumentError("cannot convert NULL to string"))
ary = ccall(:jl_pchar_to_array, Vector{UInt8},
(Ptr{UInt8}, Csize_t), p, len)
isvalid(ASCIIString, ary) || throw(ArgumentError("invalid ASCII sequence"))
ASCIIString(ary)
end

function convert(::Type{ASCIIString}, a::Array{UInt8,1}, invalids_as::ASCIIString)
l = length(a)
idx = 1
iscopy = false
while idx <= l
(a[idx] < 0x80) && (idx +=1; continue)
!iscopy && (a = copy(a); iscopy = true)
endn = idx
while endn <= l
(a[endn] < 0x80) && break
endn += 1
end
(endn > idx) && (endn -= 1)
splice!(a, idx:endn, invalids_as.data)
l = length(a)
end
convert(ASCIIString, a)
end
convert(::Type{ASCIIString}, a::Array{UInt8,1}, invalids_as::AbstractString) =
convert(ASCIIString, a, ascii(invalids_as))
convert(::Type{ASCIIString}, s::AbstractString) = ascii(bytestring(s))
ascii(x) = ascii(convert(String, x))
ascii(s::String) = byte_string_classify(s.data) == 1 ? s :
throw(ArgumentError("invalid ASCII sequence"))
ascii(p::Ptr{UInt8}) = String(bytestring(p))
ascii(p::Ptr{UInt8}, len::Integer) = ascii(pointer_to_array(p, len))
5 changes: 3 additions & 2 deletions base/atomics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function atomic_min! end
unsafe_convert{T}(::Type{Ptr{T}}, x::Atomic{T}) = convert(Ptr{T}, pointer_from_objref(x))
setindex!{T}(x::Atomic{T}, v) = setindex!(x, convert(T, v))

const llvmtypes = Dict{Type, ASCIIString}(
const llvmtypes = Dict(
Bool => "i1",
Int8 => "i8", UInt8 => "i8",
Int16 => "i16", UInt16 => "i16",
Expand All @@ -192,7 +192,8 @@ const llvmtypes = Dict{Type, ASCIIString}(
Int128 => "i128", UInt128 => "i128",
Float16 => "i16", # half
Float32 => "float",
Float64 => "double")
Float64 => "double",
)
inttype{T<:Integer}(::Type{T}) = T
inttype(::Type{Float16}) = Int16
inttype(::Type{Float32}) = Int32
Expand Down
2 changes: 1 addition & 1 deletion base/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ 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::ByteString) = str
bytestring(str::String) = str

# used by { } syntax
function cell_1d(xs::ANY...)
Expand Down
Loading

0 comments on commit 74bb1af

Please sign in to comment.