-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consider wide unicode characters to be size of 2 (#1237)
closes #260
- Loading branch information
Showing
3 changed files
with
59 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* Copyright (c) Microsoft Corporation. | ||
* Under MIT License | ||
* From https://github.com/PowerShell/PowerShell/tree/master | ||
*/ | ||
|
||
namespace CSharpier.Utilities; | ||
|
||
internal static class CharacterSizeCalculator | ||
{ | ||
// csharpier-ignore | ||
public static int CalculateWidth(char c) | ||
{ | ||
// The following is based on http://www.cl.cam.ac.uk/~mgk25/c/wcwidth.c | ||
// which is derived from https://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt | ||
var isWide = c >= 0x1100 && | ||
(c <= 0x115f || /* Hangul Jamo init. consonants */ | ||
c == 0x2329 || c == 0x232a || | ||
((uint)(c - 0x2e80) <= (0xa4cf - 0x2e80) && | ||
c != 0x303f) || /* CJK ... Yi */ | ||
((uint)(c - 0xac00) <= (0xd7a3 - 0xac00)) || /* Hangul Syllables */ | ||
((uint)(c - 0xf900) <= (0xfaff - 0xf900)) || /* CJK Compatibility Ideographs */ | ||
((uint)(c - 0xfe10) <= (0xfe19 - 0xfe10)) || /* Vertical forms */ | ||
((uint)(c - 0xfe30) <= (0xfe6f - 0xfe30)) || /* CJK Compatibility Forms */ | ||
((uint)(c - 0xff00) <= (0xff60 - 0xff00)) || /* Fullwidth Forms */ | ||
((uint)(c - 0xffe0) <= (0xffe6 - 0xffe0))); | ||
|
||
// We can ignore these ranges because .Net strings use surrogate pairs | ||
// for this range and we do not handle surrogate pairs. | ||
// (c >= 0x20000 && c <= 0x2fffd) || | ||
// (c >= 0x30000 && c <= 0x3fffd) | ||
return isWide ? 2 : 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters