|
7 | 7 | ) |
8 | 8 |
|
9 | 9 | const argumentFormatSeparator = ":" |
| 10 | +const bytesPerArgDefault = 20 |
10 | 11 |
|
11 | 12 | // Format |
12 | 13 | /* Func that makes string formatting from template |
@@ -35,7 +36,7 @@ func Format(template string, args ...any) string { |
35 | 36 |
|
36 | 37 | templateLen := len(template) |
37 | 38 | formattedStr := &strings.Builder{} |
38 | | - argsLen := 16 * len(args) |
| 39 | + argsLen := bytesPerArgDefault * len(args) |
39 | 40 | formattedStr.Grow(templateLen + argsLen + 1) |
40 | 41 | j := -1 //nolint:ineffassign |
41 | 42 |
|
@@ -160,7 +161,8 @@ func FormatComplex(template string, args map[string]any) string { |
160 | 161 |
|
161 | 162 | templateLen := len(template) |
162 | 163 | formattedStr := &strings.Builder{} |
163 | | - formattedStr.Grow(templateLen + 22*len(args)) |
| 164 | + argsLen := bytesPerArgDefault * len(args) |
| 165 | + formattedStr.Grow(templateLen + argsLen + 1) |
164 | 166 | j := -1 //nolint:ineffassign |
165 | 167 | nestedBrackets := false |
166 | 168 | formattedStr.WriteString(template[:start]) |
@@ -224,7 +226,15 @@ func FormatComplex(template string, args map[string]any) string { |
224 | 226 | } |
225 | 227 | if ok || (argFormatOptions != "" && !nestedBrackets) { |
226 | 228 | // get number from placeholder |
227 | | - strVal := getItemAsStr(&arg, &argFormatOptions) |
| 229 | + strVal := "" |
| 230 | + if arg != nil { |
| 231 | + strVal = getItemAsStr(&arg, &argFormatOptions) |
| 232 | + } else { |
| 233 | + formattedStr.WriteString(template[i:j]) |
| 234 | + if j < templateLen-1 { |
| 235 | + formattedStr.WriteByte(template[j]) |
| 236 | + } |
| 237 | + } |
228 | 238 | formattedStr.WriteString(strVal) |
229 | 239 | } else { |
230 | 240 | formattedStr.WriteString(template[i:j]) |
|
0 commit comments