Skip to content

Commit 615a623

Browse files
yuyichaotkelman
authored andcommitted
Fix errors and warnings on 0.6 (#14)
1 parent 96c851f commit 615a623

File tree

8 files changed

+27
-20
lines changed

8 files changed

+27
-20
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
julia 0.4
2-
Compat 0.8.4
2+
Compat 0.9.5

src/LegacyStrings.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import Base:
2424
endof,
2525
getindex,
2626
isvalid,
27-
lastidx,
2827
lcfirst,
2928
length,
3029
lowercase,
@@ -43,6 +42,12 @@ import Base:
4342
uppercase,
4443
write
4544

45+
using Compat
46+
47+
if isdefined(Base, :lastidx)
48+
import Base: lastidx
49+
end
50+
4651
if VERSION >= v"0.5.0-"
4752
immutable ASCIIString <: DirectIndexString
4853
data::Array{UInt8,1}

src/ascii.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function string(c::ASCIIString...)
2929
for s in c
3030
n += length(s.data)
3131
end
32-
v = Array(UInt8,n)
32+
v = Vector{UInt8}(n)
3333
o = 1
3434
for s in c
3535
ls = length(s.data)
@@ -97,7 +97,7 @@ write(io::IO, s::ASCIIString) = write(io, s.data)
9797

9898
ascii(x) = convert(ASCIIString, x)
9999
convert(::Type{ASCIIString}, s::ASCIIString) = s
100-
convert(::Type{ASCIIString}, s::String) = ascii(s.data)
100+
convert(::Type{ASCIIString}, s::String) = ascii(Vector{UInt8}(s))
101101
convert(::Type{ASCIIString}, s::UTF8String) = ascii(s.data)
102102
convert(::Type{ASCIIString}, a::Vector{UInt8}) = begin
103103
isvalid(ASCIIString,a) || throw(ArgumentError("invalid ASCII sequence"))

src/support.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ isvalid(::Type{UTF8String}, s::Union{Vector{UInt8},ByteString}) = byte_string_cl
279279
bytestring() = ASCIIString("")
280280
function bytestring(s::AbstractString...)
281281
str = Base.print_to_string(s...)
282-
isvalid(ASCIIString, str.data) ? ASCIIString(str.data) : UTF8String(str.data)
282+
data = Vector{UInt8}(str)
283+
isvalid(ASCIIString, data) ? ASCIIString(data) : UTF8String(data)
283284
end
284285
bytestring(s::Vector{UInt8}) = bytestring(String(s))
285286
bytestring(p::Union{Ptr{UInt8},Ptr{Int8},Cstring}) = unsafe_string(p)

src/utf16.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,15 @@ function convert(T::Type{UTF16String}, bytes::AbstractArray{UInt8})
226226
data = reinterpret(UInt16, bytes)
227227
# check for byte-order mark (BOM):
228228
if data[1] == 0xfeff # native byte order
229-
d = Array(UInt16, length(data))
229+
d = Vector{UInt16}(length(data))
230230
copy!(d,1, data,2, length(data)-1)
231231
elseif data[1] == 0xfffe # byte-swapped
232-
d = Array(UInt16, length(data))
232+
d = Vector{UInt16}(length(data))
233233
for i = 2:length(data)
234234
d[i-1] = bswap(data[i])
235235
end
236236
else
237-
d = Array(UInt16, length(data) + 1)
237+
d = Vector{UInt16}(length(data) + 1)
238238
copy!(d,1, data,1, length(data)) # assume native byte order
239239
end
240240
d[end] = 0 # NULL terminate

src/utf32.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ convert{T<:AbstractString, S<:Union{UInt32,Char,Int32}}(::Type{T}, v::AbstractVe
135135

136136
# specialize for performance reasons:
137137
function convert{T<:ByteString, S<:Union{UInt32,Char,Int32}}(::Type{T}, data::AbstractVector{S})
138-
s = IOBuffer(Array(UInt8,length(data)), true, true)
138+
s = IOBuffer(Vector{UInt8}(length(data)), true, true)
139139
truncate(s,0)
140140
for x in data
141141
print(s, Char(x))
142142
end
143-
convert(T, takebuf_string(s))
143+
convert(T, String(take!(s)))
144144
end
145145

146146
convert(::Type{Vector{UInt32}}, str::UTF32String) = str.data
@@ -155,15 +155,15 @@ function convert(T::Type{UTF32String}, bytes::AbstractArray{UInt8})
155155
data = reinterpret(UInt32, bytes)
156156
# check for byte-order mark (BOM):
157157
if data[1] == 0x0000feff # native byte order
158-
d = Array(UInt32, length(data))
158+
d = Vector{UInt32}(length(data))
159159
copy!(d,1, data, 2, length(data)-1)
160160
elseif data[1] == 0xfffe0000 # byte-swapped
161-
d = Array(UInt32, length(data))
161+
d = Vector{UInt32}(length(data))
162162
for i = 2:length(data)
163163
@inbounds d[i-1] = bswap(data[i])
164164
end
165165
else
166-
d = Array(UInt32, length(data) + 1)
166+
d = Vector{UInt32}(length(data) + 1)
167167
copy!(d, 1, data, 1, length(data)) # assume native byte order
168168
end
169169
d[end] = 0 # NULL terminate

src/utf8.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,15 @@ function string(a::ByteString...)
150150
return a[1]::UTF8String
151151
end
152152
# ^^ at least one must be UTF-8 or the ASCII-only method would get called
153-
data = Array(UInt8,0)
153+
data = Vector{UInt8}(0)
154154
for d in a
155155
append!(data,d.data)
156156
end
157157
UTF8String(data)
158158
end
159159

160160
function string(a::Union{ByteString,Char}...)
161-
s = Array(UInt8,0)
161+
s = Vector{UInt8}(0)
162162
for d in a
163163
if isa(d,Char)
164164
c = UInt32(d::Char)
@@ -300,7 +300,7 @@ function convert(::Type{UTF8String}, a::Vector{UInt8}, invalids_as::AbstractStri
300300
endn += 1
301301
end
302302
(endn > idx) && (endn -= 1)
303-
splice!(a, idx:endn, invalids_as.data)
303+
splice!(a, idx:endn, Vector{UInt8}(invalids_as))
304304
l = length(a)
305305
end
306306
UTF8String(a)

test/runtests.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# This file includes code that was formerly a part of Julia. License is MIT: http://julialang.org/license
22

33
using Base.Test
4-
using Compat: view
4+
using Compat
5+
using Compat: view, String
56
importall LegacyStrings
67
import LegacyStrings:
78
ascii,
@@ -27,7 +28,7 @@ let io = IOBuffer()
2728
else
2829
check = "UnicodeError: invalid UTF-8 sequence starting at index 1 (0xa) missing one or more continuation bytes)"
2930
end
30-
@test takebuf_string(io) == check
31+
@test String(take!(io)) == check
3132
end
3233

3334
## Test invalid sequences
@@ -243,7 +244,7 @@ u16 = utf16(u8)
243244
@test length(u16) == 5
244245
@test utf8(u16) == u8
245246
@test collect(u8) == collect(u16)
246-
@test u8 == utf16(u16.data[1:end-1]) == utf16(copy!(Array(UInt8, 18), 1, reinterpret(UInt8, u16.data), 1, 18))
247+
@test u8 == utf16(u16.data[1:end-1]) == utf16(copy!(Vector{UInt8}(18), 1, reinterpret(UInt8, u16.data), 1, 18))
247248
@test u8 == utf16(pointer(u16)) == utf16(convert(Ptr{Int16}, pointer(u16)))
248249
@test_throws UnicodeError utf16(utf32(Char(0x120000)))
249250
@test_throws UnicodeError utf16(UInt8[1,2,3])
@@ -264,7 +265,7 @@ u32 = utf32(u8)
264265
@test length(u32) == 5
265266
@test utf8(u32) == u8
266267
@test collect(u8) == collect(u32)
267-
@test u8 == utf32(u32.data[1:end-1]) == utf32(copy!(Array(UInt8, 20), 1, reinterpret(UInt8, u32.data), 1, 20))
268+
@test u8 == utf32(u32.data[1:end-1]) == utf32(copy!(Vector{UInt8}(20), 1, reinterpret(UInt8, u32.data), 1, 20))
268269
@test u8 == utf32(pointer(u32)) == utf32(convert(Ptr{Int32}, pointer(u32)))
269270
@test_throws UnicodeError utf32(UInt8[1,2,3])
270271

0 commit comments

Comments
 (0)