Skip to content

Commit

Permalink
Merge pull request #198 from JuliaLang/yyc/more-strings
Browse files Browse the repository at this point in the history
Add unexported alias for UTF8String and ASCIIString
  • Loading branch information
tkelman committed May 11, 2016
2 parents 93ff2e1 + 7c85f0c commit 2a969ae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ Currently, the `@compat` macro supports the following syntaxes:

* `String` has undergone multiple changes: in julia 0.3 it was an abstract type and then got renamed to `AbstractString`; later, `ASCIIString` and `UTF8String` got merged into a concrete type, `String`.

For packages that still need `ASCIIString` or `UTF8String` on julia 0.4 and
want to avoid the deprecation warning on julia 0.5,
use `Compat.ASCIIString` and `Compat.UTF8String` instead.
Note that `Compat.ASCIIString` does **not** guarantee `isascii` on julia 0.5.
Use `isascii` to check if the string is pure ASCII if needed.

* `typealias AbstractString String` - `String` has been renamed to `AbstractString` [#8872](https://github.com/JuliaLang/julia/pull/8872)

* `typealias AbstractFloat FloatingPoint` - `FloatingPoint` has been renamed to `AbstractFloat` [#12162](https://github.com/JuliaLang/julia/pull/12162)
Expand Down
3 changes: 3 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ using Base.Meta

if isdefined(Core, :String) && isdefined(Core, :AbstractString)
typealias String Core.String
# Not exported in order to not break code on 0.5
typealias UTF8String Core.String
typealias ASCIIString Core.String
else
typealias String Base.ByteString
end
Expand Down
16 changes: 9 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ let s = "abcdef", u8 = "abcdef\uff", u16 = utf16(u8), u32 = utf32(u8),
@test isvalid(u8)
@test isvalid(u16)
@test isvalid(u32)
@test isvalid(ASCIIString, s)
@test isvalid(UTF8String, u8)
@test isvalid(Compat.ASCIIString, s)
@test isvalid(Compat.UTF8String, u8)
@test isvalid(UTF16String, u16)
@test isvalid(UTF32String, u32)
end
Expand Down Expand Up @@ -668,10 +668,10 @@ mktempdir() do dir

for text in [
old_text,
convert(UTF8String, Char['A' + i % 52 for i in 1:(div(SZ_UNBUFFERED_IO,2))]),
convert(UTF8String, Char['A' + i % 52 for i in 1:( SZ_UNBUFFERED_IO -1)]),
convert(UTF8String, Char['A' + i % 52 for i in 1:( SZ_UNBUFFERED_IO )]),
convert(UTF8String, Char['A' + i % 52 for i in 1:( SZ_UNBUFFERED_IO +1)])
convert(Compat.UTF8String, Char['A' + i % 52 for i in 1:(div(SZ_UNBUFFERED_IO,2))]),
convert(Compat.UTF8String, Char['A' + i % 52 for i in 1:( SZ_UNBUFFERED_IO -1)]),
convert(Compat.UTF8String, Char['A' + i % 52 for i in 1:( SZ_UNBUFFERED_IO )]),
convert(Compat.UTF8String, Char['A' + i % 52 for i in 1:( SZ_UNBUFFERED_IO +1)])
]

write(filename, text)
Expand Down Expand Up @@ -1053,7 +1053,7 @@ for (Fun, func) in [(:AndFun, :&),
(:DotRDivFun, :./),
(:LDivFun, :\),
(:IDivFun, :div),
(:DotIDivFun, symbol("")),
(:DotIDivFun, @compat(Symbol(""))),
(:ModFun, :mod),
(:RemFun, :rem),
(:DotRemFun, :.%),
Expand Down Expand Up @@ -1127,3 +1127,5 @@ end
foostring(::String) = 1
@test foostring("hello") == 1
@test foostring("λ") == 1
@test isa("hello", Compat.ASCIIString)
@test isa("λ", Compat.UTF8String)

0 comments on commit 2a969ae

Please sign in to comment.