Repository navigation
Tabular output is not displayed correctly for non-Latin chars - #3922
Conversation
GetWidth should be replaced to wcwidth GetWidth
8942053 to
a9ee8e2
Compare
DavidKarlas
left a comment
There was a problem hiding this comment.
Looks OK, I suggested few improvements and maybe some comments explaining things.
|
|
||
| int desiredLength = maxLength - ShrinkReplacement.Length; | ||
| int possibleLength = 1; | ||
| while (text.Substring(0, possibleLength).GetUnicodeLength() <= desiredLength) |
There was a problem hiding this comment.
I wonder if it would make sense performance wise, to start with desiredLength and do possibleLength-- and go towards zero...
There was a problem hiding this comment.
I updated this to remove allocations. Starting from the beginning and moving one by one, we also calculate each character's length only once now, so it should be much better performance wise.
| { | ||
| internal static int GetUnicodeLength (this string s) | ||
| { | ||
| return s.Sum(ch => Wcwidth.UnicodeCalculator.GetWidth((int)ch)); |
There was a problem hiding this comment.
Nit: For some reason I'm not impressed with using lambda here because perf, maybe I'm wrong... We can also improve Utf16->32 story here by doing:
var sum = 0;
foreach (Rune rune in s.EnumerateRunes())
{
sum += Wcwidth.UnicodeCalculator.GetWidth(rune.Value);
}
return sum;
There was a problem hiding this comment.
Rune's are not available in .NET Standard, unfortunately, which we target.
Replaced the Sum with a for loop.
| for (int j = 0; j < columnIndexes.Length; j++) | ||
| { | ||
| parsedRow.Add(lines[i].Substring(columnsIndexes[j], columnsIndexes[j + 1] - columnsIndexes[j]).Trim()); | ||
| int unfilledColumnWidth = (j == columnIndexes.Length - 1 ? line.Length : columnIndexes[j + 1] ) - columnIndexes[j]; |
There was a problem hiding this comment.
Can this part dealing with cutting code into helper static method?
…#3922) * Reference Wcwidth.Sources package * Default to Utf8 encoding if used as sub-process (https://dev.azure.com/devdiv/DevDiv/_wiki/wikis/DevDiv.wiki/4236/Character-Encoding-Issues?anchor=.net) * Disable stylecop rules for source package references Co-authored-by: Vlada Shubina <[email protected]> # Conflicts: # eng/Versions.props
* Reference Wcwidth.Sources package * Default to Utf8 encoding if used as sub-process (https://dev.azure.com/devdiv/DevDiv/_wiki/wikis/DevDiv.wiki/4236/Character-Encoding-Issues?anchor=.net) * Disable stylecop rules for source package references Co-authored-by: Vlada Shubina <[email protected]> # Conflicts: # eng/Versions.props
…/templating#3922) * Reference Wcwidth.Sources package * Default to Utf8 encoding if used as sub-process (https://dev.azure.com/devdiv/DevDiv/_wiki/wikis/DevDiv.wiki/4236/Character-Encoding-Issues?anchor=.net) * Disable stylecop rules for source package references Co-authored-by: Vlada Shubina <[email protected]> Commit migrated from dotnet/templating@48f5e83
Problem
Fixes #3288
Solution
Take into account that a single character may not always occupy 1 space in the console.
Checks:
#nullable enableto all the modified files ?