csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.5 KiB
52 lines
1.5 KiB
// Copyright (c) The Avalonia Project. All rights reserved.
|
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|
|
|
using System.Globalization;
|
|
using System.Text;
|
|
|
|
namespace Avalonia.Utilities
|
|
{
|
|
public static class IdentifierParser
|
|
{
|
|
public static string Parse(CharacterReader r)
|
|
{
|
|
if (IsValidIdentifierStart(r.Peek))
|
|
{
|
|
var result = new StringBuilder();
|
|
|
|
while (!r.End && IsValidIdentifierChar(r.Peek))
|
|
{
|
|
result.Append(r.Take());
|
|
}
|
|
|
|
return result.ToString();
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private static bool IsValidIdentifierStart(char c)
|
|
{
|
|
return char.IsLetter(c) || c == '_';
|
|
}
|
|
|
|
private static bool IsValidIdentifierChar(char c)
|
|
{
|
|
if (IsValidIdentifierStart(c))
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
var cat = CharUnicodeInfo.GetUnicodeCategory(c);
|
|
return cat == UnicodeCategory.NonSpacingMark ||
|
|
cat == UnicodeCategory.SpacingCombiningMark ||
|
|
cat == UnicodeCategory.ConnectorPunctuation ||
|
|
cat == UnicodeCategory.Format ||
|
|
cat == UnicodeCategory.DecimalDigitNumber;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|