本文整理汇总了C#中System.Reflection.Internal.MemoryBlock.CompareUtf8NullTerminatedStringWithAsciiString方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryBlock.CompareUtf8NullTerminatedStringWithAsciiString方法的具体用法?C# MemoryBlock.CompareUtf8NullTerminatedStringWithAsciiString怎么用?C# MemoryBlock.CompareUtf8NullTerminatedStringWithAsciiString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Internal.MemoryBlock
的用法示例。
在下文中一共展示了MemoryBlock.CompareUtf8NullTerminatedStringWithAsciiString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestComparisons
private unsafe void TestComparisons(string heapValue, int offset, string value, bool unicode = false)
{
byte[] heap;
MetadataStringDecoder decoder = MetadataStringDecoder.DefaultUTF8;
fixed (byte* heapPtr = (heap = Encoding.UTF8.GetBytes(heapValue)))
{
var block = new MemoryBlock(heapPtr, heap.Length);
string heapSubstr = GetStringHeapValue(heapValue, offset);
// compare:
if (!unicode)
{
int actualCmp = block.CompareUtf8NullTerminatedStringWithAsciiString(offset, value);
int expectedCmp = StringComparer.Ordinal.Compare(heapSubstr, value);
Assert.Equal(Math.Sign(expectedCmp), Math.Sign(actualCmp));
}
// equals:
bool actualEq = block.Utf8NullTerminatedEquals(offset, value, decoder);
bool expectedEq = StringComparer.Ordinal.Equals(heapSubstr, value);
Assert.Equal(expectedEq, actualEq);
// starts with:
bool actualSW = block.Utf8NullTerminatedStartsWith(offset, value, decoder);
bool expectedSW = heapSubstr.StartsWith(value, StringComparison.Ordinal);
Assert.Equal(actualSW, expectedSW);
}
}
示例2: TestComparisons
private unsafe void TestComparisons(string heapValue, int offset, string value, bool unicode = false, bool ignoreCase = false)
{
byte[] heap;
MetadataStringDecoder decoder = MetadataStringDecoder.DefaultUTF8;
fixed (byte* heapPtr = (heap = Encoding.UTF8.GetBytes(heapValue)))
{
var block = new MemoryBlock(heapPtr, heap.Length);
string heapSubstr = GetStringHeapValue(heapValue, offset);
// compare:
if (!unicode)
{
int actualCmp = block.CompareUtf8NullTerminatedStringWithAsciiString(offset, value);
int expectedCmp = StringComparer.Ordinal.Compare(heapSubstr, value);
Assert.Equal(Math.Sign(expectedCmp), Math.Sign(actualCmp));
}
if (!ignoreCase)
{
TestComparison(block, offset, value, heapSubstr, decoder, ignoreCase: true);
}
TestComparison(block, offset, value, heapSubstr, decoder, ignoreCase);
}
}