当前位置: 首页>>代码示例>>C#>>正文


C# MemoryBlock.CompareUtf8NullTerminatedStringWithAsciiString方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:hitomi333,项目名称:corefx,代码行数:29,代码来源:MemoryBlockTests.cs

示例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);
            }
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:26,代码来源:MemoryBlockTests.cs


注:本文中的System.Reflection.Internal.MemoryBlock.CompareUtf8NullTerminatedStringWithAsciiString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。