Skip to content
 
 

Latest commit

 

History

64 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StringFormatter

A set of tools that helps to build strings from templates and process text that faster than fmt!!!.

GitHub go.mod Go version (subdirectory of monorepo) GitHub code size in bytes GitHub issues GitHub Release Date GitHub release (latest by date)

String Fomatter: a convenient string formatting tool

Features

  1. Text formatting with template using traditional for C#, Python programmers style - {0}, {name} that faster then fmt does: String Fomatter: a convenient string formatting tool

benchmark could be runned:

  • to see Format result - go test -bench=Format -benchmem -cpu 1
  • to see fmt result - go test -bench=Fmt -benchmem -cpu 1
  1. Soon will be added new useful features

Description

This is a GO module for template text formatting in syntax like in C# or/and Python using:

  • {n} , n here is a number to notes order of argument list to use
  • {name} to notes arguments by name i.e. {name}, {last_name}, {address} and so on ...

Examples

Format by arg order

i.e. you have following template: Hello {0}, we are greeting you here: {1}!

if you call Format with args "manager" and "salesApp" :

formattedStr := Format("Hello {0}, we are greeting you here: {1}!", "manager", "salesApp")

you get string "Hello manager, we are greeting you here: salesApp!"

Format by arg key

i.e. you have following template: "Hello {user} what are you doing here {app} ?"

if you call FormatComplex with args "vpupkin" and "mn_console" FormatComplex("Hello {user} what are you doing here {app} ?", map[string]interface{}{"user":"vpupkin", "app":"mn_console"})

you get string "Hello vpupkin what are you doing here mn_console ?"

another example is:

    strFormatResult = FormatComplex("Current app settings are: ipAddr: {ipaddr}, port: {port}, use ssl: {ssl}.", 
                                    map[string]interface{}{"ipaddr":"127.0.0.1", "port":5432, "ssl":false})

a result will be: "Current app settings are: ipAddr: 127.0.0.1, port: 5432, use ssl: false."

Contributors

About

A set of tools to manipulate text, i.e. making text from templates in C#/Python way is faster than fmt.Sprintf

Topics

Resources

Stars

215 stars

Watchers

8 watching

Forks

Packages

Contributors

Languages