Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
517839aa
Commit
517839aa
authored
Oct 08, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- debugging support
R=rsc DELTA=110 (98 added, 0 deleted, 12 changed) OCL=35487 CL=35490
parent
094f1d59
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
12 deletions
+110
-12
src/pkg/tabwriter/tabwriter.go
src/pkg/tabwriter/tabwriter.go
+29
-12
src/pkg/tabwriter/tabwriter_test.go
src/pkg/tabwriter/tabwriter_test.go
+81
-0
No files found.
src/pkg/tabwriter/tabwriter.go
View file @
517839aa
...
...
@@ -21,7 +21,7 @@ import (
// ----------------------------------------------------------------------------
// Filter implementation
// A cell represents a segment of text delineated by tabs, form
-
feed,
// A cell represents a segment of text delineated by tabs, formfeed,
// or newline chars. The text itself is stored in a separate buffer;
// cell only describes the segment's size in bytes, its width in runes,
// and whether it's an htab ('\t') or vtab ('\v') terminated call.
...
...
@@ -59,10 +59,10 @@ type cell struct {
// are simply passed through. The widths of tags and entities are
// assumed to be zero (tags) and one (entities) for formatting purposes.
//
// The form
feed character ('\f') acts like a newline but it also
// The formfeed character ('\f') acts like a newline but it also
// terminates all columns in the current line (effectively calling
// Flush). Cells in the next line start new columns. Unless found
// inside an HTML tag, form
feed characters appear as newlines in
// inside an HTML tag, formfeed characters appear as newlines in
// the output.
//
// The Writer must buffer input internally, because proper spacing
...
...
@@ -78,7 +78,7 @@ type Writer struct {
flags
uint
;
// current state
buf
bytes
.
Buffer
;
// collected text w/o tabs, newlines, or form
feed chars
buf
bytes
.
Buffer
;
// collected text w/o tabs, newlines, or formfeed chars
pos
int
;
// buffer position up to which width of incomplete cell has been computed
cell
cell
;
// current incomplete cell; cell.width is up to buf[pos] w/o ignored sections
html_char
byte
;
// terminating char of html tag/entity, or 0 ('>', ';', or 0)
...
...
@@ -111,9 +111,9 @@ func (b *Writer) reset() {
// Internal representation (current state):
//
// - all text written is appended to buf; form
feed chars, tabs and newlines are stripped away
// - all text written is appended to buf; formfeed chars, tabs and newlines are stripped away
// - at any given time there is a (possibly empty) incomplete cell at the end
// (the cell starts after a tab, form
feed, or newline)
// (the cell starts after a tab, formfeed, or newline)
// - cell.size is the number of bytes belonging to the cell so far
// - cell.width is text width in runes of that cell from the start of the cell to
// position pos; html tags and entities are excluded from this width if html
...
...
@@ -146,6 +146,10 @@ const (
// Handle empty columns as if they were not present in
// the input in the first place.
DiscardEmptyColumns
;
// Print a vertical bar ('|') between columns (after formatting).
// Discarded colums appear as zero-width columns ("||").
Debug
;
)
...
...
@@ -153,15 +157,21 @@ const (
// specifies the filter output. The remaining parameters control the formatting:
//
// cellwidth minimal cell width
// padding
additional cell padding
// padding
cell padding added to cell before computing its width
// padchar ASCII char used for padding
//
if padchar == '\t', the Writer will assume that the
//
width of a '\t' in the formatted output is cellwidth,
//
and cells are left-aligned independent of align_left
//
(for correct-looking results, cellwidth must correspond
//
to the tab width in the viewer displaying the result)
// if padchar == '\t', the Writer will assume that the
// width of a '\t' in the formatted output is cellwidth,
// and cells are left-aligned independent of align_left
// (for correct-looking results, cellwidth must correspond
// to the tab width in the viewer displaying the result)
// flags formatting control
//
// To format in tab-separated columns with a tab stop of 8:
// b.Init(w, 8, 1, '\t', 0);
//
// To format in space-separated columns with at least 4 spaces between columns:
// b.Init(w, 1, 4, ' ', 0);
//
func
(
b
*
Writer
)
Init
(
output
io
.
Writer
,
cellwidth
,
padding
int
,
padchar
byte
,
flags
uint
)
*
Writer
{
if
cellwidth
<
0
{
panic
(
"negative cellwidth"
);
...
...
@@ -243,6 +253,8 @@ func (b *Writer) writePadding(textw, cellw int) os.Error {
}
var
vbar
=
[]
byte
{
'|'
};
func
(
b
*
Writer
)
writeLines
(
pos0
int
,
line0
,
line1
int
)
(
pos
int
,
err
os
.
Error
)
{
pos
=
pos0
;
for
i
:=
line0
;
i
<
line1
;
i
++
{
...
...
@@ -250,6 +262,11 @@ func (b *Writer) writeLines(pos0 int, line0, line1 int) (pos int, err os.Error)
for
j
:=
0
;
j
<
line
.
Len
();
j
++
{
c
:=
line
.
At
(
j
)
.
(
cell
);
if
j
>
0
&&
b
.
flags
&
Debug
!=
0
{
if
err
=
b
.
write0
(
vbar
);
err
!=
nil
{
return
;
}
}
switch
{
default
:
// align left
...
...
src/pkg/tabwriter/tabwriter_test.go
View file @
517839aa
...
...
@@ -119,6 +119,13 @@ var tests = []entry {
""
},
entry
{
"1 debug"
,
8
,
1
,
'.'
,
Debug
,
""
,
""
},
entry
{
"2"
,
8
,
1
,
'.'
,
0
,
...
...
@@ -168,6 +175,13 @@ var tests = []entry {
"*.......*"
},
entry
{
"5c debug"
,
8
,
1
,
'.'
,
Debug
,
"*
\t
*
\t
"
,
"*.......|*"
},
entry
{
"5d"
,
8
,
1
,
'.'
,
AlignRight
,
...
...
@@ -231,6 +245,13 @@ var tests = []entry {
"g) f<o..<b>bar</b>..... non-terminated entity &"
},
entry
{
"7g debug"
,
8
,
1
,
'.'
,
FilterHTML
|
Debug
,
"g) f<o
\t
<b>bar</b>
\t
non-terminated entity &"
,
"g) f<o..|<b>bar</b>.....| non-terminated entity &"
},
entry
{
"8"
,
8
,
1
,
'*'
,
0
,
...
...
@@ -268,6 +289,16 @@ var tests = []entry {
"11222333344444
\n
"
},
entry
{
"9c debug"
,
0
,
0
,
'.'
,
Debug
,
"1
\t
2
\t
3
\t
4
\f
"
// \f causes a newline and flush
"11
\t
222
\t
3333
\t
44444
\n
"
,
"1|2|3|4
\n
"
"11|222|3333|44444
\n
"
},
entry
{
"10a"
,
5
,
0
,
'.'
,
0
,
...
...
@@ -408,6 +439,24 @@ var tests = []entry {
" .0 1.2 44.4 -13.3"
},
entry
{
"14 debug"
,
0
,
2
,
' '
,
AlignRight
|
Debug
,
".0
\t
.3
\t
2.4
\t
-5.1
\t\n
"
"23.0
\t
12345678.9
\t
2.4
\t
-989.4
\t\n
"
"5.1
\t
12.0
\t
2.4
\t
-7.0
\t\n
"
".0
\t
0.0
\t
332.0
\t
8908.0
\t\n
"
".0
\t
-.3
\t
456.4
\t
22.1
\t\n
"
".0
\t
1.2
\t
44.4
\t
-13.3
\t\t
"
,
" .0| .3| 2.4| -5.1|
\n
"
" 23.0| 12345678.9| 2.4| -989.4|
\n
"
" 5.1| 12.0| 2.4| -7.0|
\n
"
" .0| 0.0| 332.0| 8908.0|
\n
"
" .0| -.3| 456.4| 22.1|
\n
"
" .0| 1.2| 44.4| -13.3|"
},
entry
{
"15a"
,
4
,
0
,
'.'
,
0
,
...
...
@@ -468,6 +517,22 @@ var tests = []entry {
"a
\t
b
\t
c
\t
d
\t
e
\n
"
},
entry
{
"16b debug"
,
100
,
0
,
'\t'
,
DiscardEmptyColumns
|
Debug
,
"a
\v
b
\v\v
d
\n
"
"a
\v
b
\v\v
d
\v
e
\n
"
"a
\n
"
"a
\v
b
\v
c
\v
d
\n
"
"a
\v
b
\v
c
\v
d
\v
e
\n
"
,
"a
\t
|b
\t
||d
\n
"
"a
\t
|b
\t
||d
\t
|e
\n
"
"a
\n
"
"a
\t
|b
\t
|c
\t
|d
\n
"
"a
\t
|b
\t
|c
\t
|d
\t
|e
\n
"
},
entry
{
"16c"
,
100
,
0
,
'\t'
,
DiscardEmptyColumns
,
...
...
@@ -483,6 +548,22 @@ var tests = []entry {
"a
\t
b
\t
c
\t
d
\n
"
"a
\t
b
\t
c
\t
d
\t
e
\n
"
},
entry
{
"16c debug"
,
100
,
0
,
'\t'
,
DiscardEmptyColumns
|
Debug
,
"a
\t
b
\t\t
d
\n
"
// hard tabs - do not discard column
"a
\t
b
\t\t
d
\t
e
\n
"
"a
\n
"
"a
\t
b
\t
c
\t
d
\n
"
"a
\t
b
\t
c
\t
d
\t
e
\n
"
,
"a
\t
|b
\t
|
\t
|d
\n
"
"a
\t
|b
\t
|
\t
|d
\t
|e
\n
"
"a
\n
"
"a
\t
|b
\t
|c
\t
|d
\n
"
"a
\t
|b
\t
|c
\t
|d
\t
|e
\n
"
},
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment