whitespace

package
v0.5.1 Latest Latest
Warning

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

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

Documentation

Overview

Package whitespace finds the spaces out of place in a name: doubled, leading, trailing and odd spaces, and a space before a colon or a file extension. For each name it says what is wrong (Problems), shows it with the offending spaces made visible (Visible) and puts it right (Fixed).

Names come in kinds (Text), because what is wrong depends on what the text is: a file name has an extension a space can sit before, and a title in its own language keeps the spaces its typography sets - French puts one 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 of the gap are in the title too: ":" for "Dune Part Two" written with two spaces against "Dune: Part Two", the asterisks of a censored word. "" when the two do not line up, or the title holds nothing there, or more than a few words - which is another name rather than a character a renamer dropped.

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: an odd space made an ordinary one, runs made one, the ends and the space before a colon or the extension dropped. It is "" when nothing is left of the name but spaces, or its extension: there is no name to suggest, and ".mkv" for " .mkv" would be a file the next reader takes for a hidden one.

func IndexWord

func IndexWord(s, word string) int

IndexWord is where word first stands in s as a word of its own, and not inside a longer one ("IV" in "Episode IV", not in "DIVE"); -1 when it does not.

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 its stem and its extension; a name whose last dot starts no plausible extension (longer than five letters, or with a space in it) is all stem. The name is read without the spaces after it, which are no part of either: "Chapter 1 .mp3 " is "Chapter 1 " and ".mp3", so a space 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 writes a text with the offending spaces made visible: ␣ for an ordinary space in a run, at an end, before a colon or before the extension, and [U+00A0] for a space that is not the ordinary one, wherever it is. An odd space makes a run with the spaces beside it, so the ordinary one next to it is 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