~ubuntu-branches/ubuntu/wily/julia/wily

« back to all changes in this revision

Viewing changes to base/iostring.jl

  • Committer: Package Import Robot
  • Author(s): Sébastien Villemot
  • Date: 2013-02-06 17:54:29 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20130206175429-13br5kqpkfjqdmre
Tags: 0.0.0+20130206.git32ff5759-1
* New upstream snapshot.
* debian/copyright: reflect upstream changes
* debian/rules: update get-orig-source to reflect upstream changes
   + Don't ship nginx
   + Adapt for new configure-random target in deps/Makefile
* Enable build of Tk wrapper.
   + debian/control: add build dependency on tk-dev
   + debian/rules: add tk rule to build-arch
* debian/julia.install: install VERSION and COMMIT files
* no-webrepl.patch: new patch
* Refresh other patches
* Add source override for config.status file under deps/random/

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
function read{T}(from::IOString, a::Array{T})
36
36
    if !from.readable error("read failed") end
37
37
    if isa(T, BitsKind)
38
 
        nb = numel(a)*sizeof(T)
 
38
        nb = length(a)*sizeof(T)
39
39
        if nb > nb_available(from)
40
40
            throw(EOFError())
41
41
        end
59
59
 
60
60
read{T}(from::IOString, ::Type{Ptr{T}}) = convert(Ptr{T}, read(from, Uint))
61
61
 
62
 
length(io::IOString) = (io.seekable ? io.size : nb_available(io))
 
62
# TODO: IOString is not iterable, so doesn't really have a length.
 
63
# This should maybe be sizeof() instead.
 
64
#length(io::IOString) = (io.seekable ? io.size : nb_available(io))
63
65
nb_available(io::IOString) = io.size - io.ptr + 1
64
66
skip(io::IOString, n::Integer) = (io.ptr = min(io.ptr + n, io.size+1))
65
67
function seek(io::IOString, n::Integer) 
78
80
    if n > io.maxsize || n < 0 error("truncate failed") end
79
81
    nadd = n - length(io.data)
80
82
    if nadd > 0
81
 
        grow(io.data, nadd)
 
83
        grow!(io.data, nadd)
82
84
    end
83
85
    io.data[io.size+1:end] = 0
84
86
    io.size = n
111
113
    n = min(nshort + (io.append ? io.size : io.ptr-1), io.maxsize)
112
114
    ngrow = n - length(io.data)
113
115
    if ngrow > 0
114
 
        grow(io.data, ngrow)
 
116
        grow!(io.data, ngrow)
115
117
    end
116
118
    return io
117
119
end
118
120
eof(io::IOString) = (io.ptr-1 == io.size)
119
121
function close(io::IOString)
120
122
    if io.writable
121
 
        grow(io.data, -length(io.data))
 
123
        grow!(io.data, -length(io.data))
122
124
    else
123
125
        io.data = Uint8[]
124
126
    end
144
146
        else
145
147
            data = copy(data)
146
148
        end
 
149
        grow!(data,io.size-length(data))
147
150
    else
148
151
        nbytes = nb_available(io)
149
152
        a = Array(Uint8, nbytes)
157
160
end
158
161
takebuf_string(io::IOString) = bytestring(takebuf_array(io))
159
162
 
160
 
function write{T}(to::IOString, a::Array{T})
161
 
    if !to.writable error("write failed") end
 
163
function write_sub{T}(to::IOString, a::Array{T}, offs, nel)
 
164
    if !to.writable; error("write failed") end
 
165
    if offs+nel-1 > length(a) || offs < 1 || nel < 0
 
166
        throw(BoundsError())
 
167
    end
162
168
    if isa(T, BitsKind)
163
 
        nb = numel(a)*sizeof(T)
 
169
        nb = nel*sizeof(T)
164
170
        ensureroom(to, nb)
165
171
        ptr = (to.append ? to.size+1 : to.ptr)
166
172
        nb = min(nb, length(to.data) - ptr + 1)
167
 
        ccall(:memcpy, Void, (Ptr{Void}, Ptr{Void}, Int), pointer(to.data,ptr), a, nb)
 
173
        ccall(:memcpy, Void, (Ptr{Void}, Ptr{Void}, Int), pointer(to.data,ptr), pointer(a,offs), nb)
168
174
        to.size = max(to.size, ptr - 1 + nb)
169
175
        if !to.append; to.ptr += nb; end
170
176
    else
173
179
    nb
174
180
end
175
181
 
 
182
write(to::IOString, a::Array) = write_sub(to, a, 1, length(a))
 
183
 
176
184
function write(to::IOString, a::Uint8)
177
185
    if !to.writable error("write failed") end
178
186
    ensureroom(to, 1)
191
199
 
192
200
readbytes(io::IOString,nb::Integer) = bytestring(read(io, Array(Uint8, nb)))
193
201
readall(io::IOString) = readbytes(io,nb_available(io))
194
 
function memchr(buf::IOString, delim)
 
202
function search(buf::IOString, delim)
195
203
    p = pointer(buf.data, buf.ptr)
196
204
    q = ccall(:memchr,Ptr{Uint8},(Ptr{Uint8},Int32,Int32),p,delim,nb_available(buf))
197
205
    nb = (q == C_NULL ? 0 : q-p+1)
198
206
end
199
207
function readuntil(io::IOString, delim::Uint8)
200
 
    nb = memchr(io, delim)
 
208
    nb = search(io, delim)
201
209
    if nb == 0
202
210
        nb = nb_available(io)
203
211
    end