Documentation
¶
Index ¶
- Variables
- func AppendAside(s, clause string) string
- func AppendClause(s, clause string) string
- func AppendRelated(s, clause string) string
- func CardinalNoun(n int) string
- func CardinalSuffix(n int) string
- func CardinalWithUnit(n int, singular string, plural string) string
- func FinishSentence(s string) string
- func FormatSentence(s string) string
- func JoinList(strs []string) string
- func JoinListOr(strs []string) string
- func JoinSentenceParts(parts ...string) string
- func JoinSentences(ss ...string) string
- func LowerFirst(s string) string
- func LowerIfFirstWordIn(s string, words ...string) string
- func MaybeAn(s string) string
- func MaybePluralise(s string, quantity int) string
- func MaybePossessiveSuffix(s string) string
- func MultiplicativeAdverb(n int) string
- func OrdinalNoun(n int) string
- func PrefixLines(s string, prefix string) string
- func RemoveAllWhitespace(s string) string
- func RemoveRedundantWhitespace(s string) string
- func ReplaceFirstNumberWithCardinalNoun(s string) string
- func SmallCardinalNoun(n int) string
- func StartsWithNumeral(s string) bool
- func StripNewlines(s string) string
- func StripTerminator(s string) string
- func StripWasIs(st string) string
- func UpperFirst(s string) string
- type Para
- func (p *Para) AddCompleteSentence(ss ...string)
- func (p *Para) AppendAsAside(clause string)
- func (p *Para) AppendClause(ss ...string)
- func (p *Para) AppendList(ss ...string)
- func (p *Para) Continue(ss ...string)
- func (p *Para) Current() string
- func (p *Para) CurrentSentenceLength() int
- func (p *Para) CurrentSentenceWords() int
- func (p *Para) DropSentence()
- func (p *Para) FinishSentence(ss ...string)
- func (p *Para) FinishSentenceWithTerminator(t string)
- func (p *Para) IsEmpty() bool
- func (p *Para) Length() int
- func (p *Para) ReplaceSentence(s string)
- func (p *Para) StartSentence(ss ...string)
- func (p *Para) Text() string
Constants ¶
This section is empty.
Variables ¶
var CommonSentenceStarts = []string{"He", "She", "They", "His", "Her", "Their", "The", "It"}
CommonSentenceStarts lists pronouns and articles that JoinSentenceParts and AppendClause lowercase when they appear at the start of a non-first part, preventing awkward mid-sentence capitalisation.
Functions ¶
func AppendAside ¶
AppendAside is like AppendClause but also appends a trailing comma, producing a parenthetical aside: "base, clause,".
func AppendClause ¶
AppendClause appends clause to s, inserting a comma separator when s is non-empty and does not already end with one. Words from CommonSentenceStarts at the start of clause are lowercased to avoid mid-sentence capitalisation.
func AppendRelated ¶
AppendRelated joins s and clause with an HTML em-dash (—), stripping any sentence terminator from s first. The first letter of clause is lowercased unconditionally.
func CardinalNoun ¶
CardinalNoun returns the English word for n. Values 0-199 are returned as words (e.g. "forty-two"); values above 199 fall back to a decimal digit string.
func CardinalSuffix ¶
CardinalSuffix returns the English ordinal suffix for n: "st", "nd", "rd", or "th". It correctly handles the 11/12/13 exceptions (e.g. 11 -> "th", not "st").
func CardinalWithUnit ¶
CardinalWithUnit returns "one <singular>" when n is 1, and "<CardinalNoun(n)> <plural>" otherwise (e.g. "one child", "two children").
func FinishSentence ¶
FinishSentence trims trailing whitespace and soft punctuation (",", ":", ";") from s and appends a period if s does not already end with ".", "!", or "?". Returns an empty string for blank input.
func FormatSentence ¶
FormatSentence formats s as a complete, well-formed sentence.
func JoinList ¶
JoinList joins elements with commas and a final " and ", producing natural English list prose (e.g. "one, two and three"). Leading/trailing whitespace and punctuation are stripped from each element.
func JoinListOr ¶
JoinListOr is like JoinList but uses " or " before the final element.
func JoinSentenceParts ¶
JoinSentenceParts concatenates non-empty parts with a single space between them. Empty and whitespace-only parts are skipped. The colon ":" is special-cased to receive no leading space.
func JoinSentences ¶
JoinSentences formats each argument as a complete sentence and joins them with a single space. Empty arguments are skipped.
func LowerFirst ¶
LowerFirst lowercases the first rune of s and returns the result. It panics if s is empty.
func LowerIfFirstWordIn ¶
LowerIfFirstWordIn lowercases the first rune of s if s begins with one of the given words followed by a space. The match is an exact word check - a bare prefix is not enough. If no word matches, s is returned unchanged.
func MaybeAn ¶
MaybeAn returns a string intended to be appended to a literal "a" to form the correct indefinite article. It returns "n <s>" when s starts with a vowel (so "a"+"n apple" = "an apple") and " <s>" otherwise (so "a"+" book" = "a book").
func MaybePluralise ¶
MaybePluralise appends "s" to s when quantity is not 1.
func MaybePossessiveSuffix ¶
MaybePossessiveSuffix appends the correct English possessive suffix: "'" when s already ends in "s" (e.g. "Jones'"), or "'s" otherwise.
func MultiplicativeAdverb ¶
MultiplicativeAdverb returns the English adverb for n occurrences: "no" for 0, "once" for 1, "twice" for 2, and "N times" for larger values.
func OrdinalNoun ¶
OrdinalNoun returns the English ordinal word for n (e.g. 1 -> "first", 21 -> "twenty-first"). Values above 100 are not handled and produce unexpected results.
func PrefixLines ¶
PrefixLines prepends prefix to every line in s, including the first.
func RemoveAllWhitespace ¶
RemoveAllWhitespace removes every whitespace character from s.
func RemoveRedundantWhitespace ¶
RemoveRedundantWhitespace collapses each run of whitespace to a single space and trims leading and trailing whitespace.
func ReplaceFirstNumberWithCardinalNoun ¶
ReplaceFirstNumberWithCardinalNoun finds the first isolated digit sequence in s and replaces it with its English word form via CardinalNoun. If no digit sequence is found, s is returned unchanged.
func SmallCardinalNoun ¶
SmallCardinalNoun returns the English word for n when n is 0-5 ("no", "one", ..., "five"), and a decimal digit string for larger values. Use this instead of CardinalNoun when the number is expected to be small but a fallback to digits is acceptable for prose readability.
func StartsWithNumeral ¶
StartsWithNumeral reports whether s begins with an ASCII digit.
func StripNewlines ¶
StripNewlines replaces every newline character in s with a space.
func StripTerminator ¶
StripTerminator removes all trailing whitespace and punctuation (" ", ",", ":", ";", ".", "!", "?") from s.
func StripWasIs ¶
StripWasIs removes a leading "was " or "is " auxiliary verb from st, returning the remainder. Used to convert passive voice fragments into bare verb phrases when tense needs to change.
func UpperFirst ¶
UpperFirst trims surrounding whitespace from s, then uppercases its first rune. Returns an empty string if s is blank after trimming.
Types ¶
type Para ¶
type Para struct {
// contains filtered or unexported fields
}
func (*Para) AddCompleteSentence ¶
AddCompleteSentence combines the supplied strings into a formatted sentence and adds it to the para. Any open sentence is finished first. The para is left at the start of a new sentence.
func (*Para) AppendAsAside ¶
AppendAsAside appends an aside to the current sentence, preceding it with a comma if necessary and appending a comma after the clause.
func (*Para) AppendClause ¶
AppendClause appends a clause to the current sentence, preceding it with a comma if necessary.
func (*Para) AppendList ¶
func (*Para) Continue ¶
Continue appends parts to the current sentence. Empty and whitespace-only parts are skipped. A colon ":" is appended without a preceding space. The first letter is not uppercased until the sentence is finalized.
func (*Para) Current ¶ added in v0.0.3
Current returns the accumulated text without finalizing the current sentence. Unlike Text, it does not add a period or uppercase the first letter.
func (*Para) CurrentSentenceLength ¶
func (*Para) CurrentSentenceWords ¶
func (*Para) FinishSentence ¶
FinishSentence completes the current sentence, It combines the supplied strings into text which are added the current sentence and it then terminates the sentence with a full stop and leaves the paragraph ready for the next one.
func (*Para) FinishSentenceWithTerminator ¶
FinishSentence completes the current sentence, terminating it with t and leaves the paragraph ready for the next one.
func (*Para) ReplaceSentence ¶
ReplaceSentence replaces the current sentence with s
func (*Para) StartSentence ¶ added in v0.0.3
StartSentence begins a new sentence by finishing any existing sentence and combining the strings into text which becomes the current sentence. No punctuation or formatting is performed on the new sentence.