whitespace

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: GPL-3.0 Imports: 6 Imported by: 1

Documentation

Overview

Package whitespace finds the spaces out of place in a name: doubled, at an end, odd, or before a colon or a file extension. It says what is wrong (Problems), shows it (Visible) and puts it right (Fixed). What is wrong depends on the kind of text (Text): a file name has an extension, and a French title keeps its space before a colon.

Index

Constants

View Source
const (
	OddSpace        = "odd_space"
	DoubleSpace     = "double_space"
	EdgeSpace       = "edge_space"
	BeforeExtension = "space_before_extension"
	BeforeColon     = "space_before_colon"
)

The problems, named as Problems reports them, in the order it reports them.

Variables

ProblemOrder is every problem, in the order Problems lists them.

Functions

func Any

func Any(r rune) bool

Any is an ordinary space or an odd one.

func DroppedAt

func DroppedAt(name, title string) string

DroppedAt is what a title holds where a name has two spaces in a row, when the words either side are in the title: ":" for "Dune Part Two" against "Dune: Part Two". "" when they do not line up, or the gap holds more than a few words, which is another name.

func EndsWithSpace

func EndsWithSpace(s string) bool

EndsWithSpace says whether a text ends with a space of any kind.

func Fixed

func Fixed(name string, k Text) string

Fixed is a text with its spaces put right; "" when nothing is left but spaces or an extension, since ".mkv" would read as a hidden file.

func IndexWord

func IndexWord(s, word string) int

IndexWord is where word first stands in s as a word of its own ("IV" in "Episode IV", not in "DIVE"); -1 for nowhere.

func IsWordChar

func IsWordChar(r rune) bool

IsWordChar is a letter or a digit, of any script.

func Odd

func Odd(r rune) bool

Odd is a space that is not the ordinary one: a tab, a line break, a non-breaking or typographic space. The ideographic space, U+3000, is not one: Japanese titles use it as written.

func Problems

func Problems(name string, k Text) []string

Problems is what is wrong with the spaces in one text, in ProblemOrder; nothing for a text whose spaces are all in place.

func SplitExt

func SplitExt(name string) (stem, ext string)

SplitExt parts a file name into stem and extension; a last dot that starts no plausible extension (over five letters, or with a space) is all stem. Trailing spaces are read as neither, so one after the extension hides none before it.

func StartsWithSpace

func StartsWithSpace(s string) bool

StartsWithSpace says whether a text begins with a space of any kind.

func Typographic

func Typographic(r rune) bool

Typographic is a no-break or narrow space a language's own typography sets on purpose: French puts one before a colon ("Titre : Sous-titre").

func Visible

func Visible(name string, k Text) string

Visible shows the offending spaces: ␣ for an ordinary space out of place, [U+00A0] for an odd one wherever it is. An odd space makes a run with its neighbours, which are marked too.

Types

type Text

type Text int

Text is what a text is, which decides what is wrong with its spaces.

const (
	// Name is a name or a value: every problem counts
	Name Text = iota
	// File is a file name, read as a stem and an extension
	File
	// Foreign is an original title, written in its own language: the space before a colon and the typographic spaces that language's typography sets
	// are left alone, and only the rest is a problem
	Foreign
)

Jump to

Keyboard shortcuts

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