Skip to content

Commit

Permalink
Remove DirectIndexString from Base (#24262)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkamins authored and nalimilan committed Oct 22, 2017
1 parent 34aab02 commit 175f7a1
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 41 deletions.
4 changes: 1 addition & 3 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export
Signed, Int, Int8, Int16, Int32, Int64, Int128,
Unsigned, UInt, UInt8, UInt16, UInt32, UInt64, UInt128,
# string types
Char, DirectIndexString, AbstractString, String, IO,
Char, AbstractString, String, IO,
# errors
ErrorException, BoundsError, DivideError, DomainError, Exception,
InterruptException, InexactError, OutOfMemoryError, ReadOnlyMemoryError,
Expand Down Expand Up @@ -275,8 +275,6 @@ struct InitError <: WrappedException
error
end

abstract type DirectIndexString <: AbstractString end

String(s::String) = s # no constructor yet

# This should always be inlined
Expand Down
22 changes: 0 additions & 22 deletions base/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

endof(s::AbstractString) = error("you must implement endof(", typeof(s), ")")
next(s::AbstractString, i::Int) = error("you must implement next(", typeof(s), ",Int)")
next(s::DirectIndexString, i::Int) = (s[i],i+1)
next(s::AbstractString, i::Integer) = next(s,Int(i))

string() = ""
Expand Down Expand Up @@ -70,8 +69,6 @@ julia> 'j' * "ulia"

one(::Union{T,Type{T}}) where {T<:AbstractString} = convert(T, "")

length(s::DirectIndexString) = endof(s)

"""
length(s::AbstractString)
Expand Down Expand Up @@ -198,8 +195,6 @@ isless(a::Symbol, b::Symbol) = cmp(a,b) < 0

## Generic validation functions ##

isvalid(s::DirectIndexString, i::Integer) = (start(s) <= i <= endof(s))

"""
isvalid(str::AbstractString, i::Integer)
Expand Down Expand Up @@ -237,20 +232,6 @@ end

## Generic indexing functions ##

prevind(s::DirectIndexString, i::Integer) = Int(i)-1
nextind(s::DirectIndexString, i::Integer) = Int(i)+1

function prevind(s::DirectIndexString, i::Integer, nchar::Integer)
nchar > 0 || throw(ArgumentError("nchar must be greater than 0"))
Int(i)-nchar
end

function nextind(s::DirectIndexString, i::Integer, nchar::Integer)
nchar > 0 || throw(ArgumentError("nchar must be greater than 0"))
Int(i)+nchar
end


"""
prevind(str::AbstractString, i::Integer, nchar::Integer=1)
Expand Down Expand Up @@ -371,9 +352,6 @@ checkbounds(s::AbstractString, r::AbstractRange{<:Integer}) = isempty(r) || (min
checkbounds(s::AbstractString, I::AbstractArray{<:Real}) = all(i -> checkbounds(s, i), I)
checkbounds(s::AbstractString, I::AbstractArray{<:Integer}) = 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


"""
ind2chr(s::AbstractString, i::Integer)
Expand Down
8 changes: 0 additions & 8 deletions base/strings/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ sizeof(s::SubString{String}) = s.endof == 0 ? 0 : nextind(s, s.endof) - 1
# default implementation will work but it's slow
# can this be delegated efficiently somehow?
# that may require additional string interfaces
length(s::SubString{<:DirectIndexString}) = endof(s)

function length(s::SubString{String})
return s.endof==0 ? 0 : Int(ccall(:u8_charnum, Csize_t, (Ptr{UInt8}, Csize_t),
pointer(s), nextind(s, s.endof) - 1))
Expand All @@ -87,11 +85,6 @@ function isvalid(s::SubString, i::Integer)
return (start(s) <= i <= endof(s)) && isvalid(s.string, s.offset+i)
end

isvalid(s::SubString{<:DirectIndexString}, i::Integer) = (start(s) <= i <= endof(s))

ind2chr(s::SubString{<:DirectIndexString}, i::Integer) = begin checkbounds(s,i); i end
chr2ind(s::SubString{<:DirectIndexString}, i::Integer) = begin checkbounds(s,i); i end

nextind(s::SubString, i::Integer) = nextind(s.string, i+s.offset)-s.offset
prevind(s::SubString, i::Integer) = prevind(s.string, i+s.offset)-s.offset

Expand Down Expand Up @@ -177,7 +170,6 @@ Julia
```
"""
reverseind(s::AbstractString, i) = chr2ind(s, length(s) + 1 - ind2chr(reverse(s), i))
reverseind(s::Union{DirectIndexString,SubString{DirectIndexString}}, i::Integer) = length(s) + 1 - i
reverseind(s::RevString, i::Integer) = endof(s) - i + 1
reverseind(s::SubString{String}, i::Integer) =
reverseind(s.string, nextind(s.string, endof(s.string))-s.offset-s.endof+i-1) - s.offset
Expand Down
13 changes: 8 additions & 5 deletions doc/src/manual/interacting-with-julia.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,18 @@ search: AbstractString AbstractSparseMatrix AbstractSparseVector AbstractSet
No documentation found.
Summary:
Summary
≡≡≡≡≡≡≡≡≡
abstract AbstractString <: Any
abstract type AbstractString <: Any
Subtypes:
Subtypes
≡≡≡≡≡≡≡≡≡≡
Base.Test.GenericString
DirectIndexString
Base.SubstitutionString
String
SubString
Test.GenericString
```

Help mode can be exited by pressing backspace at the beginning of the line.
Expand Down
4 changes: 2 additions & 2 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ Type{Integer} # cache this
@test typejoin(Array{Float64},BitArray) <: AbstractArray
@test typejoin(Array{Bool},BitArray) <: AbstractArray{Bool}
@test typejoin(Tuple{Int,Int8},Tuple{Int8,Float64}) === Tuple{Signed,Real}
@test Base.typeseq(typejoin(Tuple{String,String},Tuple{DirectIndexString,String},
Tuple{String,DirectIndexString},Tuple{Int,String,Int}),
@test Base.typeseq(typejoin(Tuple{String,String},Tuple{GenericString,String},
Tuple{String,GenericString},Tuple{Int,String,Int}),
Tuple{Any,AbstractString,Vararg{Int}})
@test Base.typeseq(typejoin(Tuple{Int8,Vararg{Int}},Tuple{Int8,Int8}),
Tuple{Int8,Vararg{Signed}})
Expand Down
2 changes: 1 addition & 1 deletion test/strings/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ end
@test !ismatch(Regex("aa"), SubString("",1,0))
@test ismatch(Regex(""), SubString("",1,0))

# isvalid(), chr2ind() and ind2chr() for SubString{DirectIndexString}
# isvalid(), chr2ind() and ind2chr() for SubString{String}
let ss, s="lorem ipsum",
sdict=Dict(SubString(s,1,11)=>s,
SubString(s,1,6)=>"lorem ",
Expand Down

0 comments on commit 175f7a1

Please sign in to comment.