forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSharpHelpers.cs
More file actions
44 lines (39 loc) · 1.56 KB
/
Copy pathCSharpHelpers.cs
File metadata and controls
44 lines (39 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Globalization;
namespace System.Web.Razor.Tokenizer
{
public static class CSharpHelpers
{
// CSharp Spec §2.4.2
public static bool IsIdentifierStart(char character)
{
return Char.IsLetter(character) ||
character == '_' ||
Char.GetUnicodeCategory(character) == UnicodeCategory.LetterNumber; // Ln
}
public static bool IsIdentifierPart(char character)
{
return Char.IsDigit(character) ||
IsIdentifierStart(character) ||
IsIdentifierPartByUnicodeCategory(character);
}
public static bool IsRealLiteralSuffix(char character)
{
return character == 'F' ||
character == 'f' ||
character == 'D' ||
character == 'd' ||
character == 'M' ||
character == 'm';
}
private static bool IsIdentifierPartByUnicodeCategory(char character)
{
UnicodeCategory category = Char.GetUnicodeCategory(character);
return category == UnicodeCategory.NonSpacingMark || // Mn
category == UnicodeCategory.SpacingCombiningMark || // Mc
category == UnicodeCategory.ConnectorPunctuation || // Pc
category == UnicodeCategory.Format; // Cf
}
}
}