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


C# Utf8String.CopyBytes方法代码示例

本文整理汇总了C#中Utf8String.CopyBytes方法的典型用法代码示例。如果您正苦于以下问题:C# Utf8String.CopyBytes方法的具体用法?C# Utf8String.CopyBytes怎么用?C# Utf8String.CopyBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Utf8String的用法示例。


在下文中一共展示了Utf8String.CopyBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CodePointEnumeratorsTests

        public void CodePointEnumeratorsTests(string s)
        {
            Utf8String u8s = new Utf8String(s);
            TestCodePointForwardEnumerator(s, u8s);
            TestCodePointReverseEnumerator(s, u8s);

            byte[] bytes = u8s.CopyBytes();
            unsafe
            {
                fixed (byte* pinnedBytes = bytes)
                {
                    Utf8String u8sFromBytePointer = new Utf8String(new Span<byte>(pinnedBytes, u8s.Length));
                    TestCodePointForwardEnumerator(s, u8sFromBytePointer);
                    TestCodePointReverseEnumerator(s, u8sFromBytePointer);
                }
            }
        }
开发者ID:powercode,项目名称:corefxlab,代码行数:17,代码来源:RandomTests.cs

示例2: EnumerateCodePointsConstructFromByteArray

 public void EnumerateCodePointsConstructFromByteArray()
 {
     foreach (StringWithDescription testData in StringsWithDescription())
     {
         string s = testData.String;
         Utf8String utf8s = new Utf8String(s);
         utf8s = new Utf8String(utf8s.CopyBytes());
         int iterations = testData.Iterations;
         _timer.Restart();
         while (iterations-- != 0)
         {
             foreach (UnicodeCodePoint codePoint in utf8s.CodePoints)
             {
             }
         }
         PrintTime(testData);
     }
 }
开发者ID:khalidabuhakmeh,项目名称:corefxlab,代码行数:18,代码来源:PerformanceTests.cs

示例3: ParseBool

        [InlineData(" !", false, 0, 0, 0)] // invalid character test w/ char < '0'
        public unsafe void ParseBool(string text, bool expectSuccess, int index, bool expectedValue, int expectedBytesConsumed)
        {
		    bool result;
            bool parsedValue;
            int bytesConsumed;
			var utf8String = new Utf8String(text);
			byte[] utf8Bytes = utf8String.CopyBytes();
			ReadOnlySpan<byte> utf8BytesSlice = new ReadOnlySpan<byte>(utf8Bytes);

			// System.String
			result = PrimitiveParser.TryParseBoolean(text, index, 'N', out parsedValue, out bytesConsumed);
            Assert.Equal(expectSuccess, result);
            Assert.Equal(expectedValue, parsedValue);
            Assert.Equal(expectedBytesConsumed, bytesConsumed);

			// Utf8String
			result = PrimitiveParser.TryParseBoolean(utf8String.Substring(index), 'N', out parsedValue, out bytesConsumed);
            Assert.Equal(expectSuccess, result);
            Assert.Equal(expectedValue, parsedValue);
            Assert.Equal(expectedBytesConsumed, bytesConsumed);

			// byte[]
			result = PrimitiveParser.TryParseBoolean(utf8Bytes, index, EncodingData.InvariantUtf8, 'N', out parsedValue, out bytesConsumed);
            Assert.Equal(expectSuccess, result);
            Assert.Equal(expectedValue, parsedValue);
            Assert.Equal(expectedBytesConsumed, bytesConsumed);

			// ReadOnlySpan<byte>
			result = PrimitiveParser.TryParseBoolean(utf8Bytes.Slice(index), EncodingData.InvariantUtf8, 'N', out parsedValue, out bytesConsumed);
            Assert.Equal(expectSuccess, result);
            Assert.Equal(expectedValue, parsedValue);
            Assert.Equal(expectedBytesConsumed, bytesConsumed);

			// byte*
            fixed (byte* arrayPointer = utf8Bytes)
            {
                result = PrimitiveParser.TryParseBoolean(arrayPointer, index, utf8Bytes.Length, EncodingData.InvariantUtf8, 'N',
                    out parsedValue, out bytesConsumed);

                Assert.Equal(expectSuccess, result);
                Assert.Equal(expectedValue, parsedValue);
                Assert.Equal(expectedBytesConsumed, bytesConsumed);
            }
        }
