mirror of
https://github.com/golang/go
synced 2024-11-25 09:47:57 -07:00
- debugging support
R=rsc DELTA=110 (98 added, 0 deleted, 12 changed) OCL=35487 CL=35490
This commit is contained in:
parent
094f1d5990
commit
517839aa40
@ -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.
|
||||
@ -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,7 +157,7 @@ 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,
|
||||
@ -162,6 +166,12 @@ const (
|
||||
// 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
|
||||
|
||||
|
@ -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\t2\t3\t4\f" // \f causes a newline and flush
|
||||
"11\t222\t3333\t44444\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\t2.4\t-5.1\t\n"
|
||||
"23.0\t12345678.9\t2.4\t-989.4\t\n"
|
||||
"5.1\t12.0\t2.4\t-7.0\t\n"
|
||||
".0\t0.0\t332.0\t8908.0\t\n"
|
||||
".0\t-.3\t456.4\t22.1\t\n"
|
||||
".0\t1.2\t44.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\tb\tc\td\te\n"
|
||||
},
|
||||
|
||||
entry{
|
||||
"16b debug",
|
||||
100, 0, '\t', DiscardEmptyColumns | Debug,
|
||||
"a\vb\v\vd\n"
|
||||
"a\vb\v\vd\ve\n"
|
||||
"a\n"
|
||||
"a\vb\vc\vd\n"
|
||||
"a\vb\vc\vd\ve\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\tb\tc\td\n"
|
||||
"a\tb\tc\td\te\n"
|
||||
},
|
||||
|
||||
entry{
|
||||
"16c debug",
|
||||
100, 0, '\t', DiscardEmptyColumns | Debug,
|
||||
"a\tb\t\td\n" // hard tabs - do not discard column
|
||||
"a\tb\t\td\te\n"
|
||||
"a\n"
|
||||
"a\tb\tc\td\n"
|
||||
"a\tb\tc\td\te\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"
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user