Skip to content

Commit

Permalink
Merge pull request #11128 from JuliaLang/sk/charops
Browse files Browse the repository at this point in the history
Char: delete bitwise operator methods for Char type
  • Loading branch information
StefanKarpinski committed May 6, 2015
2 parents ba5e5a9 + 41fd9c7 commit 0459be9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
20 changes: 4 additions & 16 deletions base/char.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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, '\'')
Expand Down
5 changes: 5 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit 0459be9

Please sign in to comment.