Skip to content

Commit d5035d8

Browse files
authored
Merge pull request #22694 from stevengj/graphemesub
fix graphemes eltype for substrings
2 parents eaaae21 + b13e9d1 commit d5035d8

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

base/strings/utf8proc.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ letter combined with an accent mark is a single grapheme.)
354354
graphemes(s::AbstractString) = GraphemeIterator{typeof(s)}(s)
355355

356356
eltype(::Type{GraphemeIterator{S}}) where {S} = SubString{S}
357+
eltype(::Type{GraphemeIterator{SubString{S}}}) where {S} = SubString{S}
357358

358359
function length(g::GraphemeIterator)
359360
c0 = Char(0x00ad) # soft hyphen (grapheme break always allowed after this)

test/unicode/utf8proc.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,12 @@ end
311311
h = hash(str)
312312
@test hash(g) == h
313313
@test convert(GenericString, g) == str
314-
io = IOBuffer()
315-
show(io, g)
316-
check = "length-14 GraphemeIterator{String} for \"$str\""
317-
@test String(take!(io)) == check
314+
@test repr(g) == "length-14 GraphemeIterator{String} for \"$str\""
318315
end
319316
end
317+
318+
@testset "#22693: substring graphemes" begin
319+
g = graphemes(SubString("123α56789", 1, 6))
320+
@test eltype(g) == SubString{String}
321+
@test collect(g) == ["1","2","3","α","5"]
322+
end

0 commit comments

Comments
 (0)