Skip to content

Conversation

jakobnissen
Copy link
Member

@jakobnissen jakobnissen commented Sep 26, 2025

This commit includes several, interlocked changes:

  1. It removes an undocumented SubString constructor which triage has agreed can be considered internal and should be removed
  2. It adds a new public, but unexported function unsafe_substring, which creates a substring without checking for valid string indices. This new function is used in place of the old removed method, internally in Julia.
  3. It adds a new public, but unexported function unannotate, which gives the underlying non-annotated string of an AnnotatedString or SubString{AnnotatedString}. The reason for this change is that currently, code outside Base (namely, in StyledStrings and JuliaSyntaxHighlighting) relies on this operation. Its current implementation reaches into both AnnotatedString and SubString internals. Instead, I provide the function here in Base, and let the two stdlibs use it. Also in general, I think it's a completely reasonable basic function to have for annotated strings.

For reviewers: We can make these functions exported (I don't have a strong opinion on that).

For this PR to land, it also requires compatible PRs in StyledStrings.jl and JuliaSyntaxHighlighting.jl, which uses the removed constructor.

This depends on two PRs to be merged first:

  1. Switch noshift substring constructor to new unannotate function JuliaSyntaxHighlighting.jl#13
  2. Replace use of noshift constructor with new unannotate StyledStrings.jl#125

Supersedes #59606
Closes #59610

This commit includes two changes:
* It removes an undocumented SubString constructor which triage has agreed can
  be considered internal
* It adds a new public, but unexported function `unsafe_substring`, which creates
  a substring without checking for valid string indices.
@jakobnissen
Copy link
Member Author

@tecosaur both in Base, in StyledStrings, and in JuliaSyntaxHighlighting, a repeated pattern is to get the underlying string of an AnnotatedString or SubString{AnnotatedString}. The implementation for doing that requires reading internal fields of SubString and AnnotatedString.

The fact that this operation is used everywhere AnnotatedString is used, and that it requires use of internals, suggests this should be a public function.
I suggest making public the plain_substring function introduced in this PR (maybe with a better name), and then making use of it in StyledStrings and JuliaSyntaxHighlighting. It could be called unannotated or something.

@jakobnissen jakobnissen changed the title Remove noshift SubString constructor and add unsafe_substring Add new public functions unsafe_substring and unannotate Sep 27, 2025
@jakobnissen jakobnissen marked this pull request as ready for review September 27, 2025 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
strings "Strings!"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove :noshift SubString constructor and replace it with something else
3 participants