mirror of
https://github.com/golang/go
synced 2024-11-23 00:10:07 -07:00
automatically add tabs after newlines
R=gri DELTA=12 (10 added, 0 deleted, 2 changed) OCL=19758 CL=19758
This commit is contained in:
parent
01b44bbfc8
commit
0444d697c1
@ -14,6 +14,16 @@ func init() {
|
|||||||
flag.Bool("chatty", false, &chatty, "chatty");
|
flag.Bool("chatty", false, &chatty, "chatty");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Insert tabs after newlines - but not the last one
|
||||||
|
func Tabify(s string) string {
|
||||||
|
for i := 0; i < len(s) - 1; i++ { // -1 because if last char is newline, don't bother
|
||||||
|
if s[i] == '\n' {
|
||||||
|
return s[0:i+1] + "\t" + Tabify(s[i+1:len(s)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
export type T struct {
|
export type T struct {
|
||||||
errors string;
|
errors string;
|
||||||
failed bool;
|
failed bool;
|
||||||
@ -31,11 +41,11 @@ func (t *T) FailNow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *T) Log(args ...) {
|
func (t *T) Log(args ...) {
|
||||||
t.errors += "\t" + fmt.sprintln(args);
|
t.errors += "\t" + Tabify(fmt.sprintln(args));
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *T) Logf(format string, args ...) {
|
func (t *T) Logf(format string, args ...) {
|
||||||
t.errors += fmt.sprintf("\t" + format, args);
|
t.errors += Tabify(fmt.sprintf("\t" + format, args));
|
||||||
l := len(t.errors);
|
l := len(t.errors);
|
||||||
if l > 0 && t.errors[l-1] != '\n' {
|
if l > 0 && t.errors[l-1] != '\n' {
|
||||||
t.errors += "\n"
|
t.errors += "\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user