Skip to content

Commit 077b721

Browse files
authored
Merge pull request #10 from jessymilare/master
Fix bug of to_ascii constructor from vectors and pointers
2 parents 027da44 + 8bec8b8 commit 077b721

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/legacy.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
# Renamed from ascii to to_ascii, to prevent issues with Base.ascii
66
to_ascii(str) = convert(ASCIIStr, str)
7-
to_ascii(pnt::Ptr{UInt8}) = convert(ASCIIStr, unsafe_string(p))
8-
to_ascii(pnt::Ptr{UInt8}, len::Integer) = convert(ASCIIStr, unsafe_string(p, len))
7+
to_ascii(p::Ptr{UInt8}) = convert(ASCIIStr, unsafe_string(p))
8+
to_ascii(p::Ptr{UInt8}, len::Integer) = convert(ASCIIStr, unsafe_string(p, len))
99

1010
"""
1111
utf8(s)

src/utf8.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ is_ascii(str::SubString{<:Str{C}}) where {C<:Union{UTF8CSE,LatinCSE,Binary_CSEs,
157157

158158
is_ascii(vec::Vector{T}) where {T<:CodeUnitTypes} =
159159
(cnt = sizeof(vec)) == 0 ? true :
160-
@preserve str _check_mask_ul(pointer(vec), cnt, _ascii_mask(T))
160+
@preserve vec _check_mask_ul(pointer(vec), cnt, _ascii_mask(T))
161161

162162
is_ascii(str::Str{C}) where {C<:Union{UTF8_CSEs,LatinCSE,Binary_CSEs,UTF16CSE,UCS2CSE,
163163
Text2CSE,Text4CSE,UTF32CSE}} =

test/basic.jl

+13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ end
1616

1717
string_types = keys(compat_types)
1818

19+
legacy_types = Dict(ASCIIStr => to_ascii,
20+
UTF8Str => utf8,
21+
UTF16Str => utf16,
22+
UTF32Str => utf32)
23+
1924
## create type specific test strings
2025
test_strings_base = Dict()
2126
for T in AllCharTypes
@@ -28,6 +33,14 @@ end
2833
end
2934
end
3035

36+
@testset "legacy constructors" begin
37+
for (ST, constructor) in legacy_types, str in test_strings_base[ASCIIChr]
38+
vec = Vector{codeunit(ST)}(codeunits(str))
39+
@eval @test $constructor($vec) == $str
40+
@eval @test $constructor(pointer($vec), $(length(vec))) == $str
41+
end
42+
end
43+
3144
@testset "empty strings" begin
3245
for ST in keys(compat_types)
3346
@eval @test is_empty(convert($ST, ""))

0 commit comments

Comments
 (0)