Documentation
¶
Overview ¶
Package strs has the text helpers that every part of icebath shares: sentences, numbers, sizes and lengths of time in words, first filled values, sets, random tokens, and cuts by characters for the limits of other systems. Text that a person reads in icebath is never cut: a screen wraps it, or leaves a piece out whole where the full text is one step away.
Index ¶
- func About(length time.Duration) string
- func Agreeing(n int, noun, one, many string) string
- func And(items []string) string
- func AndMore(items []string, parts int) string
- func Capital(text string) string
- func Clip(s string, n int) string
- func CompareVersions(a, b string) int
- func Count(n int, noun string) string
- func Counted(n float64, what string) string
- func Deref(p *string) string
- func Filled(texts ...string) string
- func First(items []string) string
- func Fit(s string, n int, tail string) string
- func Full(text string) string
- func Head(s string, n int) string
- func Last(text string) string
- func Line(text string) string
- func List(values []string) []string
- func Lower(text string) string
- func Middle(text string, head, tail int, mark func(omitted, total int) string) string
- func MinorVersion(version string) (string, bool)
- func Nullable(text string) any
- func Number(n float64) string
- func OnOff(on bool) string
- func Opening(text string) string
- func Or(items []string) string
- func Ordinal(n int) string
- func Place(n int) string
- func Plural(word string) string
- func Quote(words ...string) string
- func Random(n int) string
- func Rounded(length time.Duration) string
- func Sentence(text string) string
- func Set(items ...string) map[string]bool
- func Shell(line string) ([]string, error)
- func Singular(word string) string
- func Size(n float64) string
- func Span(length time.Duration) string
- func Strftime(t time.Time, format string) string
- func Tail(s string, n int) string
- func Thousands[...](n T) string
- func Token(n int) string
- func Typed(word string) string
- func Unique(items []string) []string
- type Word
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func About ¶
Length of time in words rounded to the nearest of the unit a user reads it in, such as how long a wait lasts or is left: seconds under two minutes, minutes under two hours, hours under two days and days past that, at least a second
func Agreeing ¶
Count of things named in the singular with the verb after it agreeing, the verb given for one and for several: 1 session matches, 2 sessions match
func AndMore ¶
AndMore lists items in at most the parts given: all of them when they fit, otherwise the first ones and how many more, such as a, b and 6 more. It serves the model's context budget, such as a tool result that names the first files it touched, and never shortens a list that a person reads in icebath.
func Capital ¶
Text that starts a sentence: its first letter a capital, unless its first word is a name that keeps its own case, such as icebath or openWakeWord
func Clip ¶
Clip returns the first n characters of a text, with three periods after them when the text was longer. It serves a hard limit of another system, such as a platform's message length, the model's context budget, or a log field. It never shortens text that a person reads in icebath.
func CompareVersions ¶
Order of two versions by their sort keys: their numbers compared as numbers, so 1.10 comes after 1.9. A word where the other has a number or has ended starts a prerelease, which comes before its release, so 1.0rc1 comes before 1.0 and 1.0.1; zeros past the end of the other add nothing, so 1.2 is 1.2.0
func Counted ¶
Number and the word for what it counts, given in the plural and said in the singular for exactly one: 1 call, 50,000 characters
func Fit ¶
Fit returns a text in at most n characters: a longer text cut, the spaces the cut leaves at its end trimmed, and tail, such as three periods, ending it within the n. It serves a hard limit of another system, such as a title field's length on a chat platform, the model's context budget, or a log field. It never shortens text that a person reads in icebath.
func Full ¶
Text as a sentence of its own: trimmed, its first letter a capital as Capital gives it, and an end mark as Sentence gives it. Empty for none
func Head ¶
Head returns the first n characters of a text, its bytes unchanged. It serves a hard limit of another system, such as a platform's message or field length, the model's context budget, or a log field. It never shortens text that a person reads in icebath.
func Last ¶
Last line of a text that is not blank, trimmed, such as what a program printed last. Empty when every line is blank
func Lower ¶
Text that reads inside a sentence: its first letter in lower case, unless its first word is an acronym or a name with capitals of its own, such as MCP or iOS
func Middle ¶
Middle returns a text with head characters of its start and tail characters of its end once it is longer than both, and between them the mark that mark makes of how many characters were left out of how many. It serves the model's context budget, such as the middle of a long output that a tool result leaves out with a notice to the model, a hard limit of another system, or a log field. It never shortens text that a person reads in icebath.
func MinorVersion ¶
Major and minor of a version, such as 3.12 of 3.12.4, false when it has fewer than two numbers
func Number ¶
Number in digits grouped in thousands, with as many decimals as it has and no more than three
func Opening ¶
First sentence of a text, on one line: the text up to the first mark that ends a sentence with more after it, such as what a refusal says before what it tells the agent to do. The whole line when it has one sentence
func Place ¶
Place in a list as a user says it inside a sentence: first, second and third, then as Ordinal writes it, such as 4th or 21st
func Quote ¶
Words as a POSIX shell would read them back, one or a whole command line: a word with anything in it a shell reads as more than itself, or with nothing in it, quoted
func Rounded ¶
Length of time in words rounded down to its largest whole unit, such as how long ago something was: 45 seconds, 3 minutes, 2 days; under a second for less
func Sentence ¶
Text that ends as a sentence: trimmed, with a period added when it ends in no mark of its own. Empty for none
func Shell ¶
Words of a command line split as a POSIX shell splits them, honoring quotes and backslashes: a backslash takes the next character as it is, inside double quotes only a $, a backquote, a double quote or another backslash, any other keeping its backslash, and a backslash before the end of a line joins the line to the next. An error, said for a person, when a quote or a backslash at the end is left open
func Singular ¶
Word for one of what the plural names: a short unit such as MB or ms is left as it is
func Size ¶
Count of bytes in the largest unit that fits, the units of 1024 for a count they divide and of 1000 for any other: 512 bytes, 1.5 KB, 5 MB
func Span ¶
Length of time in words, in the largest unit that divides it: 1 hour, 90 minutes, 1.5 seconds
func Strftime ¶
A time as C's strftime writes it under the C locale, as Python's strftime gives it and as a user writes a format such as %H:%M: %Y %y %m %d %e %H %I %l %M %S %p %b %h %B %a %A %j %w %Z %z %F %T and %%, a - after the % leaving a number unpadded. Any other % pair is kept
func Tail ¶
Tail returns the last n characters of a text, its bytes unchanged. It serves a hard limit of another system, the model's context budget, or a log field, such as the end of a long output that a tool result keeps. It never shortens text that a person reads in icebath.
func Thousands ¶
func Thousands[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](n T) string
Whole number with commas between its thousands
func Token ¶
N random bytes as unpadded URL safe base64, the shape of a state, verifier or token handed out
Types ¶
type Word ¶
A word of a line as a user types it in a session, and where it lies in the line with its quotes
func Chat ¶
Words of a line as a user types them in a session: split at spaces and line breaks, a run in single or double quotes kept whole. A backslash keeps the quote, backslash or space after it as it is and joins a line to the next before a line break, and is itself before anything else, as in a path of Windows. Inside double quotes it keeps a quote, a backslash, a $ or a backquote. A quote right after a letter or a digit of a word is the word's own, as in don't or Nick's, and so is a single quote between two letters inside single quotes, so a name such as Nick's site reads as typed and words Quote wrote read back as they were. An error a user reads for a quote never closed or a backslash ending the line