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

Iteration error on AnnotatedStrings involving multiple codepoints #85

Closed
serenity4 opened this issue Aug 25, 2024 · 2 comments · Fixed by #86
Closed

Iteration error on AnnotatedStrings involving multiple codepoints #85

serenity4 opened this issue Aug 25, 2024 · 2 comments · Fixed by #86

Comments

@serenity4
Copy link
Contributor

serenity4 commented Aug 25, 2024

I stumbled upon an error while working with something similar to styled"𝟏{red:x}":

julia> styled"𝟏{red:x}"
"Error showing value of type Base.AnnotatedString{String}:
ERROR: StringIndexError: invalid index [4], valid nearby indices [1]=>'𝟏', [5]=>'x'
Stacktrace:
  [1] string_index_err(s::String, i::Int64)
    @ Base ./strings/string.jl:12
  [2] SubString{String}(s::String, i::Int64, j::Int64)
    @ Base ./strings/substring.jl:35
  [3] SubString(s::String, i::Int64, j::Int64)
    @ Base ./strings/substring.jl:49
  [4] SubString(s::String, r::UnitRange{Int64})
    @ Base ./strings/substring.jl:52
  [5] iterate(si::StyledStrings.RegionIterator{String}, i::Int64)
    @ StyledStrings ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/StyledStrings/src/regioniterator.jl:13
  [6] iterate
    @ ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/StyledStrings/src/regioniterator.jl:12 [inlined]
  [7] _ansi_writer(io::IOContext{Base.TTY}, s::Base.AnnotatedString{String}, string_writer::StyledStrings.var"#20#21"{Tuple{}, Tuple{Char, Char}})
    @ StyledStrings ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/StyledStrings/src/io.jl:233
  [8] escape_string
    @ ~/.julia/juliaup/julia-nightly/share/julia/stdlib/v1.12/StyledStrings/src/io.jl:266 [inlined]
  [9] print_quoted
    @ ./strings/io.jl:471 [inlined]
 [10] show
    @ ./strings/io.jl:197 [inlined]
 [11] show(io::IOContext{Base.TTY}, ::MIME{Symbol("text/plain")}, s::Base.AnnotatedString{String})
    @ Base ./strings/annotated.jl:186
  [...]

julia> versioninfo()
Julia Version 1.12.0-DEV.1093
Commit adb323f1b51 (2024-08-25 10:41 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 20 × 12th Gen Intel(R) Core(TM) i7-12700H
  WORD_SIZE: 64
  LLVM: libLLVM-18.1.7 (ORCJIT, alderlake)
Threads: 20 default, 0 interactive, 20 GC (on 20 virtual cores)
Environment:
  JULIA_INFO_COLOR = green
  JULIA_PKG_USE_CLI_GIT = true

It worked fine at some point (fairly early after the introduction of StyledStrings), then a change seems to have broken it.

@tecosaur
Copy link
Collaborator

Thanks for the report Cedric! I'm unfortunately busy for the next ~week or so, but I'll give this a look soon.

@serenity4
Copy link
Contributor Author

I had to dig into region iteration for some other stuff, and then had an idea what was up in this issue. Feel free to take a look at #86 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants