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

C# Formatting.FormattingData类代码示例

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

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



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

示例1: TryFormatInt64

        // TODO: format should be ReadOnlySpan<char>
        internal static bool TryFormatInt64(long value, byte numberOfBytes, Span<byte> buffer, Span<char> format, FormattingData formattingData, out int bytesWritten)
        {
            Precondition.Require(numberOfBytes <= sizeof(long));

            Format.Parsed parsedFormat = Format.Parse(format);
            return TryFormatInt64(value, numberOfBytes, buffer, parsedFormat, formattingData, out bytesWritten);
        }
开发者ID:TerabyteX,项目名称:corefxlab,代码行数:8,代码来源:IntegerFormatter.cs


示例2: CustomCultureTests

        // Sets up cultures with digits represented by 1 or 5 'A's (0) through 1 or 5 'J's (9) and the minus sigh represented by an underscore followed by a question mark
        static CustomCultureTests()
        {
            byte[][] utf16digitsAndSymbols = new byte[17][];
            for (ushort digit = 0; digit < 10; digit++)
            {
                char digitChar = (char)(digit + 'A');
                var digitString = new string(digitChar, 5);
                utf16digitsAndSymbols[digit] = GetBytesUtf16(digitString);
            }
            utf16digitsAndSymbols[(ushort)FormattingData.Symbol.DecimalSeparator] = GetBytesUtf16(".");
            utf16digitsAndSymbols[(ushort)FormattingData.Symbol.GroupSeparator] = GetBytesUtf16(",");
            utf16digitsAndSymbols[(ushort)FormattingData.Symbol.MinusSign] = GetBytesUtf16("_?");
            Culture5 = new FormattingData(utf16digitsAndSymbols, FormattingData.Encoding.Utf16);

            utf16digitsAndSymbols = new byte[17][];
            for (ushort digit = 0; digit < 10; digit++)
            {
                char digitChar = (char)(digit + 'A');
                var digitString = new string(digitChar, 1);
                utf16digitsAndSymbols[digit] = GetBytesUtf16(digitString);
            }
            utf16digitsAndSymbols[(ushort)FormattingData.Symbol.DecimalSeparator] = GetBytesUtf16(".");
            utf16digitsAndSymbols[(ushort)FormattingData.Symbol.GroupSeparator] = GetBytesUtf16(",");
            utf16digitsAndSymbols[(ushort)FormattingData.Symbol.MinusSign] = GetBytesUtf16("_?");
            Culture1 = new FormattingData(utf16digitsAndSymbols, FormattingData.Encoding.Utf16);
        }
开发者ID:kronic,项目名称:corefxlab,代码行数:27,代码来源:CustomCulture.cs


示例3: TryFormatUInt64

        internal static bool TryFormatUInt64(ulong value, byte numberOfBytes, Span<byte> buffer, Format.Parsed format, FormattingData formattingData, out int bytesWritten)
        {
            if(format.Symbol == 'g')
            {
                format.Symbol = 'G';
            }

            if (format.IsHexadecimal && formattingData.IsUtf16) {
                return TryFormatHexadecimalInvariantCultureUtf16(value, buffer, format, out bytesWritten);
            }

            if (format.IsHexadecimal && formattingData.IsUtf8) {
                return TryFormatHexadecimalInvariantCultureUtf8(value, buffer, format, out bytesWritten);
            }

            if ((formattingData.IsInvariantUtf16) && (format.Symbol == 'D' || format.Symbol == 'G')) {
                return TryFormatDecimalInvariantCultureUtf16(value, buffer, format, out bytesWritten);
            }

            if ((formattingData.IsInvariantUtf8) && (format.Symbol == 'D' || format.Symbol == 'G')) {
                return TryFormatDecimalInvariantCultureUtf8(value, buffer, format, out bytesWritten);
            }

            return TryFormatDecimal(value, buffer, format, formattingData, out bytesWritten);     
        }
开发者ID:TerabyteX,项目名称:corefxlab,代码行数:25,代码来源:IntegerFormatter.cs


示例4: TryFormat

        public static bool TryFormat(this DateTime value, Span<byte> buffer, Format.Parsed format, FormattingData formattingData, out int bytesWritten)
        {
            if (format.IsDefault)
            {
                format.Symbol = 'G';
            }
            Precondition.Require(format.Symbol == 'R' || format.Symbol == 'O' || format.Symbol == 'G');

            switch (format.Symbol)
            {
                case 'R':
                    var utc = value.ToUniversalTime();
                    if (formattingData.IsUtf16)
                    {
                        return TryFormatDateTimeRfc1123(utc, buffer, FormattingData.InvariantUtf16, out bytesWritten);
                    }
                    else
                    {
                        return TryFormatDateTimeRfc1123(utc, buffer, FormattingData.InvariantUtf8, out bytesWritten);
                    }
                case 'O':
                    if (formattingData.IsUtf16)
                    {
                        return TryFormatDateTimeFormatO(value, true, buffer, FormattingData.InvariantUtf16, out bytesWritten);
                    }
                    else
                    {
                        return TryFormatDateTimeFormatO(value, true, buffer, FormattingData.InvariantUtf8, out bytesWritten);
                    }
                case 'G':
                    return TryFormatDateTimeFormagG(value, buffer, formattingData, out bytesWritten);
                default:
                    throw new NotImplementedException();
            }
        }
