Tweak lib/dumbindent's comments

This commit is contained in:
Nigel Tao committed 2020-06-16 22:34:36 +10:00
1 parent ab580e7696
commit 635b502649
1 file changed
+11 -14
+11 -14
View File
@@ -96,9 +96,10 @@
// //
// In particular, the algorithm does not solve C++'s "most vexing parse" or // In particular, the algorithm does not solve C++'s "most vexing parse" or
// otherwise determine whether "x*y" is a multiplication or a type definition // otherwise determine whether "x*y" is a multiplication or a type definition
// (where y is a pointer-to-x typed variable, such as "int*p"). For a type // (where y is a pointer-to-x typed variable or function argument, such as
// definition, where other formatting algorithms would re-write around the "*" // "int*p"). For a type definition, where other formatting algorithms would
// as either "x* y" or "x *y", dumbindent will not insert spaces. // re-write around the "*" as either "x* y" or "x *y", dumbindent will not
// insert spaces.
// //
// Similarly, dumbindent will not correct this mis-indentation: // Similarly, dumbindent will not correct this mis-indentation:
// //
@@ -138,8 +139,8 @@ var hangingBytes = [256]bool{
// Options are formatting options. // Options are formatting options.
type Options struct { type Options struct {
// Spaces, if positive, is the number of spaces per indentation level. A // Spaces, if positive, is the number of spaces per indent level. A
// non-positive value means to use the default: 2 spaces per indent. // non-positive value means to use the default: 2 spaces per indent level.
// //
// This field is ignored when Tabs is true. // This field is ignored when Tabs is true.
Spaces int Spaces int
@@ -152,8 +153,8 @@ type Options struct {
// FormatBytes formats the C (or C-like) program in src, appending the result // FormatBytes formats the C (or C-like) program in src, appending the result
// to dst, and returns that longer slice. // to dst, and returns that longer slice.
// //
// It is valid to pass a dst slice (such as nil) whose unused capacity // It is valid to pass a dst slice (such as nil) whose unused capacity,
// (cap(dst) - len(dst)) is too short to hold the formatted program. In this // cap(dst) - len(dst), is too short to hold the formatted program. In this
// case, a new slice will be allocated and returned. // case, a new slice will be allocated and returned.
// //
// Passing a nil opts is valid and equivalent to passing &Options{}. // Passing a nil opts is valid and equivalent to passing &Options{}.
@@ -190,11 +191,7 @@ func FormatBytes(dst []byte, src []byte, opts *Options) []byte {
} }
lineLength := len(line) lineLength := len(line)
// Collapse 2 or more consecutive blank lines into 1. Also strip any // Strip any blank lines at the end of the file.
// blank lines:
// - immediately after a '{',
// - immediately before a '}',
// - at the end of file.
if len(line) == 0 { if len(line) == 0 {
nBlankLines++ nBlankLines++
continue continue
@@ -238,8 +235,8 @@ func FormatBytes(dst []byte, src []byte, opts *Options) []byte {
} }
} }
// Output a certain number of spaces to roughly approximate // Output indentation. Dumbindent's default, 2 spaces per indent level,
// clang-format's default indentation style. // roughly approximates clang-format's default style.
indent := 0 indent := 0
if nBraces > 0 { if nBraces > 0 {
indent += indentCount * nBraces indent += indentCount * nBraces