title: “STRING::GENERRORF”
version: “1.0.0”
date: 2024-12-22
author: “laplante@plcb.ca”
section: “1g”
category: “GOWEB/STRING”
Name
string::generrof Formatted Error Generation
Synopsis
string::generrorf(format[, args])
generrorf(format[, args])
string::genErrorf(format[, args])
genErrorf(format[, args])
Description
generrorf
generates an error message based on a format string and optional arguments, similar to Go’s fmt.Printf
formatting verbs.
It supports a wide variety of format verbs for values, types, numbers, strings, runes, pointers, widths, and precisions.
General Verbs
- %!v(MISSING) — Default format (with
%!v(MISSING)
showing struct field names)
- %!v(MISSING) — Go syntax representation of the value
- %!T(MISSING) — Go syntax representation of the type
- % — Literal percent sign (no value consumed)
Boolean
- %!t(MISSING) — Prints
true
or false
Integer
- %!b(MISSING) — Base 2
- %!c(MISSING) — Unicode character corresponding to the code point
- %!d(MISSING) — Base 10
- %!o(MISSING) — Base 8
- %!O(MISSING) — Base 8 with
0o
prefix
- %!q(MISSING) — Single-quoted character literal (Go syntax escaped)
- %!x(MISSING) — Base 16 (lowercase)
- %!X(MISSING) — Base 16 (uppercase)
- %!U(MISSING) — Unicode format:
U+1234
Floating-Point & Complex
- %!b(MISSING) — Decimal-less scientific notation (power of two exponent)
- %!e(MISSING) / %!E(MISSING) — Scientific notation (
e
or E
)
- %!f(MISSING) / %!F(MISSING) — Decimal point, no exponent
- %!g(MISSING) / %!G(MISSING) —
%!e(MISSING)
/%!E(MISSING)
for large exponents, %!f(MISSING)
/%!F(MISSING)
otherwise
- %!x(MISSING) / %!X(MISSING) — Hexadecimal float notation
String
- %!s(MISSING) — Raw bytes of the string
- %!q(MISSING) — Double-quoted, Go syntax-escaped string
- %!x(MISSING) / %!X(MISSING) — Base 16, lower/upper-case (two characters per byte)
Pointer
- %!p(MISSING) — Base 16 with leading
0x
Width & Precision
- Width: minimum field width (padded with spaces unless overridden)
- Precision: number of digits after decimal or max significant digits (
%!g(MISSING)
/%!G(MISSING)
)
- Use
*
to take width/precision from the next argument
Flags
- + — Always print sign for numeric values
- - — Left-justify (pad right)
- # — Alternate format (e.g.,
0x
for hex, raw strings for %!q(MISSING)
)
- space — Space for positive numbers, or spaces between hex bytes
- 0 — Pad with zeros (after sign for numbers)
Examples
res={{
a := [1, 2.2, "3"];
errorf("%!T(MISSING) %!T(MISSING) %!T(MISSING)\n", a);
}}.
Returns:
res=int64 float64 string
res={{
a := [1, 2.2, "3", [1,2,3]];
errorf("%!T(MISSING) %!T(MISSING) %!T(MISSING) %!T(MISSING)\n", a);
}}.
Returns:
res=int64 float64 string int64
%!!(MISSING)(EXTRA int64=2, int64=3)
Author
laplante@plcb.ca
See Also
Version
- 1.0.0 — 2024-12-22 — Initial version