axuno / SmartFormat

A lightweight text templating library written in C# which can be a drop-in replacement for string.Format
Other
1.1k stars 105 forks source link

Double ending braces aren't parsed well #84

Closed ghost closed 7 years ago

ghost commented 7 years ago

There is problem with double ending braces parsing. E.g if I provide Account {Type:choose(Days|Entries):days balance: {Value}|entries left: {Value} {Value:plural(en):entry|entries}|expiration date: {Value:d}} as a format string, the result is not satisfying. When I divide two braces with space (eg Account {Type:choose(Days|Entries):days balance: {Value}|entries left: {Value} {Value:plural(en):entry|entries}|expiration date: {Value:d} } ) everything works pretty well except that the space is also in result string. I think it is a bug and wanted you to know about it.

axunonb commented 7 years ago

By default SmartFormat.NET uses {{ and }} for escaping braces in favor of compatibility with string.Format. However, this does not work very well with nested placeholders, So it is recommended to set Smart.Default.Parser.UseBraceEscaping() and escape braces with \{ or \} respectively. \ is the alternative escape character. Have a look at the Wiki / Common Pitfalls for more details. Let me know if this has worked in your case as well, please.

axunonb commented 7 years ago

So in short: Set Smart.Default.Parser.UseBraceEscaping() as soon as you're using complex formatters, use the default behavior in order to have string.Format compatibility.

ghost commented 7 years ago

Thank you so much 👍