Skip to content

Commit 175f7a1

Browse files
bkaminsnalimilan
authored andcommitted
Remove DirectIndexString from Base (#24262)
1 parent 34aab02 commit 175f7a1

File tree

6 files changed

+12
-41
lines changed

6 files changed

+12
-41
lines changed

base/boot.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export
130130
Signed, Int, Int8, Int16, Int32, Int64, Int128,
131131
Unsigned, UInt, UInt8, UInt16, UInt32, UInt64, UInt128,
132132
# string types
133-
Char, DirectIndexString, AbstractString, String, IO,
133+
Char, AbstractString, String, IO,
134134
# errors
135135
ErrorException, BoundsError, DivideError, DomainError, Exception,
136136
InterruptException, InexactError, OutOfMemoryError, ReadOnlyMemoryError,
@@ -275,8 +275,6 @@ struct InitError <: WrappedException
275275
error
276276
end
277277

278-
abstract type DirectIndexString <: AbstractString end
279-
280278
String(s::String) = s # no constructor yet
281279

282280
# This should always be inlined

base/strings/basic.jl

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
endof(s::AbstractString) = error("you must implement endof(", typeof(s), ")")
66
next(s::AbstractString, i::Int) = error("you must implement next(", typeof(s), ",Int)")
7-
next(s::DirectIndexString, i::Int) = (s[i],i+1)
87
next(s::AbstractString, i::Integer) = next(s,Int(i))
98

109
string() = ""
@@ -70,8 +69,6 @@ julia> 'j' * "ulia"
7069

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

73-
length(s::DirectIndexString) = endof(s)
74-
7572
"""
7673
length(s::AbstractString)
7774
@@ -198,8 +195,6 @@ isless(a::Symbol, b::Symbol) = cmp(a,b) < 0
198195

199196
## Generic validation functions ##
200197

201-
isvalid(s::DirectIndexString, i::Integer) = (start(s) <= i <= endof(s))
202-
203198
"""
204199
isvalid(str::AbstractString, i::Integer)
205200
@@ -237,20 +232,6 @@ end
237232

238233
## Generic indexing functions ##
239234

240-
prevind(s::DirectIndexString, i::Integer) = Int(i)-1
241-
nextind(s::DirectIndexString, i::Integer) = Int(i)+1
242-
243-
function prevind(s::DirectIndexString, i::Integer, nchar::Integer)
244-
nchar > 0 || throw(ArgumentError("nchar must be greater than 0"))
245-
Int(i)-nchar
246-
end
247-
248-
function nextind(s::DirectIndexString, i::Integer, nchar::Integer)
249-
nchar > 0 || throw(ArgumentError("nchar must be greater than 0"))
250-
Int(i)+nchar
251-
end
252-
253-
254235
"""
255236
prevind(str::AbstractString, i::Integer, nchar::Integer=1)
256237
@@ -371,9 +352,6 @@ checkbounds(s::AbstractString, r::AbstractRange{<:Integer}) = isempty(r) || (min
371352
checkbounds(s::AbstractString, I::AbstractArray{<:Real}) = all(i -> checkbounds(s, i), I)
372353
checkbounds(s::AbstractString, I::AbstractArray{<:Integer}) = all(i -> checkbounds(s, i), I)
373354

374-
ind2chr(s::DirectIndexString, i::Integer) = begin checkbounds(s,i); i end
375-
chr2ind(s::DirectIndexString, i::Integer) = begin checkbounds(s,i); i end
376-
377355

378356
"""
379357
ind2chr(s::AbstractString, i::Integer)

base/strings/types.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ sizeof(s::SubString{String}) = s.endof == 0 ? 0 : nextind(s, s.endof) - 1
5959
# default implementation will work but it's slow
6060
# can this be delegated efficiently somehow?
6161
# that may require additional string interfaces
62-
length(s::SubString{<:DirectIndexString}) = endof(s)
63-
6462
function length(s::SubString{String})
6563
return s.endof==0 ? 0 : Int(ccall(:u8_charnum, Csize_t, (Ptr{UInt8}, Csize_t),
6664
pointer(s), nextind(s, s.endof) - 1))
@@ -87,11 +85,6 @@ function isvalid(s::SubString, i::Integer)
8785
return (start(s) <= i <= endof(s)) && isvalid(s.string, s.offset+i)
8886
end
8987

90-
isvalid(s::SubString{<:DirectIndexString}, i::Integer) = (start(s) <= i <= endof(s))
91-
92-
ind2chr(s::SubString{<:DirectIndexString}, i::Integer) = begin checkbounds(s,i); i end
93-
chr2ind(s::SubString{<:DirectIndexString}, i::Integer) = begin checkbounds(s,i); i end
94-
9588
nextind(s::SubString, i::Integer) = nextind(s.string, i+s.offset)-s.offset
9689
prevind(s::SubString, i::Integer) = prevind(s.string, i+s.offset)-s.offset
9790

@@ -177,7 +170,6 @@ Julia
177170
```
178171
"""
179172
reverseind(s::AbstractString, i) = chr2ind(s, length(s) + 1 - ind2chr(reverse(s), i))
180-
reverseind(s::Union{DirectIndexString,SubString{DirectIndexString}}, i::Integer) = length(s) + 1 - i
181173
reverseind(s::RevString, i::Integer) = endof(s) - i + 1
182174
reverseind(s::SubString{String}, i::Integer) =
183175
reverseind(s.string, nextind(s.string, endof(s.string))-s.offset-s.endof+i-1) - s.offset

doc/src/manual/interacting-with-julia.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,18 @@ search: AbstractString AbstractSparseMatrix AbstractSparseVector AbstractSet
9191
9292
No documentation found.
9393
94-
Summary:
94+
Summary
95+
≡≡≡≡≡≡≡≡≡
9596
96-
abstract AbstractString <: Any
97+
abstract type AbstractString <: Any
9798
98-
Subtypes:
99+
Subtypes
100+
≡≡≡≡≡≡≡≡≡≡
99101
100-
Base.Test.GenericString
101-
DirectIndexString
102+
Base.SubstitutionString
102103
String
104+
SubString
105+
Test.GenericString
103106
```
104107

105108
Help mode can be exited by pressing backspace at the beginning of the line.

test/core.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ Type{Integer} # cache this
9595
@test typejoin(Array{Float64},BitArray) <: AbstractArray
9696
@test typejoin(Array{Bool},BitArray) <: AbstractArray{Bool}
9797
@test typejoin(Tuple{Int,Int8},Tuple{Int8,Float64}) === Tuple{Signed,Real}
98-
@test Base.typeseq(typejoin(Tuple{String,String},Tuple{DirectIndexString,String},
99-
Tuple{String,DirectIndexString},Tuple{Int,String,Int}),
98+
@test Base.typeseq(typejoin(Tuple{String,String},Tuple{GenericString,String},
99+
Tuple{String,GenericString},Tuple{Int,String,Int}),
100100
Tuple{Any,AbstractString,Vararg{Int}})
101101
@test Base.typeseq(typejoin(Tuple{Int8,Vararg{Int}},Tuple{Int8,Int8}),
102102
Tuple{Int8,Vararg{Signed}})

test/strings/types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ end
146146
@test !ismatch(Regex("aa"), SubString("",1,0))
147147
@test ismatch(Regex(""), SubString("",1,0))
148148

149-
# isvalid(), chr2ind() and ind2chr() for SubString{DirectIndexString}
149+
# isvalid(), chr2ind() and ind2chr() for SubString{String}
150150
let ss, s="lorem ipsum",
151151
sdict=Dict(SubString(s,1,11)=>s,
152152
SubString(s,1,6)=>"lorem ",

0 commit comments

Comments
 (0)