-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Update CharUnicodeInfo to Unicode 12.1; update StringInfo to UAX29 #328
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
Merged
GrabYourPitchforks
merged 8 commits into
dotnet:master
from
GrabYourPitchforks:charunicodeinfo
Jan 14, 2020
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f813a2b
Update CharUnicodeInfo to Unicode 12.1; update StringInfo to UAX29
GrabYourPitchforks 0a322f4
Use runtime-assets package instead of checking in new UCD files
GrabYourPitchforks b0bfc14
Merge remote-tracking branch 'origin/master' into charunicodeinfo
GrabYourPitchforks f5533a7
React to package renames
GrabYourPitchforks f007969
Remove eager allocations in UnicodeDebug
GrabYourPitchforks 596ea4c
PR feedback
GrabYourPitchforks 0d29483
Delete duplicate implementation in GenUnicodeProp
GrabYourPitchforks 838d318
Merge remote-tracking branch 'origin/master' into charunicodeinfo
GrabYourPitchforks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
119 changes: 119 additions & 0 deletions
119
src/coreclr/src/System.Private.CoreLib/Tools/GenUnicodeProp/CategoryCasingInfo.cs
This file contains hidden or 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,119 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Buffers.Binary; | ||
| using System.Globalization; | ||
| using System.Text; | ||
| using System.Text.Unicode; | ||
|
|
||
| namespace GenUnicodeProp | ||
| { | ||
| /// <summary> | ||
| /// Contains information about a code point's Unicode category, | ||
| /// bidi class, and simple case mapping / folding. | ||
| /// </summary> | ||
| internal sealed class CategoryCasingInfo : IEquatable<CategoryCasingInfo> | ||
| { | ||
| private readonly (UnicodeCategory generalCategory, | ||
| StrongBidiCategory strongBidiCategory, | ||
| ushort offsetToSimpleUppercase, | ||
| ushort offsetToSimpleLowercase, | ||
| ushort offsetToSimpleTitlecase, | ||
| ushort offsetToSimpleCasefold, | ||
| bool isWhitespace) _data; | ||
|
|
||
| public CategoryCasingInfo(CodePoint codePoint) | ||
| { | ||
| _data.generalCategory = codePoint.GeneralCategory; | ||
|
|
||
| switch (codePoint.BidiClass) | ||
| { | ||
| case BidiClass.Left_To_Right: | ||
| _data.strongBidiCategory = StrongBidiCategory.StrongLeftToRight; | ||
| break; | ||
|
|
||
| case BidiClass.Right_To_Left: | ||
| case BidiClass.Arabic_Letter: | ||
| _data.strongBidiCategory = StrongBidiCategory.StrongRightToLeft; | ||
| break; | ||
|
|
||
| default: | ||
| _data.strongBidiCategory = StrongBidiCategory.Other; | ||
| break; | ||
| } | ||
|
|
||
| if (Program.IncludeCasingData) | ||
| { | ||
| _data.offsetToSimpleUppercase = (ushort)(codePoint.SimpleUppercaseMapping - codePoint.Value); | ||
| _data.offsetToSimpleLowercase = (ushort)(codePoint.SimpleLowercaseMapping - codePoint.Value); | ||
| _data.offsetToSimpleTitlecase = (ushort)(codePoint.SimpleTitlecaseMapping - codePoint.Value); | ||
| _data.offsetToSimpleCasefold = (ushort)(codePoint.SimpleCaseFoldMapping - codePoint.Value); | ||
| } | ||
| else | ||
| { | ||
| _data.offsetToSimpleUppercase = default; | ||
| _data.offsetToSimpleLowercase = default; | ||
| _data.offsetToSimpleTitlecase = default; | ||
| _data.offsetToSimpleCasefold = default; | ||
| } | ||
|
|
||
| _data.isWhitespace = codePoint.Flags.HasFlag(CodePointFlags.White_Space); | ||
| } | ||
|
|
||
| public override bool Equals(object obj) => Equals(obj as CategoryCasingInfo); | ||
|
|
||
| public bool Equals(CategoryCasingInfo other) | ||
| { | ||
| return !(other is null) && this._data.Equals(other._data); | ||
| } | ||
|
|
||
| public override int GetHashCode() | ||
| { | ||
| return _data.GetHashCode(); | ||
| } | ||
|
|
||
| public static byte[] ToCategoryBytes(CategoryCasingInfo input) | ||
| { | ||
| // We're storing 3 pieces of information in 8 bits: | ||
| // bit 7 (high bit) = isWhitespace? | ||
| // bits 6..5 = restricted bidi class | ||
| // bits 4..0 = Unicode category | ||
|
|
||
| int combinedValue = Convert.ToInt32(input._data.isWhitespace) << 7; | ||
| combinedValue += (int)input._data.strongBidiCategory << 5; | ||
| combinedValue += (int)input._data.generalCategory; | ||
|
|
||
| return new byte[] { checked((byte)combinedValue) }; | ||
| } | ||
|
|
||
| public static byte[] ToUpperBytes(CategoryCasingInfo input) | ||
| { | ||
| byte[] bytes = new byte[sizeof(ushort)]; | ||
| BinaryPrimitives.WriteUInt16LittleEndian(bytes, input._data.offsetToSimpleUppercase); | ||
| return bytes; | ||
| } | ||
|
|
||
| public static byte[] ToLowerBytes(CategoryCasingInfo input) | ||
| { | ||
| byte[] bytes = new byte[sizeof(ushort)]; | ||
| BinaryPrimitives.WriteUInt16LittleEndian(bytes, input._data.offsetToSimpleLowercase); | ||
| return bytes; | ||
| } | ||
|
|
||
| public static byte[] ToTitleBytes(CategoryCasingInfo input) | ||
| { | ||
| byte[] bytes = new byte[sizeof(ushort)]; | ||
| BinaryPrimitives.WriteUInt16LittleEndian(bytes, input._data.offsetToSimpleTitlecase); | ||
| return bytes; | ||
| } | ||
|
|
||
| public static byte[] ToCaseFoldBytes(CategoryCasingInfo input) | ||
| { | ||
| byte[] bytes = new byte[sizeof(ushort)]; | ||
| BinaryPrimitives.WriteUInt16LittleEndian(bytes, input._data.offsetToSimpleCasefold); | ||
| return bytes; | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
69 changes: 69 additions & 0 deletions
69
src/coreclr/src/System.Private.CoreLib/Tools/GenUnicodeProp/NumericGraphemeInfo.cs
This file contains hidden or 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,69 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Buffers.Binary; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Text.Unicode; | ||
|
|
||
| namespace GenUnicodeProp | ||
| { | ||
| /// <summary> | ||
| /// Contains information about a code point's numeric representation | ||
| /// and the manner in which it's treated for grapheme cluster segmentation | ||
| /// purposes. | ||
| /// </summary> | ||
| internal sealed class NumericGraphemeInfo : IEquatable<NumericGraphemeInfo> | ||
| { | ||
| public readonly (int decimalDigitValue, | ||
| int digitValue, | ||
| double numericValue, | ||
| GraphemeClusterBreakProperty graphemeClusterBreakProperty) _data; | ||
|
|
||
| public NumericGraphemeInfo(CodePoint codePoint) | ||
| { | ||
| _data.decimalDigitValue = codePoint.DecimalDigitValue; | ||
| _data.digitValue = codePoint.DigitValue; | ||
| _data.numericValue = codePoint.NumericValue; | ||
| _data.graphemeClusterBreakProperty = codePoint.GraphemeClusterBreakProperty; | ||
| } | ||
|
|
||
| public override bool Equals(object obj) => Equals(obj as NumericGraphemeInfo); | ||
|
|
||
| public bool Equals(NumericGraphemeInfo other) | ||
| { | ||
| return !(other is null) && this._data.Equals(other._data); | ||
| } | ||
|
|
||
| public override int GetHashCode() | ||
| { | ||
| return _data.GetHashCode(); | ||
| } | ||
|
|
||
| public static byte[] ToDigitBytes(NumericGraphemeInfo input) | ||
| { | ||
| // Bits 4 .. 7 contain (decimalDigitValue + 1). | ||
| // Bits 0 .. 3 contain (digitValue + 1). | ||
| // This means that each nibble will have a value 0x0 .. 0xa, inclusive. | ||
|
|
||
| int adjustedDecimalDigitValue = input._data.decimalDigitValue + 1; | ||
| int adjustedDigitValue = input._data.digitValue + 1; | ||
|
|
||
| return new byte[] { (byte)((adjustedDecimalDigitValue << 4) | adjustedDigitValue) }; | ||
| } | ||
|
|
||
| public static byte[] ToNumericBytes(NumericGraphemeInfo input) | ||
| { | ||
| byte[] bytes = new byte[sizeof(double)]; | ||
| double value = input._data.numericValue; | ||
| BinaryPrimitives.WriteUInt64LittleEndian(bytes, Unsafe.As<double, ulong>(ref value)); | ||
| return bytes; | ||
| } | ||
|
|
||
| public static byte[] ToGraphemeBytes(NumericGraphemeInfo input) | ||
| { | ||
| return new byte[] { checked((byte)input._data.graphemeClusterBreakProperty) }; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to add a dependency to eng/Version.Details.xml so that the version gets auto-updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1731 is out. Thanks for catching this! :)