本文整理汇总了C#中UTF8Encoding.GetPreamble方法的典型用法代码示例。如果您正苦于以下问题:C# UTF8Encoding.GetPreamble方法的具体用法?C# UTF8Encoding.GetPreamble怎么用?C# UTF8Encoding.GetPreamble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UTF8Encoding
的用法示例。
在下文中一共展示了UTF8Encoding.GetPreamble方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PosTest1
public void PosTest1()
{
UTF8Encoding UTF8NoPreamble = new UTF8Encoding();
Byte[] preamble;
preamble = UTF8NoPreamble.GetPreamble();
}
示例2: VerifyUtf8Encoding
public static void VerifyUtf8Encoding(UTF8Encoding encoding, bool encoderShouldEmitUTF8Identifier, bool throwOnInvalidBytes)
{
if (encoderShouldEmitUTF8Identifier)
{
Assert.Equal(new byte[] { 0xEF, 0xBB, 0xBF }, encoding.GetPreamble());
}
else
{
Assert.Empty(encoding.GetPreamble());
}
if (throwOnInvalidBytes)
{
Assert.Equal(EncoderFallback.ExceptionFallback, encoding.EncoderFallback);
Assert.Equal(DecoderFallback.ExceptionFallback, encoding.DecoderFallback);
}
else
{
Assert.Equal(new EncoderReplacementFallback("\uFFFD"), encoding.EncoderFallback);
Assert.Equal(new DecoderReplacementFallback("\uFFFD"), encoding.DecoderFallback);
}
}
示例3: PosTest1
public bool PosTest1()
{
bool retVal = true;
// Add your scenario description here
TestLibrary.TestFramework.BeginScenario("PosTest1: Verify method GetPreamble");
try
{
UTF8Encoding UTF8NoPreamble = new UTF8Encoding();
Byte[] preamble;
preamble = UTF8NoPreamble.GetPreamble();
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("001", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例4: UTF_8_BOM
static void UTF_8_BOM()
{
Encoding encodingUTF8 = new UTF8Encoding(true);
byte[] preamble = encodingUTF8.GetPreamble();
foreach (var s in Selection.GetFiltered(typeof(TextAsset), SelectionMode.DeepAssets))
{
TextAsset text = (TextAsset)s;
string path = Path.Combine(Application.dataPath, AssetDatabase.GetAssetPath(text).Substring(7));
Debug.Log("reading " + path);
byte[] bytes = File.ReadAllBytes(path);
if (bytes[0] != preamble[0] || bytes[1] != preamble[1] || bytes[2] != preamble[2])
{
byte[] newBytes = new byte[bytes.LongLength + 3];
Array.Copy(preamble, 0, newBytes, 0, preamble.Length);
Array.Copy(bytes, 0, newBytes, 3, bytes.LongLength);
File.WriteAllBytes(path, newBytes);
Debug.Log("Convert done." + newBytes.Length);
}
else
{
Debug.Log("File already with BOM.");
}
}
}