forked from axuno/SmartFormat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
String format compatibility (axuno#173)
* Separated SmartFormat features from `string.Format`compatibility * Moved `ParserSettings.UseStringFormatCompatibility` to `Settings.UseStringFormatCompatibility` because this does no more apply to the parser only. * `string.Format` compatibility: * SmartFormat acts as a drop-in replacement, and on top allows for named placeholders besides indexed placeholders. Example (note the colon is not escaped): * ```csharp var now = DateTime.Now; var smartFmt = "It is now {Date:yyyy/MM/dd HH:mm:ss}"; var stringFmt = $"It is now {now.Date:yyyy/MM/dd HH:mm:ss}"; var formatter = Smart.CreateDefaultSmartFormat(); formatter.Settings.UseStringFormatCompatibility = true; Assert.That(formatter.Format(smartFmt, now), Is.EqualTo(stringFmt)); ``` * Custom formatters of SmartFormat are not parsed and thus cannot be used * Curly braces are escaped the `string.Format` way with `{{` and `}}` * SmartFormat added feature: * As long as special characters (`(){}:\`) are escaped, any character is allowed anywhere. Now this applies also for the colon. Example (note the escaped colon): * ```Csharp var now = DateTime.Now; var smartFmt = @"It is now {Date:yyyy/MM/dd HH\:mm\:ss}"; var stringFmt = $"It is now {now.Date:yyyy/MM/dd HH:mm:ss}"; var formatter = Smart.CreateDefaultSmartFormat(); formatter.Settings.UseStringFormatCompatibility = false; Assert.That(formatter.Format(smartFmt, now), Is.EqualTo(stringFmt)); ``` * Tests are modified occordingly * Parser does not process `string[] formatterExtensionNames` any more * CTOR does not take `formatterExtensionNames` as argument * `Parser.ParseFormat` does not check for a valid formatter name (it's implemented in the formatter anyway)
- Loading branch information
Showing
15 changed files
with
187 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.