diff --git a/src/LegacyStrings.jl b/src/LegacyStrings.jl index 684fe0f..c65196c 100644 --- a/src/LegacyStrings.jl +++ b/src/LegacyStrings.jl @@ -25,22 +25,17 @@ import Base: convert, getindex, isvalid, - lcfirst, length, lowercase, map, - next, nextind, pointer, prevind, reverse, reverseind, - rsearch, - search, show, sizeof, string, - ucfirst, unsafe_convert, uppercase, write @@ -52,22 +47,22 @@ import Compat: codeunit, ncodeunits -if isdefined(Base, :iterate) - import Base: iterate -end -if isdefined(Base, :UnicodeError) +if VERSION < v"0.7-" + import Base: lcfirst + import Base: next + import Base: rsearch + import Base: search + import Base: ucfirst import Base: UnicodeError -else - include("unicodeerror.jl") -end - -if isdefined(Base, :DirectIndexString) using Base: DirectIndexString else + import Base: iterate + include("unicodeerror.jl") include("directindex.jl") end + struct ASCIIString <: DirectIndexString data::Vector{UInt8} ASCIIString(data::String) = new(Vector{UInt8}(codeunits(data))) diff --git a/test/runtests.jl b/test/runtests.jl index 1755cdf..6f69b81 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,7 +6,6 @@ using Compat: view, String using LegacyStrings using LegacyStrings: ASCIIString, UTF8String # override Compat's version import LegacyStrings: - ascii, checkstring, UnicodeError, UTF_ERR_SHORT @@ -208,13 +207,17 @@ let ch = 0x10000 end let str = UTF8String(b"this is a test\xed\x80") - @test next(str, 15) == ('\ufffd', 16) + @static if VERSION < v"0.7-" + @test next(str, 15) == ('\ufffd', 16) + else + @test iterate(str, 15) == ('\ufffd', 16) + end @test_throws BoundsError getindex(str, 0:3) @test_throws BoundsError getindex(str, 17:18) @test_throws BoundsError getindex(str, 2:17) @test_throws UnicodeError getindex(str, 16:17) # @test string(Char(0x110000)) == "\ufffd" - sa = SubString{ASCIIString}(ascii("This is a silly test"), 1, 14) + sa = SubString{ASCIIString}(LegacyStrings.ascii("This is a silly test"), 1, 14) s8 = convert(SubString{UTF8String}, sa) @test typeof(s8) == SubString{UTF8String} @test s8 == "This is a sill" @@ -283,7 +286,7 @@ function tstcvt(strUTF8::UTF8String, strUTF16::UTF16String, strUTF32::UTF32Strin end # Create some ASCII, UTF8, UTF16, and UTF32 strings -strAscii = ascii("abcdefgh") +strAscii = LegacyStrings.ascii("abcdefgh") strA_UTF8 = utf8(("abcdefgh\uff")[1:8]) strL_UTF8 = utf8("abcdef\uff\uff") str2_UTF8 = utf8("abcd\uff\uff\u7ff\u7ff") @@ -464,7 +467,7 @@ end @test reverse(utf32("abcd \uff\u7ff\u7fff\U7ffff")) == utf32("\U7ffff\u7fff\u7ff\uff dcba") # Test pointer() functions -let str = ascii("this ") +let str = LegacyStrings.ascii("this ") u8 = utf8(str) u16 = utf16(str) u32 = utf32(str) @@ -545,8 +548,13 @@ let @test lastindex(srep) == 7 - @test next(srep, 3) == ('β',5) - @test next(srep, 7) == ('β',9) + @static if VERSION < v"0.7-" + @test next(srep, 3) == ('β',5) + @test next(srep, 7) == ('β',9) + else + @test iterate(srep, 3) == ('β',5) + @test iterate(srep, 7) == ('β',9) + end @test srep[7] == 'β' @static if VERSION < v"0.7.0-DEV.2924"