diff --git a/base/LineEdit.jl b/base/LineEdit.jl index 6e7b23c211b6de..59c9daaca8a841 100644 --- a/base/LineEdit.jl +++ b/base/LineEdit.jl @@ -1325,11 +1325,11 @@ AnyDict( i = position(buf) if i != 0 c = buf.data[i] - if c == '\n' || c == '\t' || + if c == UInt8('\n') || c == UInt8('\t') || # hack to allow path completion in cmds # after a space, e.g., `cd `, while still # allowing multiple indent levels - (c == ' ' && i > 3 && buf.data[i-1] == ' ') + (c == UInt8(' ') && i > 3 && buf.data[i-1] == ' ') edit_insert(s, " "^4) return end diff --git a/base/REPL.jl b/base/REPL.jl index bf407d1da98522..9d96ae18f0c265 100644 --- a/base/REPL.jl +++ b/base/REPL.jl @@ -360,7 +360,7 @@ function hist_from_file(hp, file) while !isempty(line) push!(lines, chomp(line[2:end])) eof(file) && break - ch = Base.peek(file) + ch = Char(Base.peek(file)) ch == ' ' && error(munged_history_message, countlines) ch != '\t' && break line = hist_getline(file) diff --git a/base/char.jl b/base/char.jl index 319e4b35257b89..75105b174b6748 100644 --- a/base/char.jl +++ b/base/char.jl @@ -30,12 +30,7 @@ isempty(c::Char) = false in(x::Char, y::Char) = x == y ==(x::Char, y::Char) = UInt32(x) == UInt32(y) -==(x::Char, y::Integer) = UInt32(x) == y -==(x::Integer, y::Char) = x == UInt32(y) - -isless(x::Char, y::Char) = isless(UInt32(x), UInt32(y)) -isless(x::Char, y::Integer) = isless(UInt32(x), y) -isless(x::Integer, y::Char) = isless(x, UInt32(y)) +isless(x::Char, y::Char) = UInt32(x) < UInt32(y) -(x::Char, y::Char) = Int(x) - Int(y) -(x::Char, y::Integer) = Char(Int32(x) - Int32(y)) diff --git a/base/datafmt.jl b/base/datafmt.jl index e25dcf29bf6d73..062c07e2310b15 100644 --- a/base/datafmt.jl +++ b/base/datafmt.jl @@ -18,12 +18,13 @@ const offs_chunk_size = 5000 countlines(f::AbstractString, eol::Char='\n') = open(io->countlines(io,eol), f)::Int function countlines(io::IO, eol::Char='\n') isascii(eol) || throw(ArgumentError("only ASCII line terminators are supported")) + aeol = UInt8(eol) a = Array(UInt8, 8192) nl = 0 while !eof(io) nb = readbytes!(io, a) @simd for i=1:nb - @inbounds nl += a[i] == eol + @inbounds nl += a[i] == aeol end end nl diff --git a/base/deprecated.jl b/base/deprecated.jl index 1bee11aa391af6..5947fc523ea456 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1073,6 +1073,11 @@ end @deprecate bitunpack(B::BitArray) Array(B) @deprecate bitpack(A::AbstractArray) BitArray(A) +@deprecate ==(x::Char, y::Integer) UInt32(x) == y +@deprecate ==(x::Integer, y::Char) x == UInt32(y) +@deprecate isless(x::Char, y::Integer) isless(UInt32(x), y) +@deprecate isless(x::Integer, y::Char) isless(x, UInt32(y)) + # During the 0.5 development cycle, do not add any deprecations below this line # To be deprecated in 0.6 diff --git a/base/float.jl b/base/float.jl index 50da2e0cdaee1e..e199c6565f1711 100644 --- a/base/float.jl +++ b/base/float.jl @@ -337,7 +337,7 @@ hash(x::UInt64, h::UInt) = hx(x, Float64(x), h) hash(x::Int64, h::UInt) = hx(reinterpret(UInt64,abs(x)), Float64(x), h) hash(x::Float64, h::UInt) = isnan(x) ? (hx_NaN $ h) : hx(box(UInt64,fptoui(unbox(Float64,abs(x)))), x, h) -hash(x::Union{Bool,Char,Int8,UInt8,Int16,UInt16,Int32,UInt32}, h::UInt) = hash(Int64(x), h) +hash(x::Union{Bool,Int8,UInt8,Int16,UInt16,Int32,UInt32}, h::UInt) = hash(Int64(x), h) hash(x::Float32, h::UInt) = hash(Float64(x), h) ## precision, as defined by the effective number of bits in the mantissa ## diff --git a/base/markdown/Common/block.jl b/base/markdown/Common/block.jl index b5d715991e23c6..7a3813e6c45ed7 100644 --- a/base/markdown/Common/block.jl +++ b/base/markdown/Common/block.jl @@ -198,7 +198,7 @@ function list(stream::IO, block::MD) c = read(stream, Char) if c == '\n' eof(stream) && break - next = peek(stream) + next = Char(peek(stream)) # ok since we only compare with ASCII if next == '\n' break else diff --git a/base/markdown/Julia/interp.jl b/base/markdown/Julia/interp.jl index eecfcb09b9487c..4134c06362b78a 100644 --- a/base/markdown/Julia/interp.jl +++ b/base/markdown/Julia/interp.jl @@ -9,7 +9,7 @@ end function interpinner(stream::IO, greedy = false) startswith(stream, '$') || return - (eof(stream) || peek(stream) in whitespace) && return + (eof(stream) || peek(stream) in whitespace8) && return try return Base.parse(stream::IOBuffer, greedy = greedy) catch e diff --git a/base/markdown/parse/parse.jl b/base/markdown/parse/parse.jl index 79b5d22efea46a..5df7ff71884b5e 100644 --- a/base/markdown/parse/parse.jl +++ b/base/markdown/parse/parse.jl @@ -51,7 +51,9 @@ function parseinline(stream::IO, md::MD, config::Config) content = [] buffer = IOBuffer() while !eof(stream) - char = peek(stream) + # FIXME: this is broken if we're looking for non-ASCII + # characters because peek only returns a single byte. + char = Char(peek(stream)) if haskey(config.inner, char) && (inner = parseinline(stream, md, config.inner[char])) !== nothing c = takebuf_string(buffer) diff --git a/base/markdown/parse/util.jl b/base/markdown/parse/util.jl index 3eca2c9f9f7948..3f847113b57aa5 100644 --- a/base/markdown/parse/util.jl +++ b/base/markdown/parse/util.jl @@ -11,12 +11,13 @@ macro dotimes(n, body) end const whitespace = " \t\r" +const whitespace8 = map(UInt8,collect(whitespace)) """ Skip any leading whitespace. Returns io. """ function skipwhitespace(io::IO; newlines = true) - while !eof(io) && (peek(io) in whitespace || (newlines && peek(io) == '\n')) + while !eof(io) && (peek(io) in whitespace8 || (newlines && peek(io) == UInt8('\n'))) read(io, Char) end return io @@ -82,7 +83,7 @@ function startswith(stream::IO, s::AbstractString; eat = true, padding = false, end function startswith(stream::IO, c::Char; eat = true) - if !eof(stream) && peek(stream) == c + if !eof(stream) && peek(stream) == UInt8(c) eat && read(stream, Char) return true else @@ -181,7 +182,7 @@ function parse_inline_wrapper(stream::IO, delimiter::AbstractString; rep = false startswith(stream, delimiter^n) || return nothing while startswith(stream, delimiter); n += 1; end !rep && n > nmin && return nothing - !eof(stream) && peek(stream) in whitespace && return nothing + !eof(stream) && peek(stream) in whitespace8 && return nothing buffer = IOBuffer() while !eof(stream) diff --git a/base/precompile.jl b/base/precompile.jl index 6fa7a99d8f1f98..471cfca98a2f3d 100644 --- a/base/precompile.jl +++ b/base/precompile.jl @@ -495,6 +495,6 @@ precompile(Base.set_valid_processes, (Array{Int, 1}, )) # Speed up repl help -sprint(Markdown.term, @doc mean) +# sprint(Markdown.term, @doc mean) sprint(Docs.repl_search, "mean") sprint(Docs.repl_corrections, "meen") diff --git a/base/printf.jl b/base/printf.jl index 0546edf073cb03..e51fedd52f17c5 100644 --- a/base/printf.jl +++ b/base/printf.jl @@ -458,7 +458,7 @@ function gen_e(flags::ASCIIString, width::Int, precision::Int, c::Char, inside_g # print sign '+' in flags ? push!(blk.args, :(write(out, neg?'-':'+'))) : ' ' in flags ? push!(blk.args, :(write(out, neg?'-':' '))) : - push!(blk.args, :(neg && write(out, '-'))) + push!(blk.args, :(neg && write(out, '-'))) # print zero padding if padding !== nothing && !('-' in flags) && '0' in flags push!(blk.args, pad(width, padding, '0')) @@ -468,7 +468,7 @@ function gen_e(flags::ASCIIString, width::Int, precision::Int, c::Char, inside_g if precision > 0 if inside_g && !('#' in flags) push!(blk.args, :(endidx = $ndigits; - while endidx > 1 && DIGITS[endidx] == '0' + while endidx > 1 && DIGITS[endidx] == 0x30 endidx -= 1 end; if endidx > 1 diff --git a/test/char.jl b/test/char.jl index d2bf335b8c0470..f22aa536315bc2 100644 --- a/test/char.jl +++ b/test/char.jl @@ -2,7 +2,7 @@ #tests for /base/char.jl -@test typemin(Char) == 0 +@test typemin(Char) == Char(0) @test ndims(Char) == 0 @test getindex('a', 1) == 'a' @test_throws BoundsError getindex('a',2) @@ -133,44 +133,44 @@ let #isless(x::Char, y::Integer) = isless(UInt32(x), y) for x in upperchars - @test isless(x, 91) == true + @test isless(x, Char(91)) == true end for x in lowerchars - @test isless(x, 123) == true + @test isless(x, Char(123)) == true end for x in numberchars - @test isless(x, 66) == true + @test isless(x, Char(66)) == true end for x in plane1_playingcards - @test isless(x, 127151) == true + @test isless(x, Char(127151)) == true end for x in plane2_cjkpart1 - @test isless(x, 131088) == true + @test isless(x, Char(131088)) == true end #isless(x::Integer, y::Char) = isless(x, UInt32(y)) for x in upperchars - @test isless(64, x) == true + @test isless(Char(64), x) == true end for x in lowerchars - @test isless(96, x) == true + @test isless(Char(96), x) == true end for x in numberchars - @test isless(47, x) == true + @test isless(Char(47), x) == true end for x in plane1_playingcards - @test isless(127135, x) == true + @test isless(Char(127135), x) == true end for x in plane2_cjkpart1 - @test isless(131071, x) == true + @test isless(Char(131071), x) == true end end #end of let block diff --git a/test/random.jl b/test/random.jl index bbff7ccea5f878..a9c25cb0a75321 100644 --- a/test/random.jl +++ b/test/random.jl @@ -42,7 +42,7 @@ let mt = MersenneTwister() srand(mt) @test rand(mt, 0:3:1000) in 0:3:1000 @test issubset(rand!(mt, Array(Int, 100), 0:3:1000), 0:3:1000) - coll = Any[2, UInt128(128), big(619), "string", 'c'] + coll = Any[2, UInt128(128), big(619), "string"] @test rand(mt, coll) in coll @test issubset(rand(mt, coll, 2, 3), coll) @@ -315,7 +315,7 @@ for rng in ([], [MersenneTwister()], [RandomDevice()]) rand!(rng..., BitArray(5)) ::BitArray{1} rand!(rng..., BitArray(2, 3)) ::BitArray{2} - for T in [Base.BitInteger_types..., Bool, Char, Float16, Float32, Float64] + for T in [Base.BitInteger_types..., Bool, Float16, Float32, Float64] a0 = rand(rng..., T) ::T a1 = rand(rng..., T, 5) ::Vector{T} a2 = rand(rng..., T, 2, 3) ::Array{T, 2} diff --git a/test/read.jl b/test/read.jl index 42fc1d76c4b5e7..3406ec424451e5 100644 --- a/test/read.jl +++ b/test/read.jl @@ -383,9 +383,9 @@ f = joinpath(dir, "test.txt") open(io->write(io, "123"), f, "w") f1 = open(f) f2 = Base.Filesystem.open(f, Base.Filesystem.JL_O_RDONLY) -@test read(f1, UInt8) == read(f2, UInt8) == '1' -@test read(f1, UInt8) == read(f2, UInt8) == '2' -@test read(f1, UInt8) == read(f2, UInt8) == '3' +@test read(f1, UInt8) == read(f2, UInt8) == UInt8('1') +@test read(f1, UInt8) == read(f2, UInt8) == UInt8('2') +@test read(f1, UInt8) == read(f2, UInt8) == UInt8('3') @test_throws EOFError read(f1, UInt8) @test_throws EOFError read(f2, UInt8) close(f1) diff --git a/test/spawn.jl b/test/spawn.jl index 0818bdcbfaa39b..d446ae2b17ea1a 100644 --- a/test/spawn.jl +++ b/test/spawn.jl @@ -276,7 +276,7 @@ let out = Pipe(), echo = `$exename -f -e 'print(STDOUT, " 1\t", readstring(STDIN wait(ready) # wait for writer task to be ready before using `out` @test nb_available(out) == 0 @test endswith(readuntil(out, '1'), '1') - @test read(out, UInt8) == '\t' + @test Char(read(out, UInt8)) == '\t' c = UInt8[0] @test c == read!(out, c) Base.wait_readnb(out, 1) @@ -288,7 +288,7 @@ let out = Pipe(), echo = `$exename -f -e 'print(STDOUT, " 1\t", readstring(STDIN @test !iswritable(out) @test !isopen(out) @test nb_available(out) == 0 - @test c == ['w'] + @test c == UInt8['w'] @test lstrip(ln2) == "1\thello\n" @test ln1 == "orld\n" @test isempty(read(out)) diff --git a/test/strings/basic.jl b/test/strings/basic.jl index b0258852d45fe1..7bb8698634552a 100644 --- a/test/strings/basic.jl +++ b/test/strings/basic.jl @@ -487,7 +487,7 @@ str = "abcdef\uff\uffff\u10ffffABCDEF" @test typeof(lowercase(utf16(str))) == UTF16String @test typeof(lowercase(utf32(str))) == UTF32String -foomap(ch) = (ch > 65) +foomap(ch) = (ch > Char(65)) foobar(ch) = Char(0xd800) foobaz(ch) = reinterpret(Char, typemax(UInt32)) @test_throws UnicodeError map(foomap, utf16(str)) diff --git a/test/unicode/utf32.jl b/test/unicode/utf32.jl index 53e7de500ed3e9..20ff183e023a94 100644 --- a/test/unicode/utf32.jl +++ b/test/unicode/utf32.jl @@ -4,7 +4,7 @@ u8 = "\U10ffff\U1d565\U1d7f6\U00066\U2008a" u32 = utf32(u8) @test sizeof(u32) == 20 -@test length(u32.data) == 6 && u32.data[end] == Char(0) +@test length(u32.data) == 6 && u32.data[end] == 0 @test length(u32) == 5 @test utf8(u32) == u8 @test collect(u8) == collect(u32) @@ -181,13 +181,13 @@ for (fun, S, T) in ((utf16, UInt16, UTF16String), (utf32, UInt32, UTF32String)) str = "abcd\0\uff\u7ff\u7fff\U7ffff" tst = SubString(convert(T,str),4) cmp = Char['d','\0','\uff','\u7ff','\u7fff','\U7ffff'] - cmpch = Char['d','\0','\uff','\u7ff','\u7fff','\U7ffff','\0'] + cmp32 = UInt32['d','\0','\uff','\u7ff','\u7fff','\U7ffff','\0'] cmp16 = UInt16[0x0064,0x0000,0x00ff,0x07ff,0x7fff,0xd9bf,0xdfff,0x0000] x = fun(tst) - cmpx = (S == UInt16 ? cmp16 : cmpch) + cmpx = (S == UInt16 ? cmp16 : cmp32) @test typeof(tst) == SubString{T} @test convert(T, tst) == str[4:end] - S != UInt32 && @test convert(Vector{Char}, x) == cmp + @test convert(Vector{Char}, x) == cmp # Vector{T} / Array{T} @test convert(Vector{S}, x) == cmpx @test convert(Array{S}, x) == cmpx @@ -223,9 +223,9 @@ let str = ascii("this ") @test typeof(p8) == Ptr{UInt8} @test unsafe_load(p8,1) == 0x74 @test typeof(p16) == Ptr{UInt16} - @test unsafe_load(p16,1) == 0x0074 + @test unsafe_load(p16,1) == 0x74 @test typeof(p32) == Ptr{UInt32} - @test unsafe_load(p32,1) == 't' + @test unsafe_load(p32,1) == 0x74 pa = pointer(str, 2) p8 = pointer(u8, 2) p16 = pointer(u16, 2) @@ -235,9 +235,9 @@ let str = ascii("this ") @test typeof(p8) == Ptr{UInt8} @test unsafe_load(p8,1) == 0x68 @test typeof(p16) == Ptr{UInt16} - @test unsafe_load(p16,1) == 0x0068 + @test unsafe_load(p16,1) == 0x68 @test typeof(p32) == Ptr{UInt32} - @test unsafe_load(p32,1) == 'h' + @test unsafe_load(p32,1) == 0x68 sa = SubString{ASCIIString}(str, 3, 5) s8 = SubString{UTF8String}(u8, 3, 5) s16 = SubString{UTF16String}(u16, 3, 5) @@ -251,9 +251,9 @@ let str = ascii("this ") @test typeof(p8) == Ptr{UInt8} @test unsafe_load(p8,1) == 0x69 @test typeof(p16) == Ptr{UInt16} - @test unsafe_load(p16,1) == 0x0069 + @test unsafe_load(p16,1) == 0x69 @test typeof(p32) == Ptr{UInt32} - @test unsafe_load(p32,1) == 'i' + @test unsafe_load(p32,1) == 0x69 pa = pointer(sa, 2) p8 = pointer(s8, 2) p16 = pointer(s16, 2) @@ -263,9 +263,9 @@ let str = ascii("this ") @test typeof(p8) == Ptr{UInt8} @test unsafe_load(p8,1) == 0x73 @test typeof(p16) == Ptr{UInt16} - @test unsafe_load(p16,1) == 0x0073 + @test unsafe_load(p16,1) == 0x73 @test typeof(p32) == Ptr{UInt32} - @test unsafe_load(p32,1) == 's' + @test unsafe_load(p32,1) == 0x73 end @test isvalid(Char['f','o','o','b','a','r'])