开发者ID:ryaneliseislalom,项目名称:corefxlab,代码行数:35,代码来源:PrimitiveFormatters_time.cs


示例5: JsonWriter

 public JsonWriter(Stream stream, FormattingData.Encoding encoding, bool prettyPrint = false)
 {
     _wroteListItem = false;
     _prettyPrint = prettyPrint;
     _indent = 0;
     _formatter = new StreamFormatter(stream, encoding == FormattingData.Encoding.Utf16 ? FormattingData.InvariantUtf16 : FormattingData.InvariantUtf8);
 }
开发者ID:axxu,项目名称:corefxlab,代码行数:7,代码来源:JsonWriter.cs


示例6: JsonWriter

 public JsonWriter(Stream stream, FormattingData.Encoding encoding, bool prettyPrint = false)
 {
     _wroteListItem = false;
     _prettyPrint = prettyPrint;
     _indent = 0;
     _pool = new ManagedBufferPool<byte>(2048);
     _formatter = new StreamFormatter(stream, encoding == FormattingData.Encoding.Utf16 ? FormattingData.InvariantUtf16 : FormattingData.InvariantUtf8, _pool);
 }
开发者ID:TerabyteX,项目名称:corefxlab,代码行数:8,代码来源:JsonWriter.cs


示例7: TryFormat

 public static bool TryFormat(this float value, Span<byte> buffer, Format.Parsed format, FormattingData formattingData, out int bytesWritten)
 {
     if (format.IsDefault)
     {
         format.Symbol = 'G';
     }
     Precondition.Require(format.Symbol == 'G');
     return FloatFormatter.TryFormatNumber(value, true, buffer, format, formattingData, out bytesWritten);
 }
开发者ID:ryaneliseislalom,项目名称:corefxlab,代码行数:9,代码来源:PrimitiveFormatters_float.cs


示例8: MultispanFormatter

 public MultispanFormatter(Multispan<byte> buffer, int segmentSize, FormattingData formattingData)
 {
     _formattingData = formattingData;
     _segmentSize = segmentSize;
     _buffer = buffer;
     int index = _buffer.AppendNewSegment(_segmentSize); // TODO: is this the right thing to do? Should Multispan be resilient to empty segment list?
     _lastFull = _buffer.Last;
     _buffer.ResizeSegment(index, 0);
 }
开发者ID:GrimDerp,项目名称:corefxlab,代码行数:9,代码来源:MultispanFormatter.cs


