本文整理汇总了C#中System.Text.DecoderFallbackBuffer.Reset方法的典型用法代码示例。如果您正苦于以下问题:C# DecoderFallbackBuffer.Reset方法的具体用法?C# DecoderFallbackBuffer.Reset怎么用?C# DecoderFallbackBuffer.Reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.DecoderFallbackBuffer
的用法示例。
在下文中一共展示了DecoderFallbackBuffer.Reset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Fallback
// for GetCharCount()
static unsafe int Fallback (object provider, ref DecoderFallbackBuffer buffer, ref byte [] bufferArg, byte* bytes, long index, uint size)
{
if (buffer == null) {
DecoderFallback fb = provider as DecoderFallback;
if (fb != null)
buffer = fb.CreateFallbackBuffer ();
else
buffer = ((Decoder) provider).FallbackBuffer;
}
if (bufferArg == null)
bufferArg = new byte [1];
int ret = 0;
for (int i = 0; i < size; i++) {
bufferArg [0] = bytes [(int) index + i];
buffer.Fallback (bufferArg, 0);
ret += buffer.Remaining;
buffer.Reset ();
}
return ret;
}
示例2: InternalGetCharsFlush
// This function is called when we want to flush the decoder state
// (i.e. in case of invalid UTF-8 characters or interrupted sequences)
internal unsafe static DecoderStatus InternalGetCharsFlush (
char* chars, int charCount,
DecoderFallbackBuffer fallbackBuffer,
DecoderStatus s,
int bytesProcessed, ref int charsProcessed,
ref uint leftBytes, ref uint leftBits, ref uint procBytes)
{
// if there is nothing to flush, then exit silently
if(procBytes == 0)
return DecoderStatus.Ok;
// now we build a 'bytesUnknown' array with the
// stored bytes in 'procBytes'.
int extra = 0;
for (uint t = procBytes; t != 0; extra++)
t = t >> 8;
byte [] bytesUnknown = new byte [extra];
for (int i = extra; i > 0; i--)
bytesUnknown [i - 1] = (byte) ((procBytes >> (8 * (extra - i))) & 0xff);
// partial reset: this condition avoids infinite loops
if (s == DecoderStatus.InvalidSequence)
leftBytes = 0;
// call the fallback and cross fingers
fallbackBuffer.Fallback (bytesUnknown, bytesProcessed - extra);
if (chars != null) {
while (fallbackBuffer.Remaining > 0) {
if (charsProcessed >= charCount)
return DecoderStatus.InsufficientSpace;
chars [charsProcessed++] = fallbackBuffer.GetNextChar ();
}
} else
charsProcessed += fallbackBuffer.Remaining;
fallbackBuffer.Reset ();
// recovery was succesful, flush decoder state
leftBits = leftBytes = procBytes = 0;
return DecoderStatus.Ok;
}