Gutenberg

Class KernighanRitchieBracketer<T>

An IBracketer<T> which uses the K&R style.

Inheritance
  • Object
  • KernighanRitchieBracketer<T>
Implements
Declaration
public class KernighanRitchieBracketer<T> : Object, IBracketer<T>
Type Parameters
Name Description

T

The type of annotations in the document.

Remarks

"The K&R style" is the name for the bracketing style which is customary in C, Java, and JavaScript, among others. The opening bracket is placed on the current line, the contained document is indented, and the closing bracket is placed on a new line.

Examples
var bracketer = new KernighanRitchieBracketer<object>("{", "}", false);
var doc = "header " + bracketer.Bracket(
    new Doc[] { "line 1", "line 2" }
        .Separated(Doc.LineBreak)
);
Console.WriteLine(doc);
// Output:
// header {
//     line 1
//     line 2
// }

Constructors

KernighanRitchieBracketer(Document<T>, Document<T>, Boolean, Nullable<Int32>)

Creates an IBracketer<T> which uses the K&R style.

Declaration
public KernighanRitchieBracketer(Document<T> openingBracket, Document<T> closingBracket, bool group = true, Nullable<int> nestingLevel = null)
Parameters
Type Name Description

Document<T>

openingBracket

A Document<T> representing the opening bracket character.

Document<T>

closingBracket

A Document<T> representing the closing bracket character.

Boolean

group

Whether the resulting Document<T> should be grouped — that is, whether the document may be flattened to a single line if it fits.

Nullable<Int32>

nestingLevel

The amount of indentation to apply to the bracketed document

Methods

Bracket(Document<T>)

Surrounds the document with brackets.

Declaration
public Document<T> Bracket(Document<T> document)
Parameters
Type Name Description

Document<T>

document

Returns
Type Description

Document<T>

Implements

IBracketer<T>