diff --git a/internal/parser.go b/internal/parser.go index 9bcb499..d080aef 100644 --- a/internal/parser.go +++ b/internal/parser.go @@ -122,6 +122,19 @@ func Parse(text string) string { } if s == '}' { + countBracketInRow := 0 + for i := 0; ; i++ { + if index+i < formatLen && text[index+i] != '}' { + break + } + countBracketInRow++ + } + + if countBracketInRow > 2 { + index += countBracketInRow - 2 - 1 + continue + } + endBracketFound = true continue } diff --git a/tests/parser_test.go b/tests/parser_test.go index b9c7f82..8d00995 100644 --- a/tests/parser_test.go +++ b/tests/parser_test.go @@ -6,6 +6,11 @@ import ( "github.com/i582/cfmt" ) +type TestStruct struct { + field1 string + field2 int +} + func TestParse(t *testing.T) { cfmt.RegisterStyle("code", func(s string) string { return cfmt.Sprintf("{{%s}}::red|underline", s) @@ -20,4 +25,6 @@ func TestParse(t *testing.T) { cfmt.Println(cfmt.Sprint("{{blink group}}::blink")) cfmt.Printf("{{hex %s}}::#ff00ff sfas\n", "color group") cfmt.Printf(cfmt.Sprintf("{{background color %s}}::bg#ffff00\n", "hex color")) + cfmt.Printf("{{{hello}}}::red|underline\n") + cfmt.Printf("{{some test struct: %v}}::red|underline\n", TestStruct{"hello", 1}) }