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

Alignment option always available #174

Merged
merged 27 commits into from
Jun 4, 2021

Conversation

axunonb
Copy link
Member

@axunonb axunonb commented Jun 4, 2021

Refactored implementation for string alignment
Example: Smart.Format("{placeholder,15}") where ",15" is the string alignment

  • Modified ListFormatter so that items can be aligned, but the spacers stay untouched
  • IFormattingInfo.Alignment now returns the alignment of the current Placeholder, or - if this is null - the Alignment of any parent IFormattingInfo that is not zero.
  • Aligment is now implemented into class FormattingInfo, so it is always available. Former implementation in DefaultFormatter is removed.
  • Introduced FormatterSettings.AlignmentFillCharacter, to the the fill character can be customized. Default is space (0x20), like with string.Format.
  • Renamed IFormattingInfo.Write(Format format, object value) to FormatAsChild(Format format, object value) to make clear that nothing is written to IOutput (this happens in a next step).
  • Added dedicated AlignmentTests

axunonb and others added 27 commits April 17, 2021 10:25
@axunonb axunonb merged commit d6e2a26 into axuno:version/v3.0 Jun 4, 2021
@codecov
Copy link

codecov bot commented Jun 4, 2021

Codecov Report

Merging #174 (1e1cb89) into version/v3.0 (31735db) will decrease coverage by 0%.
The diff coverage is 96%.

Impacted file tree graph

@@             Coverage Diff             @@
##           version/v3.0   #174   +/-   ##
===========================================
- Coverage            95%    95%   -0%     
===========================================
  Files                42     43    +1     
  Lines              1835   1843    +8     
===========================================
+ Hits               1744   1750    +6     
- Misses               91     93    +2     
Impacted Files Coverage Δ
src/SmartFormat/Core/Formatting/FormattingInfo.cs 92% <88%> (-2%) ⬇️
src/SmartFormat/Core/Settings/FormatterSettings.cs 100% <100%> (ø)
src/SmartFormat/Extensions/ChooseFormatter.cs 100% <100%> (ø)
src/SmartFormat/Extensions/ConditionalFormatter.cs 99% <100%> (ø)
src/SmartFormat/Extensions/DefaultFormatter.cs 89% <100%> (-3%) ⬇️
src/SmartFormat/Extensions/DefaultSource.cs 100% <100%> (ø)
src/SmartFormat/Extensions/IsMatchFormatter.cs 93% <100%> (ø)
src/SmartFormat/Extensions/ListFormatter.cs 100% <100%> (ø)
...rtFormat/Extensions/PluralLocalizationFormatter.cs 95% <100%> (ø)
src/SmartFormat/Extensions/TemplateFormatter.cs 83% <100%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 31735db...1e1cb89. Read the comment docs.

@axunonb axunonb deleted the alignment-option-always-available branch June 4, 2021 08:58
axunonb added a commit that referenced this pull request Aug 27, 2021
#### Target frameworks

* Changed `netstandard2.0` to `netstandard2.1`.
* `net461` support unchanged.
* Added package `System.Memory`

#### Remove repetitive substring allocations

Connected modifications:

* Added method `Write(ReadOnlySpan<char> text)` to `IFormattingInfo`
* Generated substrings are cached in classes `Format`, `FormatItem`, `LiteralText`, `Placeholder` and `Selector`.
* Evaluating escaped characters for `Placeholder.FormatterOptions` and `LiteralText` work without heap memory allocation.

#### Alignment operator inheritance is optimized

* Alignment implementation introduced with PR [#174](#174) is modified for better performance
* Added method `Placeholder.AddSelector`
* `Placeholder.Selectors` is now internal. Selectors are accessible with `IReadOnlyList<Selector> Placeholder.GetSelectors()`.

#### DictionarySource performance improved

* Implemented suggestion in issue [#186](#186) for better speed and less GC pressure.
* Side effect: We're using the `CaseSensitivityType` of the dictionary for getting the value for a key. `Settings.GetCaseSensitivityComparison()` will not be applied.
axunonb added a commit to axunonb/SmartFormat that referenced this pull request Mar 10, 2022
**Refactored implementation for string alignment** 
Example: `Smart.Format("{placeholder,15}")` where ",15" is the string alignment

* Modified `ListFormatter` so that items can be aligned, but the spacers stay untouched
* `IFormattingInfo.Alignment` now returns the alignment of the current `Placeholder`, or - if this is null - the `Alignment` of any parent `IFormattingInfo` that is not zero.
* Aligment is now implemented into class `FormattingInfo`, so it is always available. Former implementation in `DefaultFormatter` is removed.
* Introduced `FormatterSettings.AlignmentFillCharacter`, to the the fill character can be customized. Default is space (0x20), like with `string.Format`.
* Renamed `IFormattingInfo.Write(Format format, object value)` to `FormatAsChild(Format format, object value)` to make clear that nothing is written to `IOutput` (this happens in a next step).
* Added dedicated AlignmentTests
axunonb added a commit to axunonb/SmartFormat that referenced this pull request Mar 10, 2022
#### Target frameworks

* Changed `netstandard2.0` to `netstandard2.1`.
* `net461` support unchanged.
* Added package `System.Memory`

#### Remove repetitive substring allocations

Connected modifications:

* Added method `Write(ReadOnlySpan<char> text)` to `IFormattingInfo`
* Generated substrings are cached in classes `Format`, `FormatItem`, `LiteralText`, `Placeholder` and `Selector`.
* Evaluating escaped characters for `Placeholder.FormatterOptions` and `LiteralText` work without heap memory allocation.

#### Alignment operator inheritance is optimized

* Alignment implementation introduced with PR [axuno#174](axuno#174) is modified for better performance
* Added method `Placeholder.AddSelector`
* `Placeholder.Selectors` is now internal. Selectors are accessible with `IReadOnlyList<Selector> Placeholder.GetSelectors()`.

#### DictionarySource performance improved

* Implemented suggestion in issue [axuno#186](axuno#186) for better speed and less GC pressure.
* Side effect: We're using the `CaseSensitivityType` of the dictionary for getting the value for a key. `Settings.GetCaseSensitivityComparison()` will not be applied.
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