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


C# Utf8String类代码示例

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


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

示例1: TryParse

        public static bool TryParse(Utf8String utf8Text, out uint value, out int bytesConsumed)
        {
            Precondition.Require(utf8Text.Length > 0);

            value = 0;
            bytesConsumed = 0;

            for (int byteIndex = 0; byteIndex < utf8Text.Length; byteIndex++)
            {
                byte nextByte = (byte)utf8Text[byteIndex];
                if (nextByte < '0' || nextByte > '9')
                {
                    if (bytesConsumed == 0)
                    {
                        value = default(uint);
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
                uint candidate = value * 10;
                candidate += (uint)nextByte - '0';
                if (candidate >= value)
                {
                    value = candidate;
                }
                bytesConsumed++;
            }

            return true;
        }
开发者ID:GrimDerp,项目名称:corefxlab,代码行数:33,代码来源:InvariantParser_uint.cs

示例2: DecodeInPlace

        public void DecodeInPlace()
        {
            var list = new List<byte>();
            for (int value = 0; value < 256; value++) {
                list.Add((byte)value);
            }
            var testBytes = list.ToArray();

            for (int value = 0; value < 256; value++) {
                var sourceBytes = testBytes.Slice(0, value + 1);
                var buffer = new byte[Base64.ComputeEncodedLength(sourceBytes.Length)];
                var bufferSlice = buffer.Slice();

                Base64.Encode(sourceBytes, bufferSlice);

                var encodedText = new Utf8String(bufferSlice).ToString();
                var expectedText = Convert.ToBase64String(testBytes, 0, value + 1);
                Assert.Equal(expectedText, encodedText);

                var decodedByteCount = Base64.DecodeInPlace(bufferSlice);
                Assert.Equal(sourceBytes.Length, decodedByteCount);

                for (int i = 0; i < decodedByteCount; i++) {
                    Assert.Equal(sourceBytes[i], buffer[i]);
                }
            }
        }
开发者ID:jkotas,项目名称:corefxlab,代码行数:27,代码来源:BasicUnitTests.cs

示例3: EndsWithUtf8String

        public void EndsWithUtf8String(string s, string pattern)
        {
            Utf8String u8s = new Utf8String(s);
            Utf8String u8pattern = new Utf8String(pattern);

            Assert.Equal(s.EndsWith(pattern), u8s.EndsWith(u8pattern));
        }
开发者ID:Applied-Duality,项目名称:corefxlab,代码行数:7,代码来源:RandomTests.cs

示例4: BasicEncodingDecoding

        public void BasicEncodingDecoding()
        {
            var list = new List<byte>();
            for(int value=0; value < 256; value++) {
                list.Add((byte)value);
            }
            var testBytes = list.ToArray();

            for (int value = 0; value < 256; value++) {

                var sourceBytes = testBytes.Slice(0, value + 1);
                var encodedBytes = new byte[Base64.ComputeEncodedLength(sourceBytes.Length)].Slice();
                var encodedBytesCount = Base64.Encode(sourceBytes, encodedBytes);
                Assert.Equal(encodedBytes.Length, encodedBytesCount);

                var encodedText = new Utf8String(encodedBytes).ToString();
                var expectedText = Convert.ToBase64String(testBytes, 0, value + 1);
                Assert.Equal(expectedText, encodedText);

                var decodedBytes = new byte[sourceBytes.Length];
                var decodedByteCount = Base64.Decode(encodedBytes, decodedBytes.Slice());
                Assert.Equal(sourceBytes.Length, decodedByteCount);

                for (int i=0; i<decodedBytes.Length; i++) {
                    Assert.Equal(sourceBytes[i], decodedBytes[i]);
                }
            } 
        }
开发者ID:jkotas,项目名称:corefxlab,代码行数:28,代码来源:BasicUnitTests.cs

示例5: NonAllocatingRead

        public void NonAllocatingRead()
        {
            var jsonText = new Utf8String("{\"First\":\"John\",\"Age\":25}");
            JsonDynamicObject json = JsonDynamicObject.Parse(jsonText);

            Assert.Equal(new Utf8String("John"), json.First());
            Assert.Equal(25U, json.Age());
        }
开发者ID:jkotas,项目名称:corefxlab,代码行数:8,代码来源:JsonDynamicObjectTests.cs

示例6: JsonReader

 public JsonReader(Utf8String str)
 {
     _str = str;
     _index = 0;
     _insideObject = 0;
     _insideArray = 0;
     TokenType = 0;
 }
开发者ID:khalidabuhakmeh,项目名称:corefxlab,代码行数:8,代码来源:JsonReader.cs

示例7: JsonReader

 public JsonReader(string str)
 {
     _str = new Utf8String(str);
     _index = 0;
     _insideObject = 0;
     _insideArray = 0;
     TokenType = JsonTokenType.Start;
 }
开发者ID:Anniepoh,项目名称:corefxlab,代码行数:8,代码来源:JsonReader.cs

示例8: Equals

 public bool Equals(Utf8String other)
 {
     if (Length != other.Length) return false;
     for(int i=0; i<Length; i++) {
         if (_bytes[i] != other.Bytes[i]) return false;
     }
     return true;
 }
开发者ID:GrimDerp,项目名称:corefxlab,代码行数:8,代码来源:HttpReader.cs

示例9: JsonReader

 public JsonReader(string str)
 {
     _str = new Utf8String(str);
     _index = 0;
     _insideObject = 0;
     _insideArray = 0;
     TokenType = 0;
     _length = _str.Length;
 }
开发者ID:powercode,项目名称:corefxlab,代码行数:9,代码来源:JsonReader.cs

示例10: JsonReader

 public JsonReader(string str)
 {
     _str = new Utf8String(str).Trim();
     _index = 0;
     _insideObject = 0;
     _insideArray = 0;
     TokenType = 0;
     _jsonStartIsObject = (byte)_str[0] == '{';
 }
开发者ID:TerabyteX,项目名称:corefxlab,代码行数:9,代码来源:JsonReader.cs

示例11: LengthPointerTest

 public unsafe void LengthPointerTest()
 {
     byte[] utf8Bytes = Encoding.UTF8.GetBytes("1258");
     fixed (byte* bytes = utf8Bytes)
     {
         var utf8String = new Utf8String(bytes, utf8Bytes.Length);
         Assert.Equal(4, utf8Bytes.Length);
     }
 }
开发者ID:IDisposable,项目名称:corefxlab,代码行数:9,代码来源:BasicUnitTests.cs

示例12: Bug869DoesNotRepro

        //[Fact(Skip = "issue #869")]
        public void Bug869DoesNotRepro()
        {
            var bytes = new byte[] { 0xF0, 0xA4, 0xAD, 0xA2 };
            var utf8String = new Utf8String(bytes);
            var str = "𤭢";
            var strFromUtf8 = utf8String.ToString();

            Assert.Equal(str, strFromUtf8);
        }
开发者ID:jkotas,项目名称:corefxlab,代码行数:10,代码来源:Bugs.cs

示例13: EagerWrite

        public void EagerWrite()
        {
            dynamic json = new JsonDynamicObject();
            json.First = "John";

            var formatter = new ArrayFormatter(1024, EncodingData.InvariantUtf8);
            formatter.Append((JsonDynamicObject)json);
            var formattedText = new Utf8String(formatter.Formatted);
            Assert.Equal(new Utf8String("{\"First\":\"John\"}"), formattedText);
        }
开发者ID:jkotas,项目名称:corefxlab,代码行数:10,代码来源:JsonDynamicObjectTests.cs

示例14: TryParse

        public static bool TryParse(Utf8String utf8Text, FormattingData cultureAndEncodingInfo, Format.Parsed numericFormat, 
            out ulong value, out int bytesConsumed)
        {
            // Precondition replacement
            if (utf8Text.Length < 1)
            {
                value = 0;
                bytesConsumed = 0;
                return false;
            }

            value = 0;
            bytesConsumed = 0;

            if (cultureAndEncodingInfo.IsInvariantUtf8)
            {
                for (int byteIndex = 0; byteIndex < utf8Text.Length; byteIndex++)
                {
                    byte nextByteVal = (byte)((byte)utf8Text[byteIndex] - '0');
                    if (nextByteVal > 9)
                    {
                        if (bytesConsumed == 0)
                        {
                            value = default(ulong);
                            return false;
                        }
                        else
                        {
                            return true;
                        }
                    }
                    else if (value > UInt64.MaxValue / 10) // overflow
                    {
                        value = 0;
                        bytesConsumed = 0;
                        return false;
                    }
                    else if (UInt64.MaxValue - value * 10 < (ulong)(nextByteVal)) // overflow
                    {
                        value = 0;
                        bytesConsumed = 0;
                        return false;
                    }
                    ulong candidate = value * 10 + nextByteVal;

                    value = candidate;
                    bytesConsumed++;
                }

                return true;
            }

            return false;
        }
开发者ID:geoffkizer,项目名称:corefxlab,代码行数:54,代码来源:InvariantParser_ulong.cs

示例15: ParseUtf8StringToUInt32

        public unsafe void ParseUtf8StringToUInt32(string text, uint expectedValue, int expectedConsumed)
        {
            var utf8 = new Utf8String(text);

            uint parsedValue;
            int bytesConsumed;
            bool result = PrimitiveParser.TryParseUInt32(utf8, out parsedValue, out bytesConsumed);

            Assert.True(result);
            Assert.Equal(expectedValue, parsedValue);
            Assert.Equal(expectedConsumed, bytesConsumed);
        }
开发者ID:jkotas,项目名称:corefxlab,代码行数:12,代码来源:PrimitiveParserTests.cs


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