开发者ID:jkotas,项目名称:corefxlab,代码行数:45,代码来源:ParserTests.cs

示例4: EnumerateCodeUnitsConstructFromByteArray

 public void EnumerateCodeUnitsConstructFromByteArray()
 {
     TestCase[] testCases = new TestCase[] {
         new TestCase(GetRandomString(5, 32, 126), "Short ASCII string", 30000000),
         new TestCase(GetRandomString(5, 32, 0xD7FF), "Short string", 30000000),
         new TestCase(GetRandomString(50000, 32, 126), "Long ASCII string", 10000),
         new TestCase(GetRandomString(50000, 32, 0xD7FF), "Long string", 3000)
     };
     foreach (TestCase testData in testCases)
     {
         string s = testData.String;
         Utf8String utf8s = new Utf8String(s);
         utf8s = new Utf8String(utf8s.CopyBytes());
         int iterations = testData.Iterations;
         _timer.Restart();
         while (iterations-- != 0)
         {
             foreach (byte codeUnit in utf8s)
             {
             }
         }
         PrintTime(testData);
     }
 }
开发者ID:benaadams,项目名称:corefxlab,代码行数:24,代码来源:PerformanceTests.cs

示例5: IndexOfNonOccuringSingleCodePointConstructFromSpan

 public unsafe void IndexOfNonOccuringSingleCodePointConstructFromSpan()
 {
     TestCase[] testCases = new TestCase[] {
         new TestCase(GetRandomString(5, 32, 126), "Short ASCII string", 5000000),
         new TestCase(GetRandomString(5, 32, 0xD7FF), "Short string", 5000000),
         new TestCase(GetRandomString(50000, 32, 126), "Long ASCII string", 500),
         new TestCase(GetRandomString(50000, 32, 0xD7FF), "Long string", 500)
     };
     foreach (TestCase testData in testCases)
     {
         string s = testData.String;
         Utf8String utf8s = new Utf8String(s);
         fixed (byte* bytes = utf8s.CopyBytes())
         {
             utf8s = new Utf8String(new Span<byte>(bytes, utf8s.Length));
             int iterations = testData.Iterations;
             _timer.Restart();
             while (iterations-- != 0)
             {
                 int p = utf8s.IndexOf((UnicodeCodePoint)31);
             }
             PrintTime(testData);
         }
     }
 }
开发者ID:benaadams,项目名称:corefxlab,代码行数:25,代码来源:PerformanceTests.cs

示例6: IndexOfNonOccuringSingleCodeUnitConstructFromByteArray

 public void IndexOfNonOccuringSingleCodeUnitConstructFromByteArray()
 {
     TestCase[] testCases = new TestCase[] {
         new TestCase(GetRandomString(5, 32, 126), "Short ASCII string", 30000000),
         new TestCase(GetRandomString(5, 32, 0xD7FF), "Short string", 30000000),
         new TestCase(GetRandomString(50000, 32, 126), "Long ASCII string", 3000),
         new TestCase(GetRandomString(50000, 32, 0xD7FF), "Long string", 3000)
     };
     foreach (TestCase testData in testCases)
     {
         string s = testData.String;
         Utf8String utf8s = new Utf8String(s);
         utf8s = new Utf8String(utf8s.CopyBytes());
         int iterations = testData.Iterations;
         _timer.Restart();
         while (iterations-- != 0)
         {
             int p = utf8s.IndexOf((byte)31);
         }
         PrintTime(testData);
     }
 }
开发者ID:benaadams,项目名称:corefxlab,代码行数:22,代码来源:PerformanceTests.cs

