82
82
const BUFSIZE = 100
83
83
84
84
type StringEncoder{F<: Encoding , T<: Encoding , S<: IO } <: IO
85
- ostream :: S
85
+ stream :: S
86
86
closestream:: Bool
87
87
cd:: Ptr{Void}
88
88
inbuf:: Vector{UInt8}
@@ -94,7 +94,7 @@ type StringEncoder{F<:Encoding, T<:Encoding, S<:IO} <: IO
94
94
end
95
95
96
96
type StringDecoder{F<: Encoding , T<: Encoding , S<: IO } <: IO
97
- istream :: S
97
+ stream :: S
98
98
closestream:: Bool
99
99
cd:: Ptr{Void}
100
100
inbuf:: Vector{UInt8}
@@ -178,35 +178,35 @@ end
178
178
# # StringEncoder
179
179
180
180
"""
181
- StringEncoder(istream , to, from=enc"UTF-8")
181
+ StringEncoder(stream , to, from=enc"UTF-8")
182
182
183
183
Returns a new write-only I/O stream, which converts any text in the encoding `from`
184
- written to it into text in the encoding `to` written to `ostream `. Calling `close` on the
185
- stream is necessary to complete the encoding (but does not close `ostream `).
184
+ written to it into text in the encoding `to` written to `stream `. Calling `close` on the
185
+ stream is necessary to complete the encoding (but does not close `stream `).
186
186
187
187
`to` and `from` can be specified either as a string or as an `Encoding` object.
188
188
"""
189
- function StringEncoder (ostream :: IO , to:: Encoding , from:: Encoding = enc " UTF-8" )
189
+ function StringEncoder (stream :: IO , to:: Encoding , from:: Encoding = enc " UTF-8" )
190
190
cd = iconv_open (ASCIIString (to), ASCIIString (from))
191
191
inbuf = Vector {UInt8} (BUFSIZE)
192
192
outbuf = Vector {UInt8} (BUFSIZE)
193
- s = StringEncoder {typeof(from), typeof(to), typeof(ostream )} (ostream , false ,
193
+ s = StringEncoder {typeof(from), typeof(to), typeof(stream )} (stream , false ,
194
194
cd, inbuf, outbuf,
195
195
Ref {Ptr{UInt8}} (pointer (inbuf)), Ref {Ptr{UInt8}} (pointer (outbuf)),
196
196
Ref {Csize_t} (0 ), Ref {Csize_t} (BUFSIZE))
197
197
finalizer (s, finalize)
198
198
s
199
199
end
200
200
201
- StringEncoder (ostream :: IO , to:: AbstractString , from:: Encoding = enc " UTF-8" ) =
202
- StringEncoder (ostream , Encoding (to), from)
203
- StringEncoder (ostream :: IO , to:: AbstractString , from:: AbstractString ) =
204
- StringEncoder (ostream , Encoding (to), Encoding (from))
201
+ StringEncoder (stream :: IO , to:: AbstractString , from:: Encoding = enc " UTF-8" ) =
202
+ StringEncoder (stream , Encoding (to), from)
203
+ StringEncoder (stream :: IO , to:: AbstractString , from:: AbstractString ) =
204
+ StringEncoder (stream , Encoding (to), Encoding (from))
205
205
206
206
function show {F, T, S} (io:: IO , s:: StringEncoder{F, T, S} )
207
207
from = F ()
208
208
to = T ()
209
- print (io, " StringEncoder{$from , $to }($(s. ostream ) )" )
209
+ print (io, " StringEncoder{$from , $to }($(s. stream ) )" )
210
210
end
211
211
212
212
# Flush input buffer and convert it into output buffer
@@ -220,7 +220,7 @@ function flush(s::StringEncoder)
220
220
s. outbytesleft[] = 0
221
221
while s. outbytesleft[] < BUFSIZE
222
222
iconv! (s. cd, s. inbuf, s. outbuf, s. inbufptr, s. outbufptr, s. inbytesleft, s. outbytesleft)
223
- write (s. ostream , sub (s. outbuf, 1 : (BUFSIZE - Int (s. outbytesleft[]))))
223
+ write (s. stream , sub (s. outbuf, 1 : (BUFSIZE - Int (s. outbytesleft[]))))
224
224
end
225
225
226
226
s
@@ -232,7 +232,7 @@ function close(s::StringEncoder)
232
232
# Make sure C memory/resources are returned
233
233
finalize (s)
234
234
if s. closestream
235
- close (s. ostream )
235
+ close (s. stream )
236
236
end
237
237
# flush() wasn't able to empty input buffer, which cannot happen with correct data
238
238
s. inbytesleft[] == 0 || throw (IncompleteSequenceError ())
@@ -248,38 +248,38 @@ end
248
248
# # StringDecoder
249
249
250
250
"""
251
- StringDecoder(istream , from, to=enc"UTF-8")
251
+ StringDecoder(stream , from, to=enc"UTF-8")
252
252
253
253
Returns a new read-only I/O stream, which converts text in the encoding `from`
254
- read from `istream ` into text in the encoding `to`. Calling `close` on the
255
- stream does not close `ostream `.
254
+ read from `stream ` into text in the encoding `to`. Calling `close` on the
255
+ stream does not close `stream `.
256
256
257
257
`to` and `from` can be specified either as a string or as an `Encoding` object.
258
258
259
259
Note that some implementations (notably the Windows one) may accept invalid sequences
260
260
in the input data without raising an error.
261
261
"""
262
- function StringDecoder (istream :: IO , from:: Encoding , to:: Encoding = enc " UTF-8" )
262
+ function StringDecoder (stream :: IO , from:: Encoding , to:: Encoding = enc " UTF-8" )
263
263
cd = iconv_open (ASCIIString (to), ASCIIString (from))
264
264
inbuf = Vector {UInt8} (BUFSIZE)
265
265
outbuf = Vector {UInt8} (BUFSIZE)
266
- s = StringDecoder {typeof(from), typeof(to), typeof(istream )} (istream , false ,
266
+ s = StringDecoder {typeof(from), typeof(to), typeof(stream )} (stream , false ,
267
267
cd, inbuf, outbuf,
268
268
Ref {Ptr{UInt8}} (pointer (inbuf)), Ref {Ptr{UInt8}} (pointer (outbuf)),
269
269
Ref {Csize_t} (0 ), Ref {Csize_t} (BUFSIZE), 0 )
270
270
finalizer (s, finalize)
271
271
s
272
272
end
273
273
274
- StringDecoder (istream :: IO , from:: AbstractString , to:: Encoding = enc " UTF-8" ) =
275
- StringDecoder (istream , Encoding (from), to)
276
- StringDecoder (istream :: IO , from:: AbstractString , to:: AbstractString ) =
277
- StringDecoder (istream , Encoding (from), Encoding (to))
274
+ StringDecoder (stream :: IO , from:: AbstractString , to:: Encoding = enc " UTF-8" ) =
275
+ StringDecoder (stream , Encoding (from), to)
276
+ StringDecoder (stream :: IO , from:: AbstractString , to:: AbstractString ) =
277
+ StringDecoder (stream , Encoding (from), Encoding (to))
278
278
279
279
function show {F, T, S} (io:: IO , s:: StringDecoder{F, T, S} )
280
280
from = F ()
281
281
to = T ()
282
- print (io, " StringDecoder{$from , $to }($(s. istream ) )" )
282
+ print (io, " StringDecoder{$from , $to }($(s. stream ) )" )
283
283
end
284
284
285
285
# Fill input buffer and convert it into output buffer
@@ -290,12 +290,12 @@ function fill_buffer!(s::StringDecoder)
290
290
s. skip = 0
291
291
292
292
# Input buffer and input stream empty
293
- if s. inbytesleft[] == 0 && eof (s. istream )
293
+ if s. inbytesleft[] == 0 && eof (s. stream )
294
294
i = iconv_reset! (s)
295
295
return i
296
296
end
297
297
298
- s. inbytesleft[] += readbytes! (s. istream , sub (s. inbuf, Int (s. inbytesleft[]+ 1 ): BUFSIZE))
298
+ s. inbytesleft[] += readbytes! (s. stream , sub (s. inbuf, Int (s. inbytesleft[]+ 1 ): BUFSIZE))
299
299
iconv! (s. cd, s. inbuf, s. outbuf, s. inbufptr, s. outbufptr, s. inbytesleft, s. outbytesleft)
300
300
end
301
301
@@ -315,7 +315,7 @@ function close(s::StringDecoder)
315
315
# Make sure C memory/resources are returned
316
316
finalize (s)
317
317
if s. closestream
318
- close (s. istream )
318
+ close (s. stream )
319
319
end
320
320
# iconv_reset!() wasn't able to empty input buffer, which cannot happen with correct data
321
321
s. inbytesleft[] == 0 || throw (IncompleteSequenceError ())
@@ -325,11 +325,11 @@ function read(s::StringDecoder, ::Type{UInt8})
325
325
eof (s) ? throw (EOFError ()) : s. outbuf[s. skip+= 1 ]
326
326
end
327
327
328
- isreadable (s:: StringDecoder ) = isreadable (s. istream )
328
+ isreadable (s:: StringDecoder ) = isreadable (s. stream )
329
329
iswritable (s:: StringDecoder ) = false
330
330
331
331
isreadable (s:: StringEncoder ) = false
332
- iswritable (s:: StringEncoder ) = iswritable (s. ostream )
332
+ iswritable (s:: StringEncoder ) = iswritable (s. stream )
333
333
334
334
335
335
# # Convenience I/O functions
0 commit comments