Skip to content

Commit

Permalink
better documentation for string reversal
Browse files Browse the repository at this point in the history
In looking back at #6165 (due to #23612), I realized that we never clearly documented the behavior or rationale.
  • Loading branch information
stevengj authored Sep 20, 2017
1 parent 4913cc4 commit b0103e9
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion base/strings/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,23 @@ end
Reverses a string.
Technically, this function reverses the "codepoints" in a string, and its
use is for reversed-order string processing, especially for reversed
regex (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
(which is more [visually pleasing but less useful](https://github.com/JuliaLang/julia/issues/6165) for reverse searching).
# 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,7 +144,7 @@ reverse(s::RevString) = s.string
"""
reverseind(v, i)
Given an index `i` in `reverse(v)`, return the corresponding index in `v` so that
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 the case where `v` is a
Unicode string.)
Expand Down

0 comments on commit b0103e9

Please sign in to comment.