COVERAGE SUMMARY
FILE SUMMARY
NameExecutedRoutines%ExecutedLines%Unexecuted
/home/matt/eu/rds/include/std/pretty.e88100.00%11413087.69%16
ROUTINE SUMMARY
RoutineExecutedLinesUnexecuted
rPrint()435184.31%8
esc_char()4850.00%4
pretty_out()71070.00%3
indent()101190.91%1
cut_line()88100.00%0
pretty()2020100.00%0
pretty_print()66100.00%0
pretty_sprint()44100.00%0
LINE COVERAGE DETAIL
#Executed
1
namespace pretty
2
3
--****
4
-- == Pretty Printing
5
--
6
-- <>
7
--
8
9
-- pretty print variables
10
integer pretty_end_col, pretty_chars, pretty_start_col, pretty_level,
11
pretty_file, pretty_ascii, pretty_indent, pretty_ascii_min,
12
pretty_ascii_max, pretty_line_count, pretty_line_max, pretty_dots,
13
pretty_line_breaks, pretty_printing
14
sequence pretty_fp_format, pretty_int_format, pretty_line
15
167486
17
-- Output text, keeping track of line length.
18
-- Buffering lines speeds up Windows console output.
197486
pretty_line &= text
207486
if equal(text, '\n') and pretty_printing then
210
puts(pretty_file, pretty_line)
220
pretty_line = ""
230
pretty_line_count += 1
24
end if
257486
if atom(text) then
264288
pretty_chars += 1
27
else
283198
pretty_chars += length(text)
29
end if
307486
end procedure
31
323084
33
-- check for time to do line break
343084
if not pretty_line_breaks then
3532
pretty_chars = 0
3632
return
37
end if
383052
if pretty_chars + n > pretty_end_col then
39160
pretty_out('\n')
40160
pretty_chars = 0
41
end if
423052
end procedure
43
44453
45
-- indent the display of a sequence
46453
if pretty_line_breaks = 0 then
4713
pretty_chars = 0
4813
return
49440
elsif pretty_line_breaks = -1 then
50
510
cut_line( 0 )
52
53
else
54440
if pretty_chars > 0 then
55430
pretty_out('\n')
56430
pretty_chars = 0
57
end if
58440
pretty_out(repeat(' ', (pretty_start_col-1) +
59
pretty_level * pretty_indent))
60
end if
61
62440
end procedure
63
64233
65
-- show escaped characters
66233
switch a do
67
case'\t' then
680
return `\t`
69
70
case'\n' then
710
return `\n`
72
73
case'\r' then
740
return `\r`
75
76
case'\\' then
772
return `\\`
78
79
case'"' then
800
return `\"`
81
82
case else
83231
return a
84
end switch
85
end function
86
873139
88
-- recursively print a Euphoria object
89
sequence sbuff
90
integer multi_line, all_ascii
91
923139
if atom(a) then
932756
if integer(a) then
942721
sbuff = sprintf(pretty_int_format, a)
952721
if pretty_ascii then
962721
if pretty_ascii >= 3 then
97
-- replace number with display character?
980
if (a >= pretty_ascii_min and a <= pretty_ascii_max) then
990
sbuff = '\'' & a & '\'' -- display char only
100
1010
elsif find(a, "\t\n\r\\") then
1020
sbuff = '\'' & esc_char(a) & '\'' -- display char only
103
104
end if
105
else -- pretty ascii 1 or 2
106
-- add display character to number?
1072721
if (a >= pretty_ascii_min and a <= pretty_ascii_max) and pretty_ascii < 2 then
1082680
sbuff &= '\'' & a & '\'' -- add to numeric display
109
end if
110
end if
111
end if
112
else
11335
sbuff = sprintf(pretty_fp_format, a)
114
end if
1152756
pretty_out(sbuff)
116
117
else
118
-- sequence
119383
cut_line(1)
120383
multi_line = 0
121383
all_ascii = pretty_ascii > 1
122383
for i = 1 to length(a) do
1233062
if sequence(a[i]) and length(a[i]) > 0 then
124114
multi_line = 1
125114
all_ascii = 0
126114
exit
127
end if
1282948
if not integer(a[i]) or
129
(a[i] < pretty_ascii_min and
130
(pretty_ascii < 2 or not find(a[i], "\t\r\n\\"))) or
131
a[i] > pretty_ascii_max then
13232
all_ascii = 0
133
end if
1342948
end for
135
136383
if all_ascii then
13732
pretty_out('\"')
138
else
139351
pretty_out('{')
140
end if
141383
pretty_level += 1
142383
for i = 1 to length(a) do
1433285
if multi_line then
144339
indent()
145
end if
1463285
if all_ascii then
147233
pretty_out(esc_char(a[i]))
148
else
1493052
rPrint(a[i])
150
end if
1513285
if pretty_line_count >= pretty_line_max then
1520
if not pretty_dots then
1530
pretty_out(" ...")
154
end if
1550
pretty_dots = 1
1560
return
157
end if
1583285
if i != length(a) and not all_ascii then
1592701
pretty_out(',')
1602701
cut_line(6)
161
end if
1623285
end for
163383
pretty_level -= 1
164383
if multi_line then
165114
indent()
166
end if
167383
if all_ascii then
16832
pretty_out('\"')
169
else
170351
pretty_out('}')
171
end if
172
end if
1733139
end procedure
174
175101
ifdef UNIX then
176101
public constant PRETTY_DEFAULT = {1, 2, 1, 78, "%d", "%.10g", 32, 126, 1000000000, 1}
177
elsedef
178
public constant PRETTY_DEFAULT = {1, 2, 1, 78, "%d", "%.10g", 32, 127, 1000000000, 1}
179
end ifdef
180
181
public enum
182101
DISPLAY_ASCII = 1,
183101
INDENT,
184101
START_COLUMN,
185101
WRAP,
186101
INT_FORMAT,
187101
FP_FORMAT,
188101
MIN_ASCII,
189101
MAX_ASCII,
190101
MAX_LINES,
191101
LINE_BREAKS
192
193
--****
194
-- === Routines
195
19687
19787
if length(options) < length( PRETTY_DEFAULT ) then
19852
options &= PRETTY_DEFAULT[length(options)+1..$]
199
end if
200
201
-- set options
20287
pretty_ascii = options[DISPLAY_ASCII]
20387
pretty_indent = options[INDENT]
20487
pretty_start_col = options[START_COLUMN]
20587
pretty_end_col = options[WRAP]
20687
pretty_int_format = options[INT_FORMAT]
20787
pretty_fp_format = options[FP_FORMAT]
20887
pretty_ascii_min = options[MIN_ASCII]
20987
pretty_ascii_max = options[MAX_ASCII]
21087
pretty_line_max = options[MAX_LINES]
21187
pretty_line_breaks = options[LINE_BREAKS]
212
21387
pretty_chars = pretty_start_col
214
21587
pretty_level = 0
21687
pretty_line = ""
21787
pretty_line_count = 0
21887
pretty_dots = 0
21987
rPrint(x)
22087
end procedure
221
222
--**
223
-- Print an object to a file or device, using braces { , , , }, indentation, and multiple lines
224
-- to show the structure.
225
--
226
-- Parameters:
227
-- # ##fn## : an integer, the file/device number to write to
228
-- # ##x## : the object to display/convert to printable form
229
-- # ##options## : is an (up to) 10-element options sequence.
230
--
231
-- Comments:
232
--
233
-- Pass {} in ##options## to select the defaults, or set options as below:
234
-- # display ASCII characters:
235
-- ** 0 ~-- never
236
-- ** 1 ~-- alongside any integers in printable ASCII range (default)
237
-- ** 2 ~-- display as "string" when all integers of a sequence
238
-- are in ASCII range
239
-- ** 3 ~-- show strings, and quoted characters (only) for any integers
240
-- in ASCII range as well as the characters: \t \r \n
241
-- # amount to indent for each level of sequence nesting ~-- default: 2
242
-- # column we are starting at ~-- default: 1
243
-- # approximate column to wrap at ~-- default: 78
244
-- # format to use for integers ~-- default: "%d"
245
-- # format to use for floating-point numbers ~-- default: "%.10g"
246
-- # minimum value for printable ASCII ~-- default 32
247
-- # maximum value for printable ASCII ~-- default 127
248
-- # maximum number of lines to output
249
-- # line breaks between elements ~-- default 1 (0 = no line breaks, -1 = line breaks to wrap only)
250
--
251
-- If the length is less than 10, unspecified options at
252
-- the end of the sequence will keep the default values.
253
-- e.g. {0, 5} will choose "never display ASCII",
254
-- plus 5-character indentation, with defaults for everything else.
255
--
256
-- The default options can be applied using the public constant ##PRETTY_DEFAULT##, and the
257
-- elements may be accessed using the following public enum~:
258
--
259
-- # ##DISPLAY_ASCII##
260
-- # ##INDENT##
261
-- # ##START_COLUMN##
262
-- # ##WRAP##
263
-- # ##INT_FORMAT##
264
-- # ##FP_FORMAT##
265
-- # ##MIN_ASCII##
266
-- # ##MAX_ASCII##
267
-- # ##MAX_LINES##
268
-- # ##LINE_BREAKS##
269
--
270
-- The display will start at the current cursor position. Normally you will want to call
271
-- ##pretty_print##() when the cursor is in column 1 (after printing a \n character).
272
-- If you want to start in a different column, you should call ##position##() and specify a value
273
-- for option [3]. This will ensure that the first and last braces in a sequence line up
274
-- vertically.
275
--
276
-- When specifying the format to use for integers and floating-point numbers, you can add
277
-- some decoration, e.g. "(%d)" or "$ %.2f"
278
--
279
-- Example 1:
280
--
281
-- pretty_print(1, "ABC", {})
282
--
283
-- {65'A',66'B',67'C'}
284
--
285
--
286
-- Example 2:
287
--
288
-- pretty_print(1, {{1,2,3}, {4,5,6}}, {})
289
--
290
-- {
291
-- {1,2,3},
292
-- {4,5,6}
293
-- }
294
--
295
--
296
-- Example 3:
297
--
298
-- pretty_print(1, {"Euphoria", "Programming", "Language"}, {2})
299
--
300
-- {
301
-- "Euphoria",
302
-- "Programming",
303
-- "Language"
304
-- }
305
--
306
--
307
-- Example 4:
308
--
309
-- puts(1, "word_list = ") -- moves cursor to column 13
310
-- pretty_print(1,
311
-- {{"Euphoria", 8, 5.3},
312
-- {"Programming", 11, -2.9},
313
-- {"Language", 8, 9.8}},
314
-- {2, 4, 13, 78, "%03d", "%.3f"}) -- first 6 of 8 options
315
--
316
-- word_list = {
317
-- {
318
-- "Euphoria",
319
-- 008,
320
-- 5.300
321
-- },
322
-- {
323
-- "Programming",
324
-- 011,
325
-- -2.900
326
-- },
327
-- {
328
-- "Language",
329
-- 008,
330
-- 9.800
331
-- }
332
-- }
333
--
334
--
335
-- See Also:
336
-- [[:print]], [[:sprint]], [[:printf]], [[:sprintf]], [[:pretty_sprint]]
337
--
33816
33916
pretty_printing = 1
34016
pretty_file = fn
34116
pretty( x, options )
34216
puts(pretty_file, pretty_line)
34316
end procedure
344
345
--**
346
-- Format an object using braces { , , , }, indentation, and multiple lines to show the structure.
347
--
348
-- Parameters:
349
-- # ##x## : the object to display
350
-- # ##options## : is an (up to) 10-element options sequence: Pass {} to select the defaults, or
351
-- set options
352
--
353
-- Returns:
354
-- A **sequence**, of printable characters, representing ##x## in an human-readable form.
355
--
356
-- Comments:
357
--
358
-- This function formats objects the same as [[:pretty_print]](), but returns the sequence obtained instead of sending it to some file..
359
--
360
-- See Also:
361
-- [[:pretty_print]], [[:sprint]]
362
36371
36471
pretty_printing = 0
36571
pretty( x, options )
36671
return pretty_line
367
end function