Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(15)

Side by Side Diff: src/pkg/tabwriter/tabwriter.go

Issue 224063: code review 224063: tabwriter: make use of new []byte() conversion (Closed)
Patch Set: code review 224063: tabwriter: make use of new []byte() conversion Created 15 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // The tabwriter package implements a write filter (tabwriter.Writer) 5 // The tabwriter package implements a write filter (tabwriter.Writer)
6 // that translates tabbed columns in input into properly aligned text. 6 // that translates tabbed columns in input into properly aligned text.
7 // 7 //
8 // The package is using the Elastic Tabstops algorithm described at 8 // The package is using the Elastic Tabstops algorithm described at
9 // http://nickgravgaard.com/elastictabstops/index.html. 9 // http://nickgravgaard.com/elastictabstops/index.html.
10 // 10 //
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 return err 236 return err
237 } 237 }
238 n -= len(src) 238 n -= len(src)
239 } 239 }
240 return b.write0(src[0:n]) 240 return b.write0(src[0:n])
241 } 241 }
242 242
243 243
244 var ( 244 var (
245 newline = []byte{'\n'} 245 newline = []byte{'\n'}
246 » tabs = []byte{'\t', '\t', '\t', '\t', '\t', '\t', '\t', '\t'} 246 » tabs = []byte("\t\t\t\t\t\t\t\t")
247 ) 247 )
248 248
249 249
250 func (b *Writer) writePadding(textw, cellw int, useTabs bool) os.Error { 250 func (b *Writer) writePadding(textw, cellw int, useTabs bool) os.Error {
251 if b.padbytes[0] == '\t' || useTabs { 251 if b.padbytes[0] == '\t' || useTabs {
252 // padding is done with tabs 252 // padding is done with tabs
253 if b.tabwidth == 0 { 253 if b.tabwidth == 0 {
254 return nil // tabs have no width - can't do any padding 254 return nil // tabs have no width - can't do any padding
255 } 255 }
256 // make cellw the smallest multiple of b.tabwidth 256 // make cellw the smallest multiple of b.tabwidth
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 // format contents of buffer 490 // format contents of buffer
491 _, err := b.format(0, 0, b.lines.Len()) 491 _, err := b.format(0, 0, b.lines.Len())
492 492
493 // reset, even in the presence of errors 493 // reset, even in the presence of errors
494 b.reset() 494 b.reset()
495 495
496 return err 496 return err
497 } 497 }
498 498
499 499
500 var hbar = []byte{'-', '-', '-', '\n'} 500 var hbar = []byte("---\n")
501 501
502 // Write writes buf to the writer b. 502 // Write writes buf to the writer b.
503 // The only errors returned are ones encountered 503 // The only errors returned are ones encountered
504 // while writing to the underlying output stream. 504 // while writing to the underlying output stream.
505 // 505 //
506 func (b *Writer) Write(buf []byte) (n int, err os.Error) { 506 func (b *Writer) Write(buf []byte) (n int, err os.Error) {
507 // split text into cells 507 // split text into cells
508 n = 0 508 n = 0
509 for i, ch := range buf { 509 for i, ch := range buf {
510 if b.endChar == 0 { 510 if b.endChar == 0 {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 return 576 return
577 } 577 }
578 578
579 579
580 // NewWriter allocates and initializes a new tabwriter.Writer. 580 // NewWriter allocates and initializes a new tabwriter.Writer.
581 // The parameters are the same as for the the Init function. 581 // The parameters are the same as for the the Init function.
582 // 582 //
583 func NewWriter(output io.Writer, minwidth, tabwidth, padding int, padchar byte, flags uint) *Writer { 583 func NewWriter(output io.Writer, minwidth, tabwidth, padding int, padchar byte, flags uint) *Writer {
584 return new(Writer).Init(output, minwidth, tabwidth, padding, padchar, fl ags) 584 return new(Writer).Init(output, minwidth, tabwidth, padding, padchar, fl ags)
585 } 585 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b