Skip to content

Commit

Permalink
Rename (Tagged → Annotated)String, etc.
Browse files Browse the repository at this point in the history
Please, please, let this be the last rename.
  • Loading branch information
tecosaur committed Oct 17, 2023
1 parent 236dbcd commit 1f127b0
Show file tree
Hide file tree
Showing 19 changed files with 559 additions and 558 deletions.
17 changes: 9 additions & 8 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ New language features
difference between `public` and `export` is that `public` names do not become
available when `using` a package/module. ([#50105])
* `ScopedValue` implement dynamic scope with inheritance across tasks ([#50958]).
* A new `AbstractString` type, `TaggedString`, is introduced that allows for
(arbitrary) regional annotations to be attached to an underlying string. This is
very useful for allowing styling information to be encoded separately, and is
used extensively in the new `StyledStrings` standard library. There is also a
new `TaggedChar` type, that is the equivalent new `AbstractChar` type.
* A new `AbstractString` type, `AnnotatedString`, is introduced that allows for
regional annotations to be attached to an underlying string. This type is
particularly useful for holding styling information, and is used extensively
in the new `StyledStrings` standard library. There is also a new `AnnotatedChar`
type, that is the equivalent new `AbstractChar` type.

Language changes
----------------
Expand Down Expand Up @@ -60,11 +60,12 @@ Standard library changes

* A new standard library for handling styling in a more comprehensive and structured way.
* The new `Faces` struct serves as a container for text styling information
(think typeface), and comes with a framework to provide a convenient,
extensible (via `addface!`), and customisable (with a user's `Faces.toml` and `loadfaces!`) approach to
(think typeface, as well as color and decoration), and comes with a framework
to provide a convenient, extensible (via `addface!`), and customisable (with a
user's `Faces.toml` and `loadfaces!`) approach to
styled content.
* The new `@styled_str` string macro provides a convenient way of creating a
`TaggedString` with various faces or other attributes applied.
`AnnotatedString` with various faces or other attributes applied.

#### Package Manager

Expand Down
8 changes: 4 additions & 4 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1089,12 +1089,12 @@ public
Generator,
ImmutableDict,
OneTo,
TaggedString,
TaggedChar,
AnnotatedString,
AnnotatedChar,
UUID,

# Tagged strings
taggedstring,
# Annotated strings
annotatedstring,
annotate!,
annotations,

Expand Down
24 changes: 12 additions & 12 deletions base/regex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -427,35 +427,35 @@ function match(re::Regex, str::Union{SubString{String}, String}, idx::Integer,
return result
end

function _taggedmatch(m::RegexMatch{S}, str::TaggedString{S}) where {S<:AbstractString}
RegexMatch{TaggedString{S}}(
(@inbounds SubString{TaggedString{S}}(
function _annotatedmatch(m::RegexMatch{S}, str::AnnotatedString{S}) where {S<:AbstractString}
RegexMatch{AnnotatedString{S}}(
(@inbounds SubString{AnnotatedString{S}}(
str, m.match.offset, m.match.ncodeunits, Val(:noshift))),
Union{Nothing,SubString{TaggedString{S}}}[
Union{Nothing,SubString{AnnotatedString{S}}}[
if !isnothing(cap)
(@inbounds SubString{TaggedString{S}}(
(@inbounds SubString{AnnotatedString{S}}(
str, cap.offset, cap.ncodeunits, Val(:noshift)))
end for cap in m.captures],
m.offset, m.offsets, m.regex)
end

function match(re::Regex, str::TaggedString)
function match(re::Regex, str::AnnotatedString)
m = match(re, str.string)
if !isnothing(m)
_taggedmatch(m, str)
_annotatedmatch(m, str)
end
end

function match(re::Regex, str::TaggedString, idx::Integer, add_opts::UInt32=UInt32(0))
function match(re::Regex, str::AnnotatedString, idx::Integer, add_opts::UInt32=UInt32(0))
m = match(re, str.string, idx, add_opts)
if !isnothing(m)
_taggedmatch(m, str)
_annotatedmatch(m, str)
end
end

match(r::Regex, s::AbstractString) = match(r, s, firstindex(s))
match(r::Regex, s::AbstractString, i::Integer) = throw(ArgumentError(
"regex matching is only available for the String and TaggedString types; use String(s) to convert"
"regex matching is only available for the String and AnnotatedString types; use String(s) to convert"
))

findnext(re::Regex, str::Union{String,SubString}, idx::Integer) = _findnext_re(re, str, idx, C_NULL)
Expand Down Expand Up @@ -708,8 +708,8 @@ struct RegexMatchIterator{S <: AbstractString}

RegexMatchIterator(regex::Regex, string::AbstractString, ovr::Bool=false) =
new{String}(regex, String(string), ovr)
RegexMatchIterator(regex::Regex, string::TaggedString, ovr::Bool=false) =
new{TaggedString{String}}(regex, TaggedString(String(string.string), string.annotations), ovr)
RegexMatchIterator(regex::Regex, string::AnnotatedString, ovr::Bool=false) =
new{AnnotatedString{String}}(regex, AnnotatedString(String(string.string), string.annotations), ovr)
end
compile(itr::RegexMatchIterator) = (compile(itr.regex); itr)
eltype(::Type{<:RegexMatchIterator}) = RegexMatch
Expand Down
Loading

0 comments on commit 1f127b0

Please sign in to comment.