示例7: SubstringTrimOneCharacterOnEachSideConstructFromSpan

 public unsafe void SubstringTrimOneCharacterOnEachSideConstructFromSpan()
 {
     TestCase[] testCases = new TestCase[] {
         new TestCase(GetRandomString(5, 32, 126), "Short ASCII string", 50000000),
         new TestCase(GetRandomString(5, 32, 0xD7FF), "Short string", 50000000),
         new TestCase(GetRandomString(50000, 32, 126), "Long ASCII string", 50000000),
         new TestCase(GetRandomString(50000, 32, 0xD7FF), "Long string", 50000000)
     };
     foreach (TestCase testData in testCases)
     {
         string s = testData.String;
         Utf8String utf8s = new Utf8String(s);
         fixed (byte* bytes = utf8s.CopyBytes())
         {
             utf8s = new Utf8String(new Span<byte>(bytes, utf8s.Length));
             int iterations = testData.Iterations;
             _timer.Restart();
             while (iterations-- != 0)
             {
                 Utf8String result = utf8s.Substring(1, utf8s.Length - 2);
             }
             PrintTime(testData);
         }
     }
 }
开发者ID:benaadams,项目名称:corefxlab,代码行数:25,代码来源:PerformanceTests.cs

示例8: ReverseEnumerateCodePointsConstructFromSpan

 public unsafe void ReverseEnumerateCodePointsConstructFromSpan()
 {
     TestCase[] testCases = new TestCase[] {
         new TestCase(GetRandomString(5, 32, 126), "Short ASCII string", 3000000),
         new TestCase(GetRandomString(5, 32, 0xD7FF), "Short string", 3000000),
         new TestCase(GetRandomString(50000, 32, 126), "Long ASCII string", 300),
         new TestCase(GetRandomString(50000, 32, 0xD7FF), "Long string", 300)
     };
     foreach (TestCase testData in testCases)
     {
         string s = testData.String;
         Utf8String utf8s = new Utf8String(s);
         fixed (byte* bytes = utf8s.CopyBytes())
         {
             utf8s = new Utf8String(new Span<byte>(bytes, utf8s.Length));
             int iterations = testData.Iterations;
             _timer.Restart();
             while (iterations-- != 0)
             {
                 Utf8String.CodePointReverseEnumerator it = utf8s.CodePoints.GetReverseEnumerator();
                 while (it.MoveNext())
                 {
                     UnicodeCodePoint codePoint = it.Current;
                 }
             }
             PrintTime(testData);
         }
     }
 }
开发者ID:benaadams,项目名称:corefxlab,代码行数:29,代码来源:PerformanceTests.cs

示例9: EnumerateCodeUnitsConstructFromSpan

 public unsafe void EnumerateCodeUnitsConstructFromSpan()
 {
     TestCase[] testCases = new TestCase[] {
         new TestCase(GetRandomString(5, 32, 126), "Short ASCII string", 30000000),
         new TestCase(GetRandomString(5, 32, 0xD7FF), "Short string", 30000000),
         new TestCase(GetRandomString(50000, 32, 126), "Long ASCII string", 10000),
         new TestCase(GetRandomString(50000, 32, 0xD7FF), "Long string", 3000)
     };
     foreach (TestCase testData in testCases)
     {
         string s = testData.String;
         Utf8String utf8s = new Utf8String(s);
         fixed (byte* bytes = utf8s.CopyBytes())
         {
             utf8s = new Utf8String(new Span<byte>(bytes, utf8s.Length));
             int iterations = testData.Iterations;
             _timer.Restart();
             while (iterations-- != 0)
             {
                 foreach (Utf8CodeUnit codeUnit in utf8s)
                 {
                 }
             }
             PrintTime(testData);
         }
     }
 }
开发者ID:GrimDerp,项目名称:corefxlab,代码行数:27,代码来源:PerformanceTests.cs

示例10: EnumerateCodePointsConstructFromSpan

 public unsafe void EnumerateCodePointsConstructFromSpan()
 {
     foreach (StringWithDescription testData in StringsWithDescription())
     {
         string s = testData.String;
         Utf8String utf8s = new Utf8String(s);
         fixed (byte* bytes = utf8s.CopyBytes())
         {
             utf8s = new Utf8String(new ByteSpan(bytes, utf8s.Length));
             int iterations = testData.Iterations;
             _timer.Restart();
             while (iterations-- != 0)
             {
                 foreach (UnicodeCodePoint codePoint in utf8s.CodePoints)
                 {
                 }
             }
             PrintTime(testData);
         }
     }
 }
开发者ID:khalidabuhakmeh,项目名称:corefxlab,代码行数:21,代码来源:PerformanceTests.cs

