dedent

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2015 License: MIT Imports: 2 Imported by: 0

README

Dedent

Build Status Godoc

Removes common leading whitespace from multiline strings. Inspired by textwrap.dedent in Python.

Usage / example

Imagine the following snippet that prints a multiline string. You want the indentation to both look nice in the code as well as in the actual output.

package main

import (
    "fmt"

    "github.com/renstrom/dedent"
)

func main() {
    s := `Lorem ipsum dolor sit amet,
        consectetur adipiscing elit.
        Curabitur justo tellus, facilisis nec efficitur dictum,
        fermentum vitae ligula. Sed eu convallis sapien.`
    fmt.Println(dedent.Dedent(s))
    fmt.Println("-------------")
    fmt.Println(s)
}

To illustrate the difference, here's the output:

$ go run main.go
Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Curabitur justo tellus, facilisis nec efficitur dictum,
fermentum vitae ligula. Sed eu convallis sapien.
-------------
Lorem ipsum dolor sit amet,
        consectetur adipiscing elit.
        Curabitur justo tellus, facilisis nec efficitur dictum,
        fermentum vitae ligula. Sed eu convallis sapien.

License

MIT

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dedent

func Dedent(s string) string

Dedent removes any common leading whitespace from every line in s.

This can be used to make multiline strings to line up with the left edge of the display, while still presenting them in the source code in indented form.

Example
fmt.Println(Dedent(`Lorem ipsum dolor sit amet,
		consectetur adipiscing elit.
		Curabitur justo tellus, facilisis nec efficitur dictum,
		fermentum vitae ligula. Sed eu convallis sapien.`))
Output:

Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Curabitur justo tellus, facilisis nec efficitur dictum,
fermentum vitae ligula. Sed eu convallis sapien.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL