Skip to content

Commit 016d84a

Browse files
authored
Merge pull request #55 from jmkuhn/writeprint
Change write() to print()
2 parents 5fb7c48 + 20c28e5 commit 016d84a

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

src/fmtcore.jl

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
### auxiliary functions
44

5-
function _repwrite(out::IO, c::Char, n::Int)
5+
### print char n times
6+
7+
function _repprint(out::IO, c::Char, n::Int)
68
while n > 0
7-
write(out, c)
9+
print(out, c)
810
n -= 1
911
end
1012
end
@@ -16,15 +18,15 @@ function _pfmt_s(out::IO, fs::FormatSpec, s::Union{AbstractString,Char})
1618
wid = fs.width
1719
slen = length(s)
1820
if wid <= slen
19-
write(out, s)
21+
print(out, s)
2022
else
2123
a = fs.align
2224
if a == '<'
23-
write(out, s)
24-
_repwrite(out, fs.fill, wid-slen)
25+
print(out, s)
26+
_repprint(out, fs.fill, wid-slen)
2527
else
26-
_repwrite(out, fs.fill, wid-slen)
27-
write(out, s)
28+
_repprint(out, fs.fill, wid-slen)
29+
print(out, s)
2830
end
2931
end
3032
end
@@ -70,19 +72,19 @@ _signchar(x::Real, s::Char) = signbit(x) ? '-' :
7072
function _pfmt_int(out::IO, sch::Char, ip::String, zs::Integer, ax::Integer, op::Op) where {Op}
7173
# print sign
7274
if sch != '\0'
73-
write(out, sch)
75+
print(out, sch)
7476
end
7577
# print prefix
7678
if !isempty(ip)
77-
write(out, ip)
79+
print(out, ip)
7880
end
7981
# print padding zeros
8082
if zs > 0
81-
_repwrite(out, '0', zs)
83+
_repprint(out, '0', zs)
8284
end
8385
# print actual digits
8486
if ax == 0
85-
write(out, '0')
87+
print(out, '0')
8688
else
8789
_pfmt_intdigits(out, ax, op)
8890
end
@@ -97,7 +99,7 @@ function _pfmt_intdigits(out::IO, ax::T, op::Op) where {Op, T<:Integer}
9799
r = ax
98100
while b > 0
99101
(q, r) = divrem(r, b)
100-
write(out, _digitchar(q, op))
102+
print(out, _digitchar(q, op))
101103
b = _div(b, op)
102104
end
103105
end
@@ -128,9 +130,9 @@ function _pfmt_i(out::IO, fs::FormatSpec, x::Integer, op::Op) where {Op}
128130
a = fs.align
129131
if a == '<'
130132
_pfmt_int(out, sch, ip, 0, ax, op)
131-
_repwrite(out, fs.fill, wid-xlen)
133+
_repprint(out, fs.fill, wid-xlen)
132134
else
133-
_repwrite(out, fs.fill, wid-xlen)
135+
_repprint(out, fs.fill, wid-xlen)
134136
_pfmt_int(out, sch, ip, 0, ax, op)
135137
end
136138
end
@@ -142,26 +144,26 @@ end
142144
function _pfmt_float(out::IO, sch::Char, zs::Integer, intv::Real, decv::Real, prec::Int)
143145
# print sign
144146
if sch != '\0'
145-
write(out, sch)
147+
print(out, sch)
146148
end
147149
# print padding zeros
148150
if zs > 0
149-
_repwrite(out, '0', zs)
151+
_repprint(out, '0', zs)
150152
end
151153
idecv = round(Integer, decv * exp10(prec))
152154
# print integer part
153155
if intv == 0
154-
write(out, '0')
156+
print(out, '0')
155157
else
156158
_pfmt_intdigits(out, intv, _Dec())
157159
end
158160
# print decimal point
159-
write(out, '.')
161+
print(out, '.')
160162
# print decimal part
161163
if prec > 0
162164
nd = _ndigits(idecv, _Dec())
163165
if nd < prec
164-
_repwrite(out, '0', prec - nd)
166+
_repprint(out, '0', prec - nd)
165167
end
166168
_pfmt_intdigits(out, idecv, _Dec())
167169
end
@@ -190,9 +192,9 @@ function _pfmt_f(out::IO, fs::FormatSpec, x::AbstractFloat)
190192
a = fs.align
191193
if a == '<'
192194
_pfmt_float(out, sch, 0, intv, decv, fs.prec)
193-
_repwrite(out, fs.fill, wid-xlen)
195+
_repprint(out, fs.fill, wid-xlen)
194196
else
195-
_repwrite(out, fs.fill, wid-xlen)
197+
_repprint(out, fs.fill, wid-xlen)
196198
_pfmt_float(out, sch, 0, intv, decv, fs.prec)
197199
end
198200
end
@@ -202,15 +204,15 @@ function _pfmt_floate(out::IO, sch::Char, zs::Integer, u::Real, prec::Int, e::In
202204
intv = trunc(Integer,u)
203205
decv = u - intv
204206
_pfmt_float(out, sch, zs, intv, decv, prec)
205-
write(out, ec)
207+
print(out, ec)
206208
if e >= 0
207-
write(out, '+')
209+
print(out, '+')
208210
else
209-
write(out, '-')
211+
print(out, '-')
210212
e = -e
211213
end
212214
if e < 10
213-
write(out, '0')
215+
print(out, '0')
214216
end
215217
_pfmt_intdigits(out, e, _Dec())
216218
end
@@ -249,9 +251,9 @@ function _pfmt_e(out::IO, fs::FormatSpec, x::AbstractFloat)
249251
a = fs.align
250252
if a == '<'
251253
_pfmt_floate(out, sch, 0, u, fs.prec, e, ec)
252-
_repwrite(out, fs.fill, wid-xlen)
254+
_repprint(out, fs.fill, wid-xlen)
253255
else
254-
_repwrite(out, fs.fill, wid-xlen)
256+
_repprint(out, fs.fill, wid-xlen)
255257
_pfmt_floate(out, sch, 0, u, fs.prec, e, ec)
256258
end
257259
end

src/formatexpr.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,21 @@ end
138138

139139
function printfmt(io::IO, fe::FormatExpr, args...)
140140
if !isempty(fe.prefix)
141-
write(io, fe.prefix)
141+
print(io, fe.prefix)
142142
end
143143
ents = fe.entries
144144
ne = length(ents)
145145
if ne > 0
146146
e = ents[1]
147147
printfmt(io, e.spec, getarg(args, e.argspec))
148148
for i = 2:ne
149-
write(io, fe.inter[i-1])
149+
print(io, fe.inter[i-1])
150150
e = ents[i]
151151
printfmt(io, e.spec, getarg(args, e.argspec))
152152
end
153153
end
154154
if !isempty(fe.suffix)
155-
write(io, fe.suffix)
155+
print(io, fe.suffix)
156156
end
157157
end
158158

0 commit comments

Comments
 (0)