From b6ceadb96c4fd509456dd43446ef452226337113 Mon Sep 17 00:00:00 2001 From: ScottPJones Date: Tue, 1 Sep 2015 15:04:40 -0400 Subject: [PATCH] Deprecate getindex/checkbounds methods that depend on non Integer Real indices Use deprecate macro instead of depwarn --- base/char.jl | 1 - base/deprecated.jl | 4 ++++ base/strings/basic.jl | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/base/char.jl b/base/char.jl index 72b8ac160b8c9..7999f4074b090 100644 --- a/base/char.jl +++ b/base/char.jl @@ -19,7 +19,6 @@ endof(c::Char) = 1 getindex(c::Char) = c getindex(c::Char, i::Integer) = i == 1 ? c : throw(BoundsError()) getindex(c::Char, I::Integer...) = all(EqX(1), I) ? c : throw(BoundsError()) -getindex(c::Char, I::Real...) = getindex(c, to_indexes(I...)...) first(c::Char) = c last(c::Char) = c eltype(::Type{Char}) = Char diff --git a/base/deprecated.jl b/base/deprecated.jl index 1fd51dcabb6df..8218743f18366 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -439,6 +439,10 @@ end to_indexes(I...) end +@deprecate getindex(c::Char, I::Real...) getindex(c, map(Int, I)...) +@deprecate getindex(s::AbstractString, x::Real) getindex(s, Int(x)) +@deprecate checkbounds(s::AbstractString, i::Real) checkbounds(s, Int(i)) + @noinline function float_isvalid{T<:Union{Float32,Float64}}(s::AbstractString, out::Array{T,1}) tf = tryparse(T, s) isnull(tf) || (out[1] = get(tf)) diff --git a/base/strings/basic.jl b/base/strings/basic.jl index 615c0b6f7e69e..1264d3fd257a4 100644 --- a/base/strings/basic.jl +++ b/base/strings/basic.jl @@ -36,7 +36,6 @@ start(s::AbstractString) = 1 done(s::AbstractString,i) = (i > endof(s)) getindex(s::AbstractString, i::Int) = next(s,i)[1] getindex(s::AbstractString, i::Integer) = s[Int(i)] -getindex(s::AbstractString, x::Real) = s[to_index(x)] getindex{T<:Integer}(s::AbstractString, r::UnitRange{T}) = s[Int(first(r)):Int(last(r))] # TODO: handle other ranges with stride ±1 specially? getindex(s::AbstractString, v::AbstractVector) = @@ -150,9 +149,10 @@ function nextind(s::AbstractString, i::Integer) end checkbounds(s::AbstractString, i::Integer) = start(s) <= i <= endof(s) || throw(BoundsError(s, i)) -checkbounds(s::AbstractString, i::Real) = checkbounds(s, to_index(i)) checkbounds{T<:Integer}(s::AbstractString, r::Range{T}) = isempty(r) || (minimum(r) >= start(s) && maximum(r) <= endof(s)) || throw(BoundsError(s, r)) +# The following will end up using a deprecated checkbounds, when T is not Integer checkbounds{T<:Real}(s::AbstractString, I::AbstractArray{T}) = all(i -> checkbounds(s, i), I) +checkbounds{T<:Integer}(s::AbstractString, I::AbstractArray{T}) = all(i -> checkbounds(s, i), I) ind2chr(s::DirectIndexString, i::Integer) = begin checkbounds(s,i); i end chr2ind(s::DirectIndexString, i::Integer) = begin checkbounds(s,i); i end