public void BooleanUtf16(char format, bool value, string expected) { ParsedFormat f = format == ' ' ? default(ParsedFormat) : new ParsedFormat(format); byte[] buffer = new byte[256]; Assert.True(Utf16Formatter.TryFormat(value, buffer, out int bytesWritten, f)); var actual = Text.Encoding.Unicode.GetString(buffer, 0, bytesWritten); Assert.Equal(expected, actual); }
public void DecimalFormattingUtf16(decimal number) { var expected = number.ToString("G", CultureInfo.InvariantCulture); var buffer = new byte[expected.Length * 2]; Assert.True(Utf16Formatter.TryFormat(number, buffer, out int bytesWritten, 'G')); var actual = Text.Encoding.Unicode.GetString(buffer, 0, bytesWritten); Assert.Equal(expected, actual); }
public static bool TryFormat(sbyte value, Span <byte> buffer, out int bytesWritten, StandardFormat format = default, SymbolTable symbolTable = null) { if (symbolTable == null || symbolTable == SymbolTable.InvariantUtf8) { return(Utf8Formatter.TryFormat(value, buffer, out bytesWritten, format)); } else if (symbolTable == SymbolTable.InvariantUtf16) { return(Utf16Formatter.TryFormat(value, buffer, out bytesWritten, format)); } else { return(TryFormatInt64(value, 0xff, buffer, out bytesWritten, format, symbolTable)); } }
public static bool TryFormat(Guid value, Span <byte> buffer, out int bytesWritten, StandardFormat format = default, SymbolTable symbolTable = null) { if (symbolTable == null || symbolTable == SymbolTable.InvariantUtf8) { return(Utf8Formatter.TryFormat(value, buffer, out bytesWritten, format)); } else if (symbolTable == SymbolTable.InvariantUtf16) { return(Utf16Formatter.TryFormat(value, buffer, out bytesWritten, format)); } else { throw new NotSupportedException(); } }