Skip to content
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
merged 30 commits into from
May 30, 2021

Conversation

axunonb
Copy link
Member

@axunonb axunonb commented May 30, 2021

  • Separated SmartFormat features from string.Formatcompatibility
  • 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):

    •        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):
    •        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)

axunonb and others added 30 commits April 17, 2021 10:25
@axunonb axunonb merged commit bded4c6 into axuno:version/v3.0 May 30, 2021
@axunonb axunonb deleted the string-format-compatibility branch May 30, 2021 20:20
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant