fmtspec

package
v1.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package fmtspec provides a tiny shared parser for the subset of C printf format specifiers that Trice needs during source analysis and host-side decoding.

The parser exists to keep internal/id and internal/decoder in sync. Issue #649 showed that the previous duplicated regex-based scanners drifted apart and did not recognize valid C length modifiers such as %zu, %lu, %lX or %llX.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kind

type Kind int

Kind classifies a single format specifier for later decoder-side handling.

const (
	KindUnsigned Kind = iota
	KindSigned
	KindBasedInteger
	KindFloat
	KindBool
	KindPointer
	KindString
)

type Spec

type Spec struct {
	Kind Kind
	Verb byte
}

Spec describes one parsed and normalized format specifier.

func Normalize

func Normalize(format string) (string, []Spec)

Normalize rewrites valid C length-modified format specifiers to a length-free form that Go fmt understands while preserving flags, width and precision.

Examples:

%zu   -> %u
%8lu  -> %8u
%li   -> %d
%016llX -> %016X
%04Lf -> %04f

Unsupported or invalid combinations are intentionally left untouched and are not counted as recognized Trice format specifiers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL