Categorygithub.com/fbaube/stringutils
modulepackage
0.0.0-20250203130909-339670f598f3
Repository: https://github.com/fbaube/stringutils.git
Documentation: pkg.go.dev

# README

String utilities for Golang. Nothing major. No rocket science.

This package has no external dependencies beyond the standard library.

Why this package exists:

  • A reluctance to use regular expressions in XML processing (they be slow).
  • XML allows both single and double quotes (and the code to process it can get very ugly):
    "A quoted string."
    'A quoted string.'
    <mytag myatt1="Ain't trip'd up" myatt2='by "weird" quoting'>
    

This package takes a liberal view towards trimming leading and trailing whitespace. Whitespace treatment is one of those very irritating things about XML.

# Functions

AddIndent prefixes `in` string with `nr` occurrences of `indentString`.
ColorDemo can be run from anywhere anytime to see samples.
ConcatAll concatenates all its (vargs) arguments into a new string.
ConcatAllSpaced concatenates all its (vargs) arguments into a new string, with spaces inserted in-between 'em.
DeleteEmptyStrings returns the slice with any empty or all-whitespace strings deleted.
ElideCWD has effects that are session-specific, so it should only be used to make better user messages.
ElideHomeDir doesn't try to deal with a relative path that starts with "." .
Enslice turns the string into a string slice of length 1.
FilterStringList filters out filenames that match simple patterns (prefixes, "midfixes", suffixes).
FilterStringsBySuffix takes a list of filenames and filters out those whose file extensions are not in the list that is passed in.
GetHomeDir is a convenience function, and refers to the invoking user's home directory.
GetIndent returns a string that has `depth` instances of the standard indent string (two spaces, unless otherwise modified).
GetYamlMetadataAsPropSet is a convenience function.
IsInSliceIgnoreCase is like IsInSlice but without case matching.
IsXmlQuote checks whether the string is either one single quote or one double quote.
IsXmlQuoted checks whether the string is surrounded by either single quotes or double quotes.
Ito09az converts its int arg (0..35) to a string of length one, in the range (for int 0..9) "0".."9", (for int 10..35) "a".."z".
LS_lh generates a file listing string like for "ls -l -h".
MakeCSV returns the string slice as a CSV string.
MakeQuotedCSV places double-quotes around the output of [MakeCSV].
MustXmlUnquote removes either paired single quotes or paired double quotes.
NormalizeWhitespace replaces weird whitespace junk (including newlines) with spaces.
No description provided by the author
NowAsYM maps (reversibly) the current year+month to "YM".
NowAsYMDHM maps (reversibly) the current time to "YMDhm" (where m is minutes / 2).
NowPlus returns the current local date+time in a sensible format, i.e.
PadLeftToLen adds leading `pad` characters to hit the target length.
PadRightToLen adds trailing `pad` characters to hit the target length.
ParseYamlMetadata tries to extract a YAML metadata block (YMB) - as a map - from the (start of the) input string `instring`.
PrettifyISO converts - 2022-02-17T15:22:07+02:00 to - 2022-02-17/15:22:07/+02.
SplitOffFirstWord splits the input string around the first whitespace, as defined by func [strings.Fields], which uses [unicode.IsSpace].
SplitOffQuotedToken expects the string to start with an XML quote (i.e.
StringToBytes uses both reflect and unsafe, so it's a bit of a turd.
StripDelimiters tries to remove corresponding characters from both ends of the input string.
StripQuotes tries to strip off matching XML quotes (i.e.
Tildotted shortens a filepath by ediding the current user's home directory, or the current working directory, by eliding "~" or "." respectively.
TrimMatchingDelims tried to strip off matching first and last characters.
TrimYamlMetadataDelimiters supplies a trailing newline.
TruncateTo truncates & ends the string with triple dots if it's too long.
YamlMapAsPropSet returns a PropSet, i.e.
YamlMetadataHeaderRange wants "---" at the start of the file at the start of a line (maybe after whitespace) to open the block, and "---" or "..." at the start of a new line to end the block.
Yn returns (as a string) a single character, `Y` or `n`.

# Constants

PathSep is a token nod to Windoze compatibility.
Raw_type_BIN is opaque .
Raw_type_DIRLIKE is a hack placeholder for consistent handling (because of consistent problems in code): IsDirlike is a more general case of IsDir() - shorthand for "is not possible to have own content" - but this can be more formally defined as "is/has link(s) to other stuff" - i.e.
Raw_type_HTML is assumed to be HTML5.
Raw_type_MKDN is assumed to be CommonMark (or GFM?).
Raw_type_NIL is none (or too little) to figure out what kind.
Raw_type_SQL is, well, hey why not eh.
Raw_type_XML is assumed to be well-formed.

# Variables

No description provided by the author
No description provided by the author
These are all functions that are created via the imported library [color].
These are all functions that are created via the imported library [color].
IndentationPrefix is for all sorts of output.
These are all functions that are created via the imported library [color].
These are all functions that are created via the imported library [color].
No description provided by the author
These are all functions that are created via the imported library [color].
These are all functions that are created via the imported library [color].

# Interfaces

Stringser is a handy interface for content.

# Type aliases

No description provided by the author
No description provided by the author
StringChainger is a func that is String In, String out, and therefore chainable.
Stringstack is a LIFO stack for strings.