Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for generically extracting unannotated string #55458

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions base/strings/annotated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ A string with metadata, in the form of annotated regions.

More specifically, this is a simple wrapper around any other
[`AbstractString`](@ref) that allows for regions of the wrapped string to be
annotated with labeled values.
annotated with labelled values. The underlying string can be extracted by
calling a string constructor with the `AnnotatedString` as the argument.

```text
C
Expand Down Expand Up @@ -125,7 +126,10 @@ AnnotatedString(s::AnnotatedString, annots::Vector{Tuple{UnitRange{Int}, Pair{Sy
AnnotatedChar(c::AnnotatedChar, annots::Vector{Pair{Symbol, Any}}) =
AnnotatedChar(c.char, vcat(c.annotations, annots))

String(s::AnnotatedString{String}) = s.string # To avoid pointless overhead
# To allow for generically de-annotating a string.
(::Type{T})(s::AnnotatedString{T}) where {T <: AbstractString} = T(s.string)
String(s::AnnotatedString{String}) = s.string # To avoid pointless overhead (and avoid ambiguity)
AnnotatedString(s::AnnotatedString) = s # To resolve an ambiguity

## Conversion/promotion ##

Expand Down