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

Better separation of built-in string.Format and Smart.Format features #175

Merged
merged 1 commit into from
Jun 4, 2021

Conversation

axunonb
Copy link
Member

@axunonb axunonb commented Jun 4, 2021

Better separation of built-in string.Format and Smart.Format features

1. Settings.StringFormatCompatibility == true

  • In this mode, SmartFormat is a drop-in replacement for string.Format regarding formatting syntax.
  • Curly braces {} must be escaped with double braces {{ and }}
  • The Parser will not include the formatter name or formatting options. Like with string.Format, everything after the Selector separator (colon) is considered as format specifier.
  • DefaultFormatter is the only formatter which will be invoked.
  • Even in compatibility mode, SmartFormat will
    • Process named Placeholders (beside indexed Placeholders)
    • have ISources available for Placeholders.
    • be able to process escaped string literals like \n, \U1234 etc.

2. Settings.StringFormatCompatibility == false

  • Makes full use of all SmartFormat features
  • Any character can be used, as long as few special characters are escaped with a backslash \. These are e.g. {}()[]():..
  • This leads to a slightly different format string syntax. Example: string.Format("It is now {0:yyyy/MM/dd HH:mm:ss}, DateTime.Now) vs. Smart.Format("It is now {Date:yyyy/MM/dd HH\:mm\:ss}, DateTime.Now).

3. All modes

  • It is possible to use a System.IFormatProvider as argument to Smart.Format - same as with string.Format. This custom format provider can in turn call a System.ICustomFormatter for special formatting needs.
  • This feature is implemented in the DefaultFormatter.

@axunonb axunonb added this to the version/v3 milestone Jun 4, 2021
@axunonb axunonb merged commit 7f8725e into version/v3.0 Jun 4, 2021
@axunonb axunonb deleted the string-vs-smart-format-features branch June 4, 2021 22:07
axunonb added a commit to axunonb/SmartFormat that referenced this pull request Mar 10, 2022
…axuno#175)

#### Better separation of built-in string.Format and Smart.Format features

1. Settings.StringFormatCompatibility == true

* In this mode, *SmartFormat* is a drop-in replacement for `string.Format` regarding formatting syntax.
* Curly braces `{}` **must** be escaped with double braces `{{` and `}}`
* The `Parser` will not include the formatter name or formatting options. Like with `string.Format`, everything after the `Selector` separator (colon) is considered as format specifier.
* `DefaultFormatter` is the only formatter which will be invoked.
* Even in compatibility mode, *SmartFormat* will
  * Process named `Placeholder`s (beside indexed `Placeholder`s)
  * have `ISource`s available for `Placeholder`s.
  * be able to process escaped string literals like \n, \U1234 etc.

2. Settings.StringFormatCompatibility == false

* Makes full use of all *SmartFormat* features
* Any character can be used, as long as few special characters are escaped with a backslash `\`. These are e.g. `{}()[]():.`.
* This leads to a slightly different format string syntax. Example: `string.Format("It is now {0:yyyy/MM/dd HH:mm:ss}, DateTime.Now)` vs. `Smart.Format("It is now {Date:yyyy/MM/dd HH\:mm\:ss}, DateTime.Now)`.

3. All modes

* It is possible to use a `System.IFormatProvider` as argument to `Smart.Format` - same as with `string.Format`. This custom format provider can in turn call a `System.ICustomFormatter` for special formatting needs.
* This feature is implemented in the `DefaultFormatter`.
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