示例9: TryParse

        public static bool TryParse(ReadOnlySpan<byte> text, FormattingData.Encoding encoding, out uint value, out int bytesConsumed)
        {
            Precondition.Require(text.Length > 0);
            Precondition.Require(encoding == FormattingData.Encoding.Utf8 || text.Length > 1);

            value = 0;
            bytesConsumed = 0;

            if (text[0] == '0')
            {
                if (encoding == FormattingData.Encoding.Utf16)
                {
                    bytesConsumed = 2;
                    return text[1] == 0;
                }
                bytesConsumed = 1;
                return true;
            }

            for (int byteIndex = 0; byteIndex < text.Length; byteIndex++)
            {
                byte nextByte = text[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;
                }
                else {
                    return true;
                }
                bytesConsumed++;
                if (encoding == FormattingData.Encoding.Utf16)
                {
                    byteIndex++;
                    if (byteIndex >= text.Length || text[byteIndex] != 0)
                    {
                        return false;
                    }
                    bytesConsumed++;
                }
            }

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


示例10: StreamFormatter

 public StreamFormatter(Stream stream, FormattingData formattingData, int bufferSize = 256)
 {
     _buffer = null;
     if (bufferSize > 0)
     {
         _buffer = BufferPool.Shared.RentBuffer(bufferSize);
     }
     _formattingData = formattingData;
     _stream = stream;
 }
开发者ID:ReedKimble,项目名称:corefxlab,代码行数:10,代码来源:StreamFormatter.cs


示例11: BufferFormatter

 public BufferFormatter(int capacity, FormattingData formattingData, BufferPool pool = null)
 {
     _formattingData = formattingData;
     _count = 0;
     _pool = pool;
     if(_pool == null)
     {
         _pool = BufferPool.Shared;
     }
     _buffer = _pool.RentBuffer(capacity);
 }
开发者ID:ryaneliseislalom,项目名称:corefxlab,代码行数:11,代码来源:BufferFormatter.cs


示例12: StreamFormatter

 public StreamFormatter(Stream stream, FormattingData formattingData, ManagedBufferPool<byte> pool, int bufferSize = 256)
 {
     _pool = pool;
     _buffer = null;
     if (bufferSize > 0)
     {
         _buffer = _pool.RentBuffer(bufferSize);
     }
     _formattingData = formattingData;
     _stream = stream;
 }
开发者ID:kronic,项目名称:corefxlab,代码行数:11,代码来源:StreamFormatter.cs


示例13: BufferFormatter

 public BufferFormatter(int capacity, FormattingData formattingData, ArrayPool<byte> pool = null)
 {
     _formattingData = formattingData;
     _count = 0;
     _pool = pool;
     if(_pool == null)
     {
         _pool = ArrayPool<byte>.Shared;
     }
     _buffer = _pool.Rent(capacity);
 }
开发者ID:nguerrera,项目名称:corefxlab,代码行数:11,代码来源:BufferFormatter.cs


示例14: TryFormat

        public bool TryFormat(Span<byte> buffer, Format.Parsed format, FormattingData formattingData, out int bytesWritten)
        {
            if (!PrimitiveFormatters.TryFormat(_age, buffer, format, formattingData, out bytesWritten)) return false;

            char symbol = _inMonths ? 'm' : 'y';
            int symbolBytes;
            if (!PrimitiveFormatters.TryFormat(symbol, buffer.Slice(bytesWritten), format, formattingData, out symbolBytes)) return false;

            bytesWritten += symbolBytes;
            return true;
        }
开发者ID:ReedKimble,项目名称:corefxlab,代码行数:11,代码来源:CustomTypeFormatting.cs


示例15: BufferFormatter

 public BufferFormatter(int capacity, FormattingData formattingData, ManagedBufferPool<byte> pool = null)
 {
     _formattingData = formattingData;
     _count = 0;
     _pool = pool;
     if(_pool == null)
     {
         _pool = new ManagedBufferPool<byte>(capacity);
     }
     _buffer = _pool.RentBuffer(capacity);
 }
开发者ID:kronic,项目名称:corefxlab,代码行数:11,代码来源:BufferFormatter.cs


示例16: TryFormat

        public static bool TryFormat(this char value, Span<byte> buffer, Format.Parsed format, FormattingData formattingData, out int bytesWritten)
        {
            if (formattingData.IsUtf16)
            {
                if (buffer.Length < 2)
                {
                    bytesWritten = 0;
                    return false;
                }
                buffer[0] = (byte)value;
                buffer[1] = (byte)(value >> 8);
                bytesWritten = 2;
                return true;
            }

            if (buffer.Length < 1)
            {
                bytesWritten = 0;
                return false;
            }

            // fast path for ASCII
            if (value <= 127)
            {
                buffer[0] = (byte)value;
                bytesWritten = 1;
                return true;
            }

            // TODO: This can be directly encoded to SpanByte. There is no conversion between spans yet
            var encoded = new Utf8EncodedCodePoint(value);
            bytesWritten = encoded.Length;
            if (buffer.Length < bytesWritten)
            {
                bytesWritten = 0;
                return false;
            }

            buffer[0] = encoded.Byte0;
            if(bytesWritten > 1)
            {
                buffer[1] = encoded.Byte1;
            }
            if(bytesWritten > 2)
            {
                buffer[2] = encoded.Byte2;
            }
            if(bytesWritten > 3)
            {
                buffer[3] = encoded.Byte3;
            }
            return true;
        }
开发者ID:Applied-Duality,项目名称:corefxlab,代码行数:53,代码来源:PrimitiveFormatters.cs


示例17: TryFormat

        public static bool TryFormat(this char value, Span<byte> buffer, Format.Parsed format, FormattingData formattingData, out int bytesWritten)
        {
            if (formattingData.IsUtf16)
            {
                if (buffer.Length < 2)
                {
                    bytesWritten = 0;
                    return false;
                }
                buffer[0] = (byte)value;
                buffer[1] = (byte)(value >> 8);
                bytesWritten = 2;
                return true;
            }

            if (buffer.Length < 1)
            {
                bytesWritten = 0;
                return false;
            }

            // fast path for ASCII
            if (value <= 127)
            {
                buffer[0] = (byte)value;
                bytesWritten = 1;
                return true;
            }

            var encoded = new FourBytes();
            bytesWritten = Utf8Encoder.CharToUtf8(value, ref encoded);
            if(buffer.Length < bytesWritten)
            {
                bytesWritten = 0;
                return false;
            }

            buffer[0] = encoded.B0;
            if(bytesWritten > 1)
            {
                buffer[1] = encoded.B1;
            }
            if(bytesWritten > 2)
            {
                buffer[2] = encoded.B2;
            }
            if(bytesWritten > 3)
            {
                buffer[3] = encoded.B3;
            }
            return true;
        }
开发者ID:ericstj,项目名称:corefxlab,代码行数:52,代码来源:PrimitiveFormatters.cs


示例18: FormattingData

        // it might be worth compacting the data into a single byte array.
        // Also, it would be great if we could freeze it.
        static FormattingData()
        {
            var utf16digitsAndSymbols = new byte[][] {
                new byte[] { 48, 0, }, // digit 0
                new byte[] { 49, 0, },
                new byte[] { 50, 0, },
                new byte[] { 51, 0, },
                new byte[] { 52, 0, },
                new byte[] { 53, 0, },
                new byte[] { 54, 0, },
                new byte[] { 55, 0, },
                new byte[] { 56, 0, },
                new byte[] { 57, 0, }, // digit 9
                new byte[] { 46, 0, }, // decimal separator
                new byte[] { 44, 0, }, // group separator
                new byte[] { 73, 0, 110, 0, 102, 0, 105, 0, 110, 0, 105, 0, 116, 0, 121, 0, }, // Infinity
                new byte[] { 45, 0, }, // minus sign 
                new byte[] { 43, 0, }, // plus sign 
                new byte[] { 78, 0, 97, 0, 78, 0, }, // NaN
                new byte[] { 69, 0, }, // E
            };

            s_invariantUtf16 = new FormattingData(utf16digitsAndSymbols, Encoding.Utf16);

            var utf8digitsAndSymbols = new byte[][] {
                new byte[] { 48, },
                new byte[] { 49, },
                new byte[] { 50, },
                new byte[] { 51, },
                new byte[] { 52, },
                new byte[] { 53, },
                new byte[] { 54, },
                new byte[] { 55, },
                new byte[] { 56, },
                new byte[] { 57, }, // digit 9
                new byte[] { 46, }, // decimal separator
                new byte[] { 44, }, // group separator
                new byte[] { 73, 110, 102, 105, 110, 105, 116, 121, },
                new byte[] { 45, }, // minus sign
                new byte[] { 43, }, // plus sign
                new byte[] { 78, 97, 78, }, // NaN
                new byte[] { 69, }, // E
            };

            s_invariantUtf8 = new FormattingData(utf8digitsAndSymbols, Encoding.Utf8);
        }
开发者ID:SmartCloudAI,项目名称:corefxlab,代码行数:48,代码来源:FormattingData.cs


示例19: TryFormatNumber

        public static bool TryFormatNumber(double value, bool isSingle, Span<byte> buffer, Format.Parsed format, FormattingData formattingData, out int bytesWritten)
        {
            Precondition.Require(format.Symbol == 'G' || format.Symbol == 'E' || format.Symbol == 'F');

            bytesWritten = 0;
            int written;

            if (Double.IsNaN(value))
            {
                return formattingData.TryWriteSymbol(FormattingData.Symbol.NaN, buffer, out bytesWritten);
            }

            if (Double.IsInfinity(value))
            {
                if (Double.IsNegativeInfinity(value))
                {
                    if (!formattingData.TryWriteSymbol(FormattingData.Symbol.MinusSign, buffer, out written))
                    {
                        bytesWritten = 0;
                        return false;
                    }
                    bytesWritten += written;
                }
                if (!formattingData.TryWriteSymbol(FormattingData.Symbol.InfinitySign, buffer.Slice(bytesWritten), out written))
                {
                    bytesWritten = 0;
                    return false;
                }
                bytesWritten += written;
                return true;
            }

            // TODO: the lines below need to be replaced with properly implemented algorithm
            // the problem is the algorithm is complex, so I am commiting a stub for now
            var hack = value.ToString(format.Symbol.ToString());
            return hack.TryFormat(buffer, default(Format.Parsed), formattingData, out bytesWritten);
        }
开发者ID:TerabyteX,项目名称:corefxlab,代码行数:37,代码来源:FloatFormatter.cs


示例20: SpanFormatter

 public SpanFormatter(Span<byte> buffer, FormattingData formattingData)
 {
     _formattingData = formattingData;
     _count = 0;
     _buffer = buffer;
 }
开发者ID:GrimDerp,项目名称:corefxlab,代码行数:6,代码来源:SpanFormatter.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# RegularExpressions.Group类代码示例发布时间:2022-05-26
下一篇:
C# Text.UnicodeEncoding类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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