Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Simple and pure Go text/word wrapping port of Python textwrap

License

Notifications You must be signed in to change notification settings

cbess/go-textwrap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

6 Commits

Repository files navigation

Go Text Wrapping

It is a lightweight and simple port of the textwrap Python module.

Soli Deo gloria

Features:

  • Lightweight. Uses only the Go built-in library (no external deps).
  • Simple. Easy to understand code.
  • Counts number of words and characters.
  • Splits (or groups) text based on character limit (width) per group (each wrap).
  • 100% test coverage.
  • GoDoc documentation

Note

It was only designed to work with English text; it separates words by whitespace.

Example

import (
 "fmt"
 "textwrap"
)
origText := "Jesus is God. He Saves by grace through faith alone."
result, err := textwrap.WordWrap(origText, 10, -1)
if err != nil {
 // handle error
}
// check if max word count exceeded
if result.IsValid() {
 // print text groups
 for idx, text := range result.TextGroups {
 fmt.Println("[", idx+1, "]", text)
 }
}

License

MIT

About

Simple and pure Go text/word wrapping port of Python textwrap

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /