Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

v0 source pure

v0 - Unaudited: This is an initial version that has not yet been formally audited. A fully audited version will be pu...

Readme View source

v0 - Unaudited This is an initial version of this package that has not yet been formally audited. A fully audited version will be published as a subsequent release. Use in production at your own risk.

ufmt

Package ufmt provides utility functions for formatting strings, similarly to the Go package fmt, of which only a subset is currently supported.

Overview

v0 - Unaudited: This is an initial version that has not yet been formally audited. A fully audited version will be published as a subsequent release. Use in production at your own risk.

Package ufmt provides utility functions for formatting strings, similarly to the Go package "fmt", of which only a subset is currently supported.

Package ufmt provides utility functions for formatting strings, similarly to the Go package "fmt", of which only a subset is currently supported (hence the name µfmt - micro fmt). It includes functions like Printf, Sprintf, Fprintf, and Errorf. Supported formatting verbs are documented in the Sprintf function.

Functions 13

func Append

1func Append(b []byte, a ...any) []byte
source

Append formats using default formats, appends to b, and returns the updated slice. Spaces are added between arguments.

func Appendf

1func Appendf(b []byte, format string, a ...any) []byte
source

Appendf formats according to a format specifier, appends the result to the byte slice, and returns the updated slice.

func Appendln

1func Appendln(b []byte, a ...any) []byte
source

Appendln formats using default formats, appends to b, and returns the updated slice. Appends a newline after the last argument.

func Errorf

1func Errorf(format string, args ...any) error
source

Errorf formats according to a format specifier and returns an error value. Supports the same verbs as Sprintf. See Sprintf documentation for details.

func Fprint

1func Fprint(w io.Writer, a ...any) (n int, err error)
source

Fprint formats using default formats and writes to w. Spaces are added between arguments. Returns the number of bytes written and any write error encountered.

func Fprintf

1func Fprintf(w io.Writer, format string, a ...any) (n int, err error)
source

Fprintf formats according to a format specifier and writes to w. Returns the number of bytes written and any write error encountered.

func Fprintln

1func Fprintln(w io.Writer, a ...any) (n int, err error)
source

Fprintln formats using default formats and writes to w with newline. Returns the number of bytes written and any write error encountered.

func Print

1func Print(a ...any) (n int, err error)
source

Print formats using default formats and writes to standard output. Spaces are added between arguments. Returns the number of bytes written and any write error encountered.

XXX: Replace with os.Stdout handling when available.

func Printf

1func Printf(format string, a ...any) (n int, err error)
source

Printf formats according to a format specifier and writes to standard output. Returns the number of bytes written and any write error encountered.

XXX: Replace with os.Stdout handling when available.

func Println

1func Println(a ...any) (n int, err error)
source

Println formats using default formats and writes to standard output with newline. Returns the number of bytes written and any write error encountered.

XXX: Replace with os.Stdout handling when available.

func Sprint

1func Sprint(a ...any) string
source

Sprint formats using the default formats for its operands and returns the resulting string. Sprint writes the given arguments with spaces between arguments.

func Sprintf

1func Sprintf(format string, a ...any) string
source

Sprintf offers similar functionality to Go's fmt.Sprintf, or the sprintf equivalent available in many languages, including C/C++. The number of args passed must exactly match the arguments consumed by the format. A limited number of formatting verbs and features are currently supported.

Supported verbs:

Example
 1%s: Places a string value directly.
 2    If the value implements the interface interface{ String() string },
 3    the String() method is called to retrieve the value. Same about Error()
 4    string.
 5%c: Formats the character represented by Unicode code point
 6%d: Formats an integer value using package "strconv".
 7    Currently supports only uint, uint64, int, int64.
 8%f: Formats a float value, with a default precision of 6.
 9%e: Formats a float with scientific notation; 1.23456e+78
10%E: Formats a float with scientific notation; 1.23456E+78
11%F: The same as %f
12%g: Formats a float value with %e for large exponents, and %f with full precision for smaller numbers
13%G: Formats a float value with %G for large exponents, and %F with full precision for smaller numbers
14%t: Formats a boolean value to "true" or "false".
15%x: Formats an integer value as a hexadecimal string.
16    Currently supports only uint8, []uint8, [32]uint8.
17%c: Formats a rune value as a string.
18    Currently supports only rune, int.
19%q: Formats a string value as a quoted string.
20%T: Formats the type of the value.
21%v: Formats the value with a default representation appropriate for the value's type
22    - nil: <nil>
23    - bool: true/false
24    - integers: base 10
25    - float64: %g format
26    - string: verbatim
27    - types with String()/Error(): method result
28    - others: (unhandled)
29%%: Outputs a literal %. Does not consume an argument.

Unsupported verbs or type mismatches produce error strings like "%!d(string=foo)".

func Sprintln

1func Sprintln(a ...any) string
source

Sprintln formats using default formats and returns the string with newline. Spaces are always added between arguments.

Imports 5

  • errors stdlib
  • io stdlib
  • strconv stdlib
  • strings stdlib
  • unicode/utf8 stdlib

Source Files 5