From a29058e61230247d7217be796b3369cdbeb92c12 Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Mon, 4 May 2015 18:01:15 -0400 Subject: [PATCH 1/2] Char: delete bitwise operator methods for Char type --- base/char.jl | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/base/char.jl b/base/char.jl index 0d976f1663462..24076d6373578 100644 --- a/base/char.jl +++ b/base/char.jl @@ -7,7 +7,6 @@ convert(::Type{Char}, x::Float64) = Char(convert(UInt32, x)) typemax(::Type{Char}) = Char(typemax(UInt32)) typemin(::Type{Char}) = Char(typemin(UInt32)) -## character operations & comparisons ## size(c::Char) = () size(c::Char,d) = convert(Int, d) < 1 ? throw(BoundsError()) : 1 ndims(c::Char) = 0 @@ -28,7 +27,6 @@ done(c::Char, state) = state 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) @@ -37,25 +35,15 @@ 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)) -# numeric operations - -# ordinal operations -+(x::Char , y::Integer) = reinterpret(Char, Int32(x) + Int32(y)) +-(x::Char, y::Char) = Int(x) - Int(y) +-(x::Char, y::Integer) = reinterpret(Char, Int32(x) - Int32(y)) ++(x::Char, y::Integer) = reinterpret(Char, Int32(x) + Int32(y)) +(x::Integer, y::Char) = y + x --(x::Char , y::Char) = Int(x) - Int(y) --(x::Char , y::Integer) = reinterpret(Char, Int32(x) - Int32(y)) - -# bitwise operations -(~)(x::Char) = Char(~UInt32(x)) -(&)(x::Char, y::Char) = Char(UInt32(x) & UInt32(y)) -(|)(x::Char, y::Char) = Char(UInt32(x) | UInt32(y)) -($)(x::Char, y::Char) = Char(UInt32(x) $ UInt32(y)) bswap(x::Char) = Char(bswap(UInt32(x))) -## printing & showing characters ## print(io::IO, c::Char) = (write(io, c); nothing) -show(io::IO, c::Char) = begin +function show(io::IO, c::Char) print(io, '\'') print_escaped(io, utf32(c), "'") print(io, '\'') From 41fd9c76b12d6da6c8b0c1e66e68b6f42dc3a16b Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Tue, 5 May 2015 14:43:29 -0400 Subject: [PATCH 2/2] Char: add deprecations for bitwise ops on Chars --- base/deprecated.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/base/deprecated.jl b/base/deprecated.jl index 0895070d30544..e49bb6bada70b 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -435,3 +435,8 @@ export float32_isvalid, float64_isvalid @deprecate BigFloat(s::AbstractString) parse(BigFloat,s) @deprecate BigInt(s::AbstractString) parse(BigInt,s) + +@deprecate (~)(x::Char) Char(~UInt32(x)) +@deprecate (&)(x::Char, y::Char) Char(UInt32(x) & UInt32(y)) +@deprecate (|)(x::Char, y::Char) Char(UInt32(x) | UInt32(y)) +@deprecate ($)(x::Char, y::Char) Char(UInt32(x) $ UInt32(y))