Skip to content

Commit d461708

Browse files
authored
Merge pull request #18 from JuliaString/spj/fixlatin
Fix Issue #17, as well as another problem with convert and _LatinStr, and a new error code added in 1.8
2 parents 266312c + 2d33623 commit d461708

5 files changed

Lines changed: 15 additions & 6 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ authors = ["ScottPJones <scottjones@alum.mit.edu>"]
44
keywords = ["Strings"]
55
license = "MIT"
66
uuid = "e79e7a6a-7bb1-5a4d-9d64-da657b06f53a"
7-
version = "1.1.0"
7+
version = "1.1.1"
88

99
[deps]
1010
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

src/latin.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#=
22
LatinStr/_LatinStr type (ISO Latin1 8-bit subset of Unicode)
33
4-
Copyright 2017 Gandalf Software, Inc., Scott P. Jones, and other contributors to the Julia language
4+
Copyright 2017-2022 Gandalf Software, Inc., Scott P. Jones,
5+
and other contributors to the Julia language
56
Licensed under MIT License, see LICENSE.md
67
Based in part on code for ASCIIString that used to be in Julia
78
=#
@@ -50,7 +51,7 @@ const LatinSubStr = SubString{<:Str{LatinCSE}}
5051
const _LatinSubStr = SubString{<:Str{_LatinCSE}}
5152

5253
_cpyconvert(::Type{C}, str) where {C} = Str(C, _copysub(str))::Str{C,Nothing,Nothing,Nothing}
53-
_cpysubset(::Type{_LatinCSE}, str) = Str(is_ascii(s) ? ASCIICSE : _LatinCSE, _copysub(s))
54+
_cpysubset(::Type{_LatinCSE}, str) = Str(is_ascii(str) ? ASCIICSE : _LatinCSE, _copysub(str))
5455

5556
convert(::Type{<:Str{LatinCSE}}, s::Str{LatinCSE}) = s
5657
convert(::Type{<:Str{LatinCSE}}, s::Str{ASCIICSE}) = _cpyconvert(LatinCSE, s)
@@ -167,7 +168,7 @@ end
167168

168169
function convert(::Type{<:Str{C}}, vec::Vector{CU}) where {C<:Latin_CSEs,CU<:CodeUnitTypes}
169170
# handle zero length string quickly
170-
(len = length(vec)) == 0 && return _empty_str(C)
171+
(len = length(vec)) == 0 && return empty_str(C)
171172
@preserve vec begin
172173
pnt = pointer(vec)
173174
# get number of bytes to allocate

test/basic.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ legacy_types = Dict(ASCIIStr => to_ascii,
2121
UTF16Str => utf16,
2222
UTF32Str => utf32)
2323

24+
const errtype =
25+
@static isdefined(Base, :CanonicalIndexError) ? Base.CanonicalIndexError : ErrorException
26+
2427
## create type specific test strings
2528
test_strings_base = Dict()
2629
for T in AllCharTypes
@@ -872,7 +875,7 @@ end
872875
@test u[1] == 0xe2
873876
@test u[2] == 0x88
874877
@test u[8] == 0x79
875-
@test_throws ErrorException (u[1] = 0x00)
878+
@test_throws errtype (u[1] = 0x00)
876879
@test collect(u) == b"∀x∃y"
877880
end
878881

test/convert.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Typos in Latin conversions
2+
3+
@test convert(StrBase._LatinStr, SubString(LatinStr("abc"))) == ASCIIStr("abc")
4+
@test convert(LatinStr, UInt8[]) == ""
5+
16
# issue #11551 (#11004,#10959)
27
function tstcvt(strUTF8::UTF8Str, strUTF16::UTF16Str, strUTF32::UTF32Str)
38
@test utf16(strUTF8) == strUTF16

test/util.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@
314314
b = testb()
315315
@test eltype(b) === UInt8
316316
@test b isa AbstractVector
317-
@test_throws ErrorException b[4] = '4'
317+
@test_throws errtype (b[4] = '4')
318318
@test testb() == UInt8['0','1','2','3']
319319
end
320320
end

0 commit comments

Comments
 (0)