return true
}
-// sendType sends the type info to the other side, if necessary.
+// sendType sends the type info to the other side, if necessary.
func (enc *Encoder) sendType(w io.Writer, state *encoderState, origt reflect.Type) (sent bool) {
ut := userType(origt)
if ut.isGobEncoder {
return true
}
-// sendType sends the type info to the other side, if necessary.
+// sendType sends the type info to the other side, if necessary.
func (enc *Encoder) sendType(w io.Writer, state *encoderState, origt reflect.Type) (sent bool) {
ut := userType(origt)
if ut.isGobEncoder {
// all messages <=N have been seen by the recipient. We check anyway.
expLog("sequence out of order:", client.ackNum, hdr.SeqNum)
}
- if client.ackNum < hdr.SeqNum { // If there has been an error, don't back up the count.
+ if client.ackNum < hdr.SeqNum { // If there has been an error, don't back up the count.
client.ackNum = hdr.SeqNum
}
client.mu.Unlock()
// all messages <=N have been seen by the recipient. We check anyway.
expLog("sequence out of order:", client.ackNum, hdr.SeqNum)
}
- if client.ackNum < hdr.SeqNum { // If there has been an error, don't back up the count.
+ if client.ackNum < hdr.SeqNum { // If there has been an error, don't back up the count.
client.ackNum = hdr.SeqNum
}
client.mu.Unlock()
return s
}
-// Errorf formats according to a format specifier and returns the string
+// Errorf formats according to a format specifier and returns the string
// converted to an os.ErrorString, which satisfies the os.Error interface.
func Errorf(format string, a ...interface{}) os.Error {
return os.NewError(Sprintf(format, a...))
return s
}
-// Errorf formats according to a format specifier and returns the string
+// Errorf formats according to a format specifier and returns the string
// converted to an os.ErrorString, which satisfies the os.Error interface.
func Errorf(format string, a ...interface{}) os.Error {
return os.NewError(Sprintf(format, a...))
"strconv"
"strings"
"text/tabwriter"
+ "unicode"
)
const (
// Split comment text into lines
// (using strings.Split(text, "\n") is significantly slower for
// this specific purpose, as measured with: go test -bench=Print)
+//
func split(text string) []string {
// count lines (comment text never ends in a newline)
n := 1
// Returns true if s contains only white space
// (only tabs and blanks can appear in the printer's context).
+//
func isBlank(s string) bool {
for i := 0; i < len(s); i++ {
if s[i] > ' ' {
return true
}
+// commonPrefix returns the common prefix of a and b.
func commonPrefix(a, b string) string {
i := 0
for i < len(a) && i < len(b) && a[i] == b[i] && (a[i] <= ' ' || a[i] == '*') {
return a[0:i]
}
+// trimRight returns s with trailing whitespace removed.
+func trimRight(s string) string {
+ return strings.TrimRightFunc(s, unicode.IsSpace)
+}
+
// stripCommonPrefix removes a common prefix from /*-style comment lines (unless no
// comment line is indented, all but the first line have some form of space prefix).
// The prefix is computed using heuristics such that is is likely that the comment
// shortcut common case of //-style comments
if text[1] == '/' {
- p.writeString(pos, text, true)
+ p.writeString(pos, trimRight(text), true)
return
}
pos = p.pos
}
if len(line) > 0 {
- p.writeString(pos, line, true)
+ p.writeString(pos, trimRight(line), true)
}
}
}
// ----------------------------------------------------------------------------
// Public interface
-// A Mode value is a set of flags (or 0). They control printing.
+// A Mode value is a set of flags (or 0). They control printing.
type Mode uint
const (
}
func _() {
- var a = []int{1, 2}// jasldf
+ var a = []int{1, 2}// jasldf
_ = a
}
var lflag bool // -l - disable line directives
}
+// Trailing white space in comments should be trimmed
+func _() {
+ // This comment has 4 blanks following that should be trimmed:
+ /* Each line of this comment has blanks or tabs following that should be trimmed:
+ line 2:
+ line 3:
+ */
+}
+
/* This comment is the last entry in this file. It must be printed and should be followed by a newline */
}
func _() {
- var a = []int{1, 2, // jasldf
+ var a = []int{1, 2, // jasldf
}
_ = a
}
var lflag bool // -l - disable line directives
}
+// Trailing white space in comments should be trimmed
+func _() {
+// This comment has 4 blanks following that should be trimmed:
+/* Each line of this comment has blanks or tabs following that should be trimmed:
+ line 2:
+ line 3:
+*/
+}
/* This comment is the last entry in this file. It must be printed and should be followed by a newline */