1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
- using System . Diagnostics ;
5
4
using System . Runtime . CompilerServices ;
6
5
using System . Text ;
7
6
@@ -13,10 +12,10 @@ internal static bool IsNormalized(ReadOnlySpan<char> source, NormalizationForm n
13
12
{
14
13
CheckNormalizationForm ( normalizationForm ) ;
15
14
16
- // In Invariant mode we assume all characters are normalized.
17
- if ( GlobalizationMode . Invariant || source . IsEmpty || Ascii . IsValid ( source ) )
15
+ // In Invariant mode we assume all characters are normalized because we don't support any linguistic operations on strings.
16
+ // If it's ASCII && one of the 4 main forms, then it's already normalized.
17
+ if ( GlobalizationMode . Invariant || Ascii . IsValid ( source ) )
18
18
{
19
- // This is because we don't support any linguistic operation on the strings
20
19
return true ;
21
20
}
22
21
@@ -29,10 +28,10 @@ internal static string Normalize(string strInput, NormalizationForm normalizatio
29
28
{
30
29
CheckNormalizationForm ( normalizationForm ) ;
31
30
32
- if ( GlobalizationMode . Invariant )
31
+ // In Invariant mode we assume all characters are normalized because we don't support any linguistic operations on strings.
32
+ // If it's ASCII && one of the 4 main forms, then it's already normalized.
33
+ if ( GlobalizationMode . Invariant || Ascii . IsValid ( strInput ) )
33
34
{
34
- // In Invariant mode we assume all characters are normalized.
35
- // This is because we don't support any linguistic operation on the strings
36
35
return strInput ;
37
36
}
38
37
@@ -45,17 +44,10 @@ internal static bool TryNormalize(ReadOnlySpan<char> source, Span<char> destinat
45
44
{
46
45
CheckNormalizationForm ( normalizationForm ) ;
47
46
48
- if ( source . IsEmpty )
49
- {
50
- charsWritten = 0 ;
51
- return true ;
52
- }
53
-
47
+ // In Invariant mode we assume all characters are normalized because we don't support any linguistic operations on strings.
48
+ // If it's ASCII && one of the 4 main forms, then it's already normalized.
54
49
if ( GlobalizationMode . Invariant || Ascii . IsValid ( source ) )
55
50
{
56
- // In Invariant mode we assume all characters are normalized.
57
- // This is because we don't support any linguistic operation on the strings
58
-
59
51
if ( source . TryCopyTo ( destination ) )
60
52
{
61
53
charsWritten = source . Length ;
@@ -75,10 +67,10 @@ internal static int GetNormalizedLength(this ReadOnlySpan<char> source, Normaliz
75
67
{
76
68
CheckNormalizationForm ( normalizationForm ) ;
77
69
78
- if ( GlobalizationMode . Invariant || source . IsEmpty || Ascii . IsValid ( source ) )
70
+ // In Invariant mode we assume all characters are normalized because we don't support any linguistic operations on strings.
71
+ // If it's ASCII && one of the 4 main forms, then it's already normalized.
72
+ if ( GlobalizationMode . Invariant || Ascii . IsValid ( source ) )
79
73
{
80
- // In Invariant mode we assume all characters are normalized.
81
- // This is because we don't support any linguistic operation on the strings
82
74
return source . Length ;
83
75
}
84
76
0 commit comments