Skip to content

Commit

Permalink
Add Compat entries for #11140 & #11241
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottPJones committed May 22, 2015
1 parent 2583c38 commit e871aaa
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,30 @@ if VERSION < v"0.4.0-dev+2861"
export muladd
end

if VERSION < v"0.4.0-dev+4734"
function is_valid_utf32(str::Union(Vector{Char}, Vector{UInt32}))
for i=1:length(str)
@inbounds if !is_valid_char(reinterpret(UInt32, str[i])) ; return false ; end
end
return true
end
is_valid_utf32(str::UTF32String) = is_valid_utf32(str.data)
export is_valid_utf32
end

if VERSION < v"0.4.0-dev+4939"
import Base.isvalid
isvalid(ch::Char) = is_valid_char(ch)
isvalid(str::ASCIIString) = is_valid_ascii(str)
isvalid(str::UTF8String) = is_valid_utf8(str)
isvalid(str::UTF16String) = is_valid_utf16(str)
isvalid(str::UTF32String) = is_valid_utf32(str)
isvalid(::Type{Char}, ch) = is_valid_char(ch)
isvalid(::Type{ASCIIString}, str) = is_valid_ascii(str)
isvalid(::Type{UTF8String}, str) = is_valid_utf8(str)
isvalid(::Type{UTF16String}, str) = is_valid_utf16(str)
isvalid(::Type{UTF32String}, str) = is_valid_utf32(str)
export isvalid
end

end # module
22 changes: 22 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,25 @@ end

# fma and muladd
@test fma(3,4,5) == 3*4+5 == muladd(3,4,5)

# is_valid_utf32
s = utf32("abc")
@test is_valid_utf32(s)
s = utf32(UInt32[65,0x110000])
@test !is_valid_utf32(s)

# isvalid
let s = "abcdef", u8 = "abcdef\uff", u16 = utf16(u8), u32 = utf32(u8),
bad32 = utf32(UInt32[65,0x110000]), badch = Char[0x110000][1]

@test !isvalid(bad32)
@test !isvalid(badch)
@test isvalid(s)
@test isvalid(u8)
@test isvalid(u16)
@test isvalid(u32)
@test isvalid(ASCIIString, s)
@test isvalid(UTF8String, u8)
@test isvalid(UTF16String, u16)
@test isvalid(UTF32String, u32)
end

0 comments on commit e871aaa

Please sign in to comment.