-
-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String format compatibility #173
Merged
axunonb
merged 30 commits into
axuno:version/v3.0
from
axunonb:string-format-compatibility
May 30, 2021
Merged
String format compatibility #173
axunonb
merged 30 commits into
axuno:version/v3.0
from
axunonb:string-format-compatibility
May 30, 2021
Conversation
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
…ngFormatCompatibility
axunonb
added a commit
to axunonb/SmartFormat
that referenced
this pull request
Mar 10, 2022
* 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)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
string.Format
compatibilityParserSettings.UseStringFormatCompatibility
toSettings.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):
Custom formatters of SmartFormat are not parsed and thus cannot be used
Curly braces are escaped the
string.Format
way with{{
and}}
(){}:\
) are escaped, any character is allowed anywhere. Now this applies also for the colon. Example (note the escaped colon):string[] formatterExtensionNames
any moreformatterExtensionNames
as argumentParser.ParseFormat
does not check for a valid formatter name (it's implemented in the formatter anyway)