本文整理汇总了C#中Utf8String.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Utf8String.Equals方法的具体用法?C# Utf8String.Equals怎么用?C# Utf8String.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Utf8String
的用法示例。
在下文中一共展示了Utf8String.Equals方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateFormattingData
public static FormattingData CreateFormattingData(string localeId)
{
const int maxIdLength = 15;
const int recordSize = 20;
var resourceName = "System.Text.Formatting.locales.bin";
var resourceStream = typeof(FormattingDataProvider).GetTypeInfo().Assembly.GetManifestResourceStream(resourceName);
if (resourceStream == null)
{
throw new Exception("resource missing");
}
var b1 = resourceStream.ReadByte();
var b2 = resourceStream.ReadByte();
var numberOfIDs = b1 * 256 + b2;
var indexSize = numberOfIDs * 20;
var index = new byte[indexSize];
resourceStream.Read(index, 0, indexSize);
byte[] idBytes = new byte[maxIdLength];
int idByteCount;
if (!localeId.TryFormat(idBytes, default(Format.Parsed), FormattingData.InvariantUtf8, out idByteCount))
{
throw new Exception("bad locale id");
}
var id = new Utf8String(idBytes.Slice(0, idByteCount).CreateArray());
int recordStart = -1;
for (int record = 0; record < numberOfIDs; record++)
{
var indexId = index.Slice(record * recordSize, idByteCount);
if (id.Equals(new Utf8String(indexId.CreateArray()))) // found record
{
var indexData = index.Slice(record * recordSize + maxIdLength);
recordStart = 0;
recordStart += indexData[3] * 256 * 256 * 256;
recordStart += indexData[2] * 256 * 256;
recordStart += indexData[1] * 256;
recordStart += indexData[0];
break;
}
}
if(recordStart == -1)
{
throw new Exception("local not found");
}
resourceStream.Position = recordStart;
const int bufferSize = 512;
var data = new byte[bufferSize];
var bytesRead = resourceStream.Read(data, 0, bufferSize);
// TODO: maybe we should store length in the index
var numberOfStrings = ReadUInt16At(data, 0);
Debug.Assert(numberOfStrings == 17);
var utf16digitsAndSymbols = new byte[numberOfStrings][];
for (int stringIndex = 0; stringIndex < numberOfStrings; stringIndex++)
{
var stringStart = ReadUInt16At(data, stringIndex * 2 + 1);
var stringLength = ReadUInt16At(data, stringIndex * 2 + 2);
utf16digitsAndSymbols[stringIndex] = new byte[stringLength];
Array.Copy(data, stringStart, utf16digitsAndSymbols[stringIndex], 0, stringLength);
}
return new FormattingData(utf16digitsAndSymbols, FormattingData.Encoding.Utf16);
}
示例2: StringEqualsConvertedToUtf16String
public unsafe void StringEqualsConvertedToUtf16String(bool expected, Utf8String s1, Utf8String s2)
{
Assert.Equal(expected, s1.Equals(s2.ToString()));
Assert.Equal(expected, s2.Equals(s1.ToString()));
}
示例3: StringEquals
public unsafe void StringEquals(bool expected, Utf8String s1, Utf8String s2)
{
Assert.Equal(expected, s1.Equals(s2));
Assert.Equal(expected, s2.Equals(s1));
}
示例4: StringEquals
public unsafe void StringEquals(bool equal, string s1, string s2)
{
byte[] b1 = Encoding.UTF8.GetBytes(s1);
byte[] b2 = Encoding.UTF8.GetBytes(s2);
Utf8String s1FromBytes = new Utf8String(b1);
Utf8String s2FromBytes = new Utf8String(b2);
fixed (byte* b1pinned = b1)
fixed (byte* b2pinned = b2)
{
ByteSpan sp1 = new ByteSpan(b1pinned, b1.Length);
ByteSpan sp2 = new ByteSpan(b2pinned, b2.Length);
Utf8String s1FromSpan = new Utf8String(sp1);
Utf8String s2FromSpan = new Utf8String(sp2);
Assert.Equal(equal, s1FromBytes == s2FromBytes);
Assert.Equal(equal, s1FromBytes == s2FromSpan);
Assert.Equal(equal, s1FromBytes == s2);
Assert.Equal(equal, s1FromSpan == s2FromBytes);
Assert.Equal(equal, s1FromSpan == s2FromSpan);
Assert.Equal(equal, s1FromSpan == s2);
Assert.Equal(equal, s1 == s2FromBytes);
Assert.Equal(equal, s1 == s2FromSpan);
Assert.Equal(equal, s1FromBytes.Equals(s2FromBytes));
Assert.Equal(equal, s1FromBytes.Equals(s2FromSpan));
Assert.Equal(equal, s1FromBytes.Equals(s2));
Assert.Equal(equal, s1FromSpan.Equals(s2FromBytes));
Assert.Equal(equal, s1FromSpan.Equals(s2FromSpan));
Assert.Equal(equal, s1FromSpan.Equals(s2));
Assert.Equal(equal, s1.EqualsUtf8String(s2FromBytes));
Assert.Equal(equal, s1.EqualsUtf8String(s2FromSpan));
}
}
示例5: CreateEncoding
private static EncodingData CreateEncoding(string localeId, Stream resourceStream)
{
const int maxIdLength = 15;
const int recordSize = 20;
var b1 = resourceStream.ReadByte();
var b2 = resourceStream.ReadByte();
var numberOfIDs = b1 * 256 + b2;
var indexSize = numberOfIDs * 20;
var index = new byte[indexSize];
resourceStream.Read(index, 0, indexSize);
byte[] idBytes = new byte[maxIdLength];
int idByteCount;
if (!localeId.TryFormat(new Span<byte>(idBytes), default(Format.Parsed), EncodingData.InvariantUtf8, out idByteCount))
{
throw new Exception("bad locale id");
}
var id = new Utf8String(idBytes.Slice(0, idByteCount));
int recordStart = -1;
for (int record = 0; record < numberOfIDs; record++)
{
var indexId = index.Slice(record * recordSize, idByteCount);
if (id.Equals(new Utf8String(indexId))) // found record
{
var indexData = index.Slice(record * recordSize + maxIdLength);
recordStart = 0;
recordStart += indexData[3] * 256 * 256 * 256;
recordStart += indexData[2] * 256 * 256;
recordStart += indexData[1] * 256;
recordStart += indexData[0];
break;
}
}
if (recordStart == -1)
{
throw new Exception("local not found");
}
resourceStream.Position = recordStart;
const int bufferSize = 512;
var data = new byte[bufferSize];
var bytesRead = resourceStream.Read(data, 0, bufferSize);
// TODO: maybe we should store length in the index
var numberOfStrings = ReadUInt16At(data, 0);
Debug.Assert(numberOfStrings == 17);
var utf16digitsAndSymbols = new byte[numberOfStrings][];
for (int stringIndex = 0; stringIndex < numberOfStrings; stringIndex++)
{
var stringStart = ReadUInt16At(data, stringIndex * 2 + 1);
var stringLength = ReadUInt16At(data, stringIndex * 2 + 2);
utf16digitsAndSymbols[stringIndex] = new byte[stringLength];
Array.Copy(data, stringStart, utf16digitsAndSymbols[stringIndex], 0, stringLength);
}
return new EncodingData(utf16digitsAndSymbols, EncodingData.Encoding.Utf16);
}
示例6: EqualsUtf8String
// TODO: Naming it Equals causes picking up wrong overload when compiling (Equals(object))
public static bool EqualsUtf8String(this string left, Utf8String right)
{
return right.Equals(left);
}