Skip to content

Commit

Permalink
better documentation for string reversal (#23793)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj authored and JeffBezanson committed Sep 21, 2017
1 parent 07479c8 commit c8f1c55
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions base/strings/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,22 @@ end
Reverses a string.
Technically, this function reverses the codepoints in a string, and its
main utility is for reversed-order string processing, especially for reversed
regular-expression searches. See also [`reverseind`](@ref) to convert indices
in `s` to indices in `reverse(s)` and vice-versa, and [`graphemes`](@ref)
to operate on user-visible "characters" (graphemes) rather than codepoints.
# Examples
```jldoctest
julia> reverse("JuliaLang")
"gnaLailuJ"
julia> reverse("ax̂e") # combining characters can lead to surprising results
"êxa"
julia> join(reverse(collect(graphemes("ax̂e")))) # reverses graphemes
"ex̂a"
```
"""
reverse(s::AbstractString) = RevString(s)
Expand All @@ -131,9 +143,9 @@ reverse(s::RevString) = s.string
"""
reverseind(v, i)
Given an index `i` in `reverse(v)`, return the corresponding index in `v` so that
`v[reverseind(v,i)] == reverse(v)[i]`. (This can be nontrivial in the case where `v` is a
Unicode string.)
Given an index `i` in [`reverse(v)`](@ref), return the corresponding index in `v` so that
`v[reverseind(v,i)] == reverse(v)[i]`. (This can be nontrivial in cases where `v` contains
non-ASCII characters.)
# Examples
```jldoctest
Expand Down

0 comments on commit c8f1c55

Please sign in to comment.