fmtstr

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: Apache-2.0 Imports: 8 Imported by: 1

README

godoc codecov Go Report Card

go-corelibs/fmtstr - format string utility

fmtstr is a package for parsing fmt package format strings and doing interesting things with the results. This package is primarily built to support the custom gotext parsing of text and html template files within the Go-Enjin theming system.

Installation

> go get github.com/go-corelibs/fmtstr@latest

Examples

Parse

func main() {
    replaced, labelled, variables, err := Parse("Testing: %d %T things", ".Count", ".Data")
    // err == nil in this case
    // replaced == "Testing: %[1]d %[2]T things"
    // labelled == "Testing: {Count} {Data} things"
    // variables contains all the specifics of each format variable used and
    // if you're not building a language translation system, or otherwise doing
    // strange and different things with format strings, this is likely too
    // much information and not the actual Go package you're looking for
}

Go-CoreLibs

Go-CoreLibs is a repository of shared code between the Go-Curses and Go-Enjin projects.

License

Copyright 2023 The Go-CoreLibs Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use file except in compliance with the License.
You may obtain a copy of the license at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPosArgNotImpl = errors.New("positional argument support for width and precision is not implemented yet")
)

Functions

func TrimVarPrefix

func TrimVarPrefix(tmplVar string) (trimmed string)

Types

type Modifier

type Modifier uint8
const (
	NoModifiers Modifier = 0
	ModPlus     Modifier = 1 << iota
	ModMinus
	ModHash
	ModSpace
	ModDecimal
	ModZeroPad
)

type Variable

type Variable struct {
	Type      string
	Label     string
	Source    string
	Pos       int
	Verb      Verb
	Value     string
	Width     int
	Precision int
	Modifiers Modifier
}

func (*Variable) Has

func (v *Variable) Has(m Modifier) (present bool)

func (*Variable) String

func (v *Variable) String() (value string)

type Variables

type Variables []*Variable

func Parse

func Parse(format string, argv ...string) (replaced, labelled string, variables Variables, err error)

func (Variables) Count

func (v Variables) Count() (argc int)

func (Variables) Sort

func (v Variables) Sort() (sorted Variables)

func (Variables) String

func (v Variables) String() (values string)

type Verb

type Verb string

func (Verb) Equal

func (v Verb) Equal(o Verb) (equal bool)

func (Verb) Label

func (v Verb) Label() string

func (Verb) String

func (v Verb) String() string

func (Verb) Type

func (v Verb) Type() string

Jump to

Keyboard shortcuts

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