Made the character inspector use the new code point enumerator.

This commit is contained in:
GoldenCrystal
2014-11-01 02:26:35 +01:00
parent f8742d9dad
commit fe01c38387
2 changed files with 14 additions and 5 deletions
@@ -6,6 +6,7 @@ using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnicodeInformation;
namespace UnicodeCharacterInspector
{
@@ -118,16 +119,18 @@ namespace UnicodeCharacterInspector
int index = 0;
if (!string.IsNullOrEmpty(value))
{
var enumerator = StringInfo.GetTextElementEnumerator(value);
while (enumerator.MoveNext())
foreach (int codePoint in value.AsCodePointEnumerable())
{
if (index >= characters.Length) Array.Resize(ref characters, characters.Length * 2);
// We don't replace pre-existing elements if they already have the correct value.
// This should help a bit with GC, by making new string elements as short-lived as possible.
string element = enumerator.GetTextElement();
if (characters[index] != element) characters[index] = element;
string oldCodePointValue = characters[index];
if (oldCodePointValue == null || char.ConvertToUtf32(oldCodePointValue, 0) != codePoint)
{
characters[index] = char.ConvertFromUtf32(codePoint);
}
++index;
}
@@ -78,6 +78,12 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\UnicodeInformation\UnicodeInformation.csproj">
<Project>{cb722958-a1c4-4121-804b-7d5a671491b1}</Project>
<Name>UnicodeInformation</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.