示例11: SubstringTrimOneCharacterOnEachSideConstructFromSpan

 public unsafe void SubstringTrimOneCharacterOnEachSideConstructFromSpan()
 {
     foreach (StringWithDescription testData in StringsWithDescription())
     {
         string s = testData.String;
         Utf8String utf8s = new Utf8String(s);
         fixed (byte* bytes = utf8s.CopyBytes())
         {
             utf8s = new Utf8String(new ByteSpan(bytes, utf8s.Length));
             int iterations = testData.Iterations;
             _timer.Restart();
             while (iterations-- != 0)
             {
                 Utf8String result = utf8s.Substring(1, utf8s.Length - 2);
             }
             PrintTime(testData);
         }
     }
 }
开发者ID:khalidabuhakmeh,项目名称:corefxlab,代码行数:19,代码来源:PerformanceTests.cs

示例12: ReverseEnumerateCodePointsConstructFromSpan

 public unsafe void ReverseEnumerateCodePointsConstructFromSpan()
 {
     foreach (StringWithDescription testData in StringsWithDescription())
     {
         string s = testData.String;
         Utf8String utf8s = new Utf8String(s);
         fixed (byte* bytes = utf8s.CopyBytes())
         {
             utf8s = new Utf8String(new ByteSpan(bytes, utf8s.Length));
             int iterations = testData.Iterations;
             _timer.Restart();
             while (iterations-- != 0)
             {
                 Utf8String.CodePointReverseEnumerator it = utf8s.CodePoints.GetReverseEnumerator();
                 while (it.MoveNext())
                 {
                     UnicodeCodePoint codePoint = it.Current;
                 }
             }
             PrintTime(testData);
         }
     }
 }
开发者ID:khalidabuhakmeh,项目名称:corefxlab,代码行数:23,代码来源:PerformanceTests.cs

示例13: ReverseEnumerateCodePointsConstructFromByteArray

 public void ReverseEnumerateCodePointsConstructFromByteArray()
 {
     foreach (StringWithDescription testData in StringsWithDescription())
     {
         string s = testData.String;
         Utf8String utf8s = new Utf8String(s);
         utf8s = new Utf8String(utf8s.CopyBytes());
         int iterations = testData.Iterations;
         _timer.Restart();
         while (iterations-- != 0)
         {
             Utf8String.CodePointReverseEnumerator it = utf8s.CodePoints.GetReverseEnumerator();
             while (it.MoveNext())
             {
                 UnicodeCodePoint codePoint = it.Current;
             }
         }
         PrintTime(testData);
     }
 }
开发者ID:khalidabuhakmeh,项目名称:corefxlab,代码行数:20,代码来源:PerformanceTests.cs

示例14: IndexOfNonOccuringSingleCodeUnitConstructFromSpan

 public unsafe void IndexOfNonOccuringSingleCodeUnitConstructFromSpan()
 {
     foreach (StringWithDescription testData in StringsWithDescription())
     {
         string s = testData.String;
         Utf8String utf8s = new Utf8String(s);
         fixed (byte* bytes = utf8s.CopyBytes())
         {
             utf8s = new Utf8String(new ByteSpan(bytes, utf8s.Length));
             int iterations = testData.Iterations;
             _timer.Restart();
             while (iterations-- != 0)
             {
                 int p = utf8s.IndexOf((Utf8CodeUnit)31);
             }
             PrintTime(testData);
         }
     }
 }
开发者ID:khalidabuhakmeh,项目名称:corefxlab,代码行数:19,代码来源:PerformanceTests.cs

示例15: IndexOfNonOccuringSingleCodeUnitConstructFromByteArray

 public void IndexOfNonOccuringSingleCodeUnitConstructFromByteArray()
 {
     foreach (StringWithDescription testData in StringsWithDescription())
     {
         string s = testData.String;
         Utf8String utf8s = new Utf8String(s);
         utf8s = new Utf8String(utf8s.CopyBytes());
         int iterations = testData.Iterations;
         _timer.Restart();
         while (iterations-- != 0)
         {
             int p = utf8s.IndexOf((Utf8CodeUnit)31);
         }
         PrintTime(testData);
     }
 }
开发者ID:khalidabuhakmeh,项目名称:corefxlab,代码行数:16,代码来源:PerformanceTests.cs


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