Skip to content

Commit a0a85aa

Browse files
committed
Merge branch 'release/v1.2.1'
2 parents 6b3d325 + a679eb2 commit a0a85aa

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# StringFormatter
22

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

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

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

formatter.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ func Format(template string, args ...any) string {
4444
if template[i] == '{' {
4545
// possibly it is a template placeholder
4646
if i == templateLen-1 {
47+
// if we gave { at the end of line i.e. -> type serviceHealth struct {,
48+
// without this write we got type serviceHealth struct
49+
formattedStr.WriteByte('{')
4750
break
4851
}
4952
// considering in 2 phases - {{ }}
@@ -156,6 +159,9 @@ func FormatComplex(template string, args map[string]any) string {
156159
if template[i] == '{' {
157160
// possibly it is a template placeholder
158161
if i == templateLen-1 {
162+
// if we gave { at the end of line i.e. -> type serviceHealth struct {,
163+
// without this write we got type serviceHealth struct
164+
formattedStr.WriteByte('{')
159165
break
160166
}
161167

formatter_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ func TestFormat(t *testing.T) {
113113
},
114114
expected: "Example is: {123 This is a test str, nothing more special -1.098743 main question error, is 42}",
115115
},
116+
"open bracket at the end of line of go file": {
117+
template: "type serviceHealth struct {",
118+
args: []any{},
119+
expected: "type serviceHealth struct {",
120+
},
116121
} {
117122
t.Run(name, func(t *testing.T) {
118123
assert.Equal(t, test.expected, stringFormatter.Format(test.template, test.args...))
@@ -192,6 +197,11 @@ func TestFormatComplex(t *testing.T) {
192197
args: map[string]any{"ipaddr": "127.0.0.1", "port": 5432, "ssl": false},
193198
expected: "Current app settings are: ipAddr: 127.0.0.1, port: 5432, use ssl: false.",
194199
},
200+
"one json line with open bracket at the end": {
201+
template: " \"server\": {",
202+
args: map[string]any{},
203+
expected: " \"server\": {",
204+
},
195205
} {
196206
t.Run(name, func(t *testing.T) {
197207
assert.Equal(t, test.expected, stringFormatter.FormatComplex(test.template, test.args))

0 commit comments

Comments
 (0)