Skip to content

Commit 6ae7c18

Browse files
committed
Use Compat.jl for readstring() and read()
1 parent a2b684c commit 6ae7c18

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
julia 0.4
22
BinDeps
3+
Compat
34
@windows WinRPM

src/StringEncodings.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module StringEncodings
44
import Base: close, eof, flush, read, readall, write, show
55
import Base.Libc: errno, strerror, E2BIG, EINVAL, EILSEQ
6+
import Compat: read
67

78
export StringEncoder, StringDecoder, encode, decode, encodings
89
export StringEncodingError, OutputBufferError, IConvError
@@ -337,7 +338,7 @@ in the input data without raising an error.
337338
function decode{T<:AbstractString}(::Type{T}, a::Vector{UInt8}, enc::Encoding)
338339
b = IOBuffer(a)
339340
try
340-
T(readbytes(StringDecoder(b, enc, encoding(T))))
341+
T(read(StringDecoder(b, enc, encoding(T))))
341342
finally
342343
close(b)
343344
end

test/runtests.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Base.Test
2+
import Compat: readstring
23
using StringEncodings
34

45
for s in ("", "\0", "a", "café crème",
@@ -46,7 +47,7 @@ let s = "a string チャネルパートナーの選択"
4647
end
4748

4849
p = StringDecoder(IOBuffer(encode(s, "UTF-16LE")[1:19]), "UTF-16LE")
49-
@test readall(p) == s[1:9]
50+
@test readstring(p) == s[1:9]
5051
@test_throws IncompleteSequenceError close(p)
5152

5253
# Test stateful encoding, which output some bytes on final reset
@@ -102,7 +103,7 @@ mktemp() do p, io
102103
s = "café crème"
103104
write(io, encode(s, "CP1252"))
104105
close(io)
105-
@test readall(p, enc"CP1252") == s
106+
@test readstring(p, enc"CP1252") == s
106107
end
107108

108109
@test_throws InvalidEncodingError p = StringEncoder(IOBuffer(), "nonexistent_encoding")
@@ -127,10 +128,6 @@ catch err
127128
"Conversion from nonexistent_encoding to UTF-8 not supported by iconv implementation, check that specified encodings are correct"
128129
end
129130

130-
if !isdefined(Base, :readstring)
131-
readstring = readall
132-
end
133-
134131
mktemp() do path, io
135132
s = "a string \0チャネルパ\0\0トナーの選択 with embedded and trailing nuls\0"
136133
write(io, encode(s, "ISO-2022-JP"))

0 commit comments

Comments
 (0)