Skip to content

Commit

Permalink
Merge branch 'release/v1.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
EvilLord666 committed Nov 13, 2024
2 parents 6b3d325 + a679eb2 commit a0a85aa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# StringFormatter

A set of a ***high performance string tools*** that helps to build strings from templates and process text that
faster than `fmt`!!!.
A set of a ***high performance string tools*** that helps to build strings from templates and process text faster than with `fmt`!!!.

![GitHub go.mod Go version (subdirectory of monorepo)](https://img.shields.io/github/go-mod/go-version/wissance/stringFormatter?style=plastic)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/wissance/stringFormatter?style=plastic)
![GitHub issues](https://img.shields.io/github/issues/wissance/stringFormatter?style=plastic)
![GitHub Release Date](https://img.shields.io/github/release-date/wissance/stringFormatter)
![GitHub release (latest by date)](https://img.shields.io/github/downloads/wissance/stringFormatter/v1.2.0/total?style=plastic)
![GitHub release (latest by date)](https://img.shields.io/github/downloads/wissance/stringFormatter/v1.2.1/total?style=plastic)

![String Formatter: a convenient string formatting tool](/img/sf_cover.png)

Expand Down
6 changes: 6 additions & 0 deletions formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func Format(template string, args ...any) string {
if template[i] == '{' {
// possibly it is a template placeholder
if i == templateLen-1 {
// if we gave { at the end of line i.e. -> type serviceHealth struct {,
// without this write we got type serviceHealth struct
formattedStr.WriteByte('{')
break
}
// considering in 2 phases - {{ }}
Expand Down Expand Up @@ -156,6 +159,9 @@ func FormatComplex(template string, args map[string]any) string {
if template[i] == '{' {
// possibly it is a template placeholder
if i == templateLen-1 {
// if we gave { at the end of line i.e. -> type serviceHealth struct {,
// without this write we got type serviceHealth struct
formattedStr.WriteByte('{')
break
}

Expand Down
10 changes: 10 additions & 0 deletions formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ func TestFormat(t *testing.T) {
},
expected: "Example is: {123 This is a test str, nothing more special -1.098743 main question error, is 42}",
},
"open bracket at the end of line of go file": {
template: "type serviceHealth struct {",
args: []any{},
expected: "type serviceHealth struct {",
},
} {
t.Run(name, func(t *testing.T) {
assert.Equal(t, test.expected, stringFormatter.Format(test.template, test.args...))
Expand Down Expand Up @@ -192,6 +197,11 @@ func TestFormatComplex(t *testing.T) {
args: map[string]any{"ipaddr": "127.0.0.1", "port": 5432, "ssl": false},
expected: "Current app settings are: ipAddr: 127.0.0.1, port: 5432, use ssl: false.",
},
"one json line with open bracket at the end": {
template: " \"server\": {",
args: map[string]any{},
expected: " \"server\": {",
},
} {
t.Run(name, func(t *testing.T) {
assert.Equal(t, test.expected, stringFormatter.FormatComplex(test.template, test.args))
Expand Down

0 comments on commit a0a85aa

Please sign in to comment.