|
static bool | Contains (this string source, char value) |
|
static bool | Contains (this string source, char value, StringComparison comp) |
|
static bool | Contains (this string source, string value, StringComparison comp) |
|
static unsafe string | TruncateAndFill (this string s, int length, char fillChar) |
|
static unsafe int | IndexOfOccurance (this string s, char c, int index) |
|
static unsafe void | Write (this string s, sbyte *ptr) |
|
static unsafe void | Write (this string s, ref sbyte *ptr) |
|
static unsafe string | Read (this string s, byte *ptr) |
|
static string | ToBinaryArray (this string s) |
|
static int | CompareBits (this string t1, string t2) |
|
static bool | AtBit (this string s, int bitIndex) |
|
static string | RemoveInvalidCharacters (this string s, string valid) |
|
static int | UTF8Length (this string s) |
|
◆ AtBit()
static bool BrawlLib.Internal.StringExtension.AtBit |
( |
this string |
s, |
|
|
int |
bitIndex |
|
) |
| |
|
inlinestatic |
145 {
146 int bit = bitIndex % 8;
147 int byteIndex = (bitIndex - bit) / 8;
148 return ((s[byteIndex] >> (7 - bit)) & 1) != 0;
149 }
◆ CompareBits()
static int BrawlLib.Internal.StringExtension.CompareBits |
( |
this string |
t1, |
|
|
string |
t2 |
|
) |
| |
|
inlinestatic |
111 {
112 int bit = 0;
113 bool found = false;
114 int min = Math.Min(t1.Length, t2.Length);
115 for (int i = 0; i < min; i++)
116 {
117 byte c1 = (byte) t1[i];
118 byte c2 = (byte) t2[i];
119
120 for (int x = 0; x < 8; x++)
121 {
122 if (c1 >> (7 - x) != c2 >> (7 - x))
123 {
124 bit = i * 8 + x;
125 found = true;
126 break;
127 }
128 }
129
130 if (bit != 0)
131 {
132 break;
133 }
134 }
135
136 if (!found)
137 {
138 bit = min * 8 + 1;
139 }
140
141 return bit;
142 }
◆ Contains() [1/3]
static bool BrawlLib.Internal.StringExtension.Contains |
( |
this string |
source, |
|
|
char |
value |
|
) |
| |
|
inlinestatic |
10 {
11 return source.IndexOf(value) >= 0;
12 }
◆ Contains() [2/3]
static bool BrawlLib.Internal.StringExtension.Contains |
( |
this string |
source, |
|
|
char |
value, |
|
|
StringComparison |
comp |
|
) |
| |
|
inlinestatic |
15 {
16 return source.IndexOf(value.ToString(), comp) >= 0;
17 }
◆ Contains() [3/3]
static bool BrawlLib.Internal.StringExtension.Contains |
( |
this string |
source, |
|
|
string |
value, |
|
|
StringComparison |
comp |
|
) |
| |
|
inlinestatic |
20 {
21 return source.IndexOf(value, comp) >= 0;
22 }
◆ IndexOfOccurance()
static unsafe int BrawlLib.Internal.StringExtension.IndexOfOccurance |
( |
this string |
s, |
|
|
char |
c, |
|
|
int |
index |
|
) |
| |
|
inlinestatic |
44 {
45 int len = s.Length;
46 fixed (char* cPtr = s)
47 {
48 for (int i = 0, count = 0; i < len; i++)
49 {
50 if (cPtr[i] == c && count++ == index)
51 {
52 return i;
53 }
54 }
55 }
56
57 return -1;
58 }
◆ Read()
static unsafe string BrawlLib.Internal.StringExtension.Read |
( |
this string |
s, |
|
|
byte * |
ptr |
|
) |
| |
|
inlinestatic |
82 {
83
84
85
86
87
88 return new string((sbyte*) ptr);
89 }
◆ RemoveInvalidCharacters()
static string BrawlLib.Internal.StringExtension.RemoveInvalidCharacters |
( |
this string |
s, |
|
|
string |
valid |
|
) |
| |
|
inlinestatic |
152 {
153 string m = "";
154 char[] t = s.ToCharArray().Where(x => valid.Contains(x)).ToArray();
155 foreach (char c in t)
156 {
157 m += c;
158 }
159
160 return m;
161 }
◆ ToBinaryArray()
static string BrawlLib.Internal.StringExtension.ToBinaryArray |
( |
this string |
s | ) |
|
|
inlinestatic |
92 {
93
94
95
96
97
98
99
100
101 string result = string.Empty;
102 foreach (char ch in s)
103 {
104 result += Convert.ToString(ch, 2);
105 }
106
107 return result.PadLeft(result.Length.Align(8), '0');
108 }
◆ TruncateAndFill()
static unsafe string BrawlLib.Internal.StringExtension.TruncateAndFill |
( |
this string |
s, |
|
|
int |
length, |
|
|
char |
fillChar |
|
) |
| |
|
inlinestatic |
25 {
26 char* buffer = stackalloc char[length];
27
28 int i;
29 int min = Math.Min(s.Length, length);
30 for (i = 0; i < min; i++)
31 {
32 buffer[i] = s[i];
33 }
34
35 while (i < length)
36 {
37 buffer[i++] = fillChar;
38 }
39
40 return new string(buffer, 0, length);
41 }
◆ UTF8Length()
static int BrawlLib.Internal.StringExtension.UTF8Length |
( |
this string |
s | ) |
|
|
inlinestatic |
164 {
165 return Encoding.UTF8.GetByteCount(s);
166 }
◆ Write() [1/2]
static unsafe void BrawlLib.Internal.StringExtension.Write |
( |
this string |
s, |
|
|
ref sbyte * |
ptr |
|
) |
| |
|
inlinestatic |
71 {
72
73 for (int i = 0; i < s.Length; i++)
74 {
75 *ptr++ = (sbyte) s[i];
76 }
77
78 *ptr++ = 0;
79 }
◆ Write() [2/2]
static unsafe void BrawlLib.Internal.StringExtension.Write |
( |
this string |
s, |
|
|
sbyte * |
ptr |
|
) |
| |
|
inlinestatic |
62 {
63
64 for (int i = 0; i < s.Length; i++)
65 {
66 ptr[i] = (sbyte) s[i];
67 }
68 }
The documentation for this class was generated from the following file:
- BrawlLib/Internal/StringExtension.cs