• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Utf8String类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Utf8String类属于命名空间,在下文中一共展示了Utf8String类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 = " 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Util类代码示例发布时间:2022-05-24
下一篇:
C# Usuario类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap