Improved compatibility of Format String #30
Merged
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.
BCL-Compatibility
The format of ZString has some incompatibility with BCL.
The main missing piece is the "Alignment Component".
There are also differences in the handling of whitespace and incorrect formatting.
Some of the cases are listed below.
String.Format
ZString.Format
Test("{0,10:X}{{0}}{1,-10:c}", Guid.NewGuid(), DateTime.Now.TimeOfDay.Negate());
Test("{1,-1}{0,1}", Int64.MinValue, Int64.MaxValue);
"9223372036854775807-9223372036854775808"
"-1-1"
Test("{00 , 01 }, {01 ,02 }, {2 ,3 :D }, {3 ,4: X }", 2, 3, 5, 7)
Test("}")
Test("{ 0,0}, 9999")
"9999"
I have added a test in CompositeFormatTest.cs that you can check out.
Performance
I've refactored the formatting parsing process.
As a side effect, it makes most of the parsing process about 20% faster. (compared to ver 2.2.0)
However, in the case of short format string (like
x:{0}, y:{1}
), Utf16PreparedFormat and Utf8PreparedFormat are about 20% slower.I have optimized the PreparedFormat class, but Utf16PreparedFormat is still slow.
Format is acceptable because the impact is limited.
FormatBenchmark.cs
BuiltinTypesBenchmark.cs