Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dedent ¶
Dedent takes a string and returns the same string with all leading whitespace characters removed, with a maximum of the smallest count of those characters. It is very similar to Python's textwrap.dedent(). Dedent also removes any newline-only lines.
For example, the following string (which I need to write this way because of godoc formatting):
\tabc\n\t\teasy as\n\t\t\tone two three
would be returned as:
abc\t\neasy as\n\t\tone two three
which is dedented by one tab character (the smallest amount discovered).
Note that this implementation depends on the line separator being LF (`\n`).
Example ¶
Dedent is most helpful when writing embedded multiline strings, that typically you would need to align fully to the first column of your file. Using Dedent allows for indenting for easier readability without the ugly break in visual scans.
theUglyWayYouUsuallyHaveToDoIt := `--- some: yaml_frontmatter --- key1: key1a: value key2a: key2aa: value key2: value` indentedString := ` --- some: yaml_frontmatter --- key1: key1a: value key2a: key2aa: value key2: value ` dedentedString := Dedent(indentedString) fmt.Println(dedentedString == theUglyWayYouUsuallyHaveToDoIt)
Output: true
Types ¶
This section is empty.