Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
StringInfo.cs
Go to the documentation of this file.
1
using
System.Collections.Generic
;
2
using
System.Diagnostics.CodeAnalysis
;
3
using
System.Text.Unicode
;
4
5
namespace
System.Globalization
;
6
7
public
class
StringInfo
8
{
9
private
string
_str
;
10
11
private
int
[]
_indexes
;
12
13
private
int
[]?
Indexes
14
{
15
get
16
{
17
if
(
_indexes
==
null
&&
String
.
Length
> 0)
18
{
19
_indexes
=
ParseCombiningCharacters
(
String
);
20
}
21
return
_indexes
;
22
}
23
}
24
25
public
string
String
26
{
27
get
28
{
29
return
_str
;
30
}
31
[
MemberNotNull
(
"_str"
)]
32
set
33
{
34
_str
=
value
??
throw
new
ArgumentNullException
(
"value"
);
35
_indexes
=
null
;
36
}
37
}
38
39
public
int
LengthInTextElements
40
{
41
get
42
{
43
int
[]?
indexes
=
Indexes
;
44
if
(
indexes
==
null
)
45
{
46
return
0;
47
}
48
return
indexes
.Length;
49
}
50
}
51
52
public
StringInfo
()
53
:
this
(
string
.
Empty
)
54
{
55
}
56
57
public
StringInfo
(
string
value
)
58
{
59
String
=
value
;
60
}
61
62
public
override
bool
Equals
([
NotNullWhen
(
true
)]
object
?
value
)
63
{
64
if
(
value
is
StringInfo
stringInfo
)
65
{
66
return
_str
.Equals(
stringInfo
._str);
67
}
68
return
false
;
69
}
70
71
public
override
int
GetHashCode
()
72
{
73
return
_str
.GetHashCode();
74
}
75
76
public
string
SubstringByTextElements
(
int
startingTextElement
)
77
{
78
int
[]?
indexes
=
Indexes
;
79
return
SubstringByTextElements
(
startingTextElement
, ((
indexes
!=
null
) ?
indexes
.Length : 0) -
startingTextElement
);
80
}
81
82
public
string
SubstringByTextElements
(
int
startingTextElement
,
int
lengthInTextElements
)
83
{
84
int
[]
array
=
Indexes
??
Array
.Empty<
int
>();
85
if
((uint)
startingTextElement
>= (uint)
array
.Length)
86
{
87
throw
new
ArgumentOutOfRangeException
(
"startingTextElement"
,
startingTextElement
,
SR
.
Arg_ArgumentOutOfRangeException
);
88
}
89
if
((uint)
lengthInTextElements
> (uint)(
array
.Length -
startingTextElement
))
90
{
91
throw
new
ArgumentOutOfRangeException
(
"lengthInTextElements"
,
lengthInTextElements
,
SR
.
Arg_ArgumentOutOfRangeException
);
92
}
93
int
num =
array
[
startingTextElement
];
94
Index
end = ^0;
95
if
((uint)(
startingTextElement
+
lengthInTextElements
) < (uint)
array
.Length)
96
{
97
end =
array
[
startingTextElement
+
lengthInTextElements
];
98
}
99
return
String
[num..end];
100
}
101
102
public
static
string
GetNextTextElement
(
string
str
)
103
{
104
return
GetNextTextElement
(
str
, 0);
105
}
106
107
public
static
string
GetNextTextElement
(
string
str
,
int
index
)
108
{
109
int
nextTextElementLength
=
GetNextTextElementLength
(
str
,
index
);
110
return
str
.Substring(
index
,
nextTextElementLength
);
111
}
112
113
public
static
int
GetNextTextElementLength
(
string
str
)
114
{
115
return
GetNextTextElementLength
(
str
, 0);
116
}
117
118
public
static
int
GetNextTextElementLength
(
string
str
,
int
index
)
119
{
120
if
(
str
==
null
)
121
{
122
ThrowHelper
.
ThrowArgumentNullException
(
ExceptionArgument
.str);
123
}
124
if
((uint)
index
> (uint)
str
.Length)
125
{
126
ThrowHelper
.
ThrowArgumentOutOfRange_IndexException
();
127
}
128
return
GetNextTextElementLength
(
str
.AsSpan(
index
));
129
}
130
131
public
static
int
GetNextTextElementLength
(
ReadOnlySpan<char>
str
)
132
{
133
return
TextSegmentationUtility
.
GetLengthOfFirstUtf16ExtendedGraphemeCluster
(
str
);
134
}
135
136
public
static
TextElementEnumerator
GetTextElementEnumerator
(
string
str
)
137
{
138
return
GetTextElementEnumerator
(
str
, 0);
139
}
140
141
public
static
TextElementEnumerator
GetTextElementEnumerator
(
string
str
,
int
index
)
142
{
143
if
(
str
==
null
)
144
{
145
ThrowHelper
.
ThrowArgumentNullException
(
ExceptionArgument
.str);
146
}
147
if
((uint)
index
> (uint)
str
.Length)
148
{
149
ThrowHelper
.
ThrowArgumentOutOfRange_IndexException
();
150
}
151
return
new
TextElementEnumerator
(
str
,
index
);
152
}
153
154
public
static
int
[]
ParseCombiningCharacters
(
string
str
)
155
{
156
if
(
str
==
null
)
157
{
158
ThrowHelper
.
ThrowArgumentNullException
(
ExceptionArgument
.str);
159
}
160
Span<int>
initialSpan
=
stackalloc
int
[64];
161
ValueListBuilder<int>
valueListBuilder
=
new
ValueListBuilder<int>
(
initialSpan
);
162
ReadOnlySpan<char>
str2
=
str
;
163
while
(!
str2
.IsEmpty)
164
{
165
valueListBuilder
.Append(
str
.Length -
str2
.Length);
166
str2
=
str2
.Slice(
GetNextTextElementLength
(
str2
));
167
}
168
int
[] result =
valueListBuilder
.AsSpan().ToArray();
169
valueListBuilder
.Dispose();
170
return
result;
171
}
172
}
System.ArgumentNullException
Definition
ArgumentNullException.cs:10
System.ArgumentOutOfRangeException
Definition
ArgumentOutOfRangeException.cs:9
System.Array
Definition
Array.cs:16
System.Collections.Generic.Dictionary
Definition
Dictionary.cs:14
System.Empty
Definition
Empty.cs:4
System.Globalization.StringInfo.Indexes
int?[] Indexes
Definition
StringInfo.cs:14
System.Globalization.StringInfo._indexes
int[] _indexes
Definition
StringInfo.cs:11
System.Globalization.StringInfo.SubstringByTextElements
string SubstringByTextElements(int startingTextElement, int lengthInTextElements)
Definition
StringInfo.cs:82
System.Globalization.StringInfo.GetNextTextElementLength
static int GetNextTextElementLength(ReadOnlySpan< char > str)
Definition
StringInfo.cs:131
System.Globalization.StringInfo.GetNextTextElementLength
static int GetNextTextElementLength(string str, int index)
Definition
StringInfo.cs:118
System.Globalization.StringInfo.StringInfo
StringInfo(string value)
Definition
StringInfo.cs:57
System.Globalization.StringInfo.LengthInTextElements
int LengthInTextElements
Definition
StringInfo.cs:40
System.Globalization.StringInfo.GetNextTextElement
static string GetNextTextElement(string str, int index)
Definition
StringInfo.cs:107
System.Globalization.StringInfo.GetTextElementEnumerator
static TextElementEnumerator GetTextElementEnumerator(string str)
Definition
StringInfo.cs:136
System.Globalization.StringInfo.GetHashCode
override int GetHashCode()
Definition
StringInfo.cs:71
System.Globalization.StringInfo.StringInfo
StringInfo()
Definition
StringInfo.cs:52
System.Globalization.StringInfo.GetNextTextElementLength
static int GetNextTextElementLength(string str)
Definition
StringInfo.cs:113
System.Globalization.StringInfo.GetNextTextElement
static string GetNextTextElement(string str)
Definition
StringInfo.cs:102
System.Globalization.StringInfo.Equals
override bool Equals([NotNullWhen(true)] object? value)
Definition
StringInfo.cs:62
System.Globalization.StringInfo.GetTextElementEnumerator
static TextElementEnumerator GetTextElementEnumerator(string str, int index)
Definition
StringInfo.cs:141
System.Globalization.StringInfo.ParseCombiningCharacters
static int[] ParseCombiningCharacters(string str)
Definition
StringInfo.cs:154
System.Globalization.StringInfo._str
string _str
Definition
StringInfo.cs:9
System.Globalization.StringInfo.SubstringByTextElements
string SubstringByTextElements(int startingTextElement)
Definition
StringInfo.cs:76
System.Globalization.StringInfo
Definition
StringInfo.cs:8
System.Globalization.TextElementEnumerator
Definition
TextElementEnumerator.cs:7
System.SR.Arg_ArgumentOutOfRangeException
static string Arg_ArgumentOutOfRangeException
Definition
SR.cs:68
System.SR
Definition
SR.cs:7
System.String.Length
int Length
Definition
String.cs:52
System.String
Definition
String.cs:22
System.Text.Unicode.TextSegmentationUtility.GetLengthOfFirstUtf16ExtendedGraphemeCluster
static int GetLengthOfFirstUtf16ExtendedGraphemeCluster(ReadOnlySpan< char > input)
Definition
TextSegmentationUtility.cs:145
System.Text.Unicode.TextSegmentationUtility
Definition
TextSegmentationUtility.cs:8
System.ThrowHelper.ThrowArgumentOutOfRange_IndexException
static void ThrowArgumentOutOfRange_IndexException()
Definition
ThrowHelper.cs:62
System.ThrowHelper.ThrowArgumentNullException
static void ThrowArgumentNullException(string name)
Definition
ThrowHelper.cs:14
System.ThrowHelper
Definition
ThrowHelper.cs:6
string
System.Collections.Generic
Definition
IHashKeyCollection.cs:1
System.Diagnostics.CodeAnalysis
Definition
AllowNullAttribute.cs:1
System.Globalization
Definition
Calendar.cs:1
System.Text.Unicode
Definition
GraphemeClusterBreakType.cs:1
System.ExceptionArgument
ExceptionArgument
Definition
ExceptionArgument.cs:4
System.ExceptionArgument.value
@ value
System.ExceptionArgument.str
@ str
System.ExceptionArgument.index
@ index
System.ExceptionArgument.array
@ array
System.Index
Definition
Index.cs:7
source
System.Private.CoreLib
System.Globalization
StringInfo.cs
Generated by
1.10.0