Skip to content

Commit ebc668d

Browse files
committed
Rename strings/types.jl to strings/substring.jl
Move the non-substring related functionality to strings/basic.jl.
1 parent 80f4eb0 commit ebc668d

File tree

3 files changed

+50
-49
lines changed

3 files changed

+50
-49
lines changed

base/strings/basic.jl

+49
Original file line numberDiff line numberDiff line change
@@ -566,3 +566,52 @@ function filter(f, s::AbstractString)
566566
end
567567
String(take!(out))
568568
end
569+
570+
## reverse an index i so that reverse(s)[i] == s[reverseind(s,i)]
571+
572+
"""
573+
reverseind(v, i)
574+
575+
Given an index `i` in [`reverse(v)`](@ref), return the corresponding index in `v` so that
576+
`v[reverseind(v,i)] == reverse(v)[i]`. (This can be nontrivial in cases where `v` contains
577+
non-ASCII characters.)
578+
579+
# Examples
580+
```jldoctest
581+
julia> r = reverse("Julia")
582+
"ailuJ"
583+
584+
julia> for i in 1:length(r)
585+
print(r[reverseind("Julia", i)])
586+
end
587+
Julia
588+
```
589+
"""
590+
reverseind(s::AbstractString, i) = chr2ind(s, length(s) + 1 - ind2chr(reverse(s), i))
591+
592+
"""
593+
repeat(s::AbstractString, r::Integer)
594+
595+
Repeat a string `r` times. This can equivalently be accomplished by calling [`s^r`](@ref ^).
596+
597+
# Examples
598+
```jldoctest
599+
julia> repeat("ha", 3)
600+
"hahaha"
601+
```
602+
"""
603+
repeat(s::AbstractString, r::Integer) = repeat(convert(String, s), r)
604+
605+
"""
606+
^(s::Union{AbstractString,Char}, n::Integer)
607+
608+
Repeat a string or character `n` times.
609+
The [`repeat`](@ref) function is an alias to this operator.
610+
611+
# Examples
612+
```jldoctest
613+
julia> "Test "^3
614+
"Test Test Test "
615+
```
616+
"""
617+
(^)(s::Union{AbstractString,Char}, r::Integer) = repeat(s, r)

base/strings/strings.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

33
include("strings/errors.jl")
4-
include("strings/types.jl")
4+
include("strings/substring.jl")
55
include("strings/basic.jl")
66
include("strings/search.jl")
77
include("strings/util.jl")

base/strings/types.jl renamed to base/strings/substring.jl

-48
Original file line numberDiff line numberDiff line change
@@ -97,57 +97,9 @@ function unsafe_convert(::Type{Ptr{R}}, s::SubString{String}) where R<:Union{Int
9797
convert(Ptr{R}, pointer(s.string)) + s.offset
9898
end
9999

100-
## reverse an index i so that reverse(s)[i] == s[reverseind(s,i)]
101-
102-
"""
103-
reverseind(v, i)
104-
105-
Given an index `i` in [`reverse(v)`](@ref), return the corresponding index in `v` so that
106-
`v[reverseind(v,i)] == reverse(v)[i]`. (This can be nontrivial in cases where `v` contains
107-
non-ASCII characters.)
108-
109-
# Examples
110-
```jldoctest
111-
julia> r = reverse("Julia")
112-
"ailuJ"
113-
114-
julia> for i in 1:length(r)
115-
print(r[reverseind("Julia", i)])
116-
end
117-
Julia
118-
```
119-
"""
120-
reverseind(s::AbstractString, i) = chr2ind(s, length(s) + 1 - ind2chr(reverse(s), i))
121100
reverseind(s::Union{DirectIndexString,SubString{DirectIndexString}}, i::Integer) = length(s) + 1 - i
122101
reverseind(s::SubString{String}, i::Integer) =
123102
reverseind(s.string, nextind(s.string, endof(s.string))-s.offset-s.endof+i-1) - s.offset
124103

125-
"""
126-
repeat(s::AbstractString, r::Integer)
127-
128-
Repeat a string `r` times. This can equivalently be accomplished by calling [`s^r`](@ref ^).
129-
130-
# Examples
131-
```jldoctest
132-
julia> repeat("ha", 3)
133-
"hahaha"
134-
```
135-
"""
136-
repeat(s::AbstractString, r::Integer) = repeat(convert(String, s), r)
137-
138-
"""
139-
^(s::Union{AbstractString,Char}, n::Integer)
140-
141-
Repeat a string or character `n` times.
142-
The [`repeat`](@ref) function is an alias to this operator.
143-
144-
# Examples
145-
```jldoctest
146-
julia> "Test "^3
147-
"Test Test Test "
148-
```
149-
"""
150-
(^)(s::Union{AbstractString,Char}, r::Integer) = repeat(s,r)
151-
152104
pointer(x::SubString{String}) = pointer(x.string) + x.offset
153105
pointer(x::SubString{String}, i::Integer) = pointer(x.string) + x.offset + (i-1)

0 commit comments

Comments
 (0)