// INTERNAL DECODING FUNCTION (UTF8 -> CHAR/UTF16)
///////////////////////////////////////////////////////////////////////
- internal enum DecoderStatus {
+ internal enum DecoderStatus {
Ok,
InsufficientSpace,
InvalidChar,
// See http://www.cl.cam.ac.uk/~mgk25/unicode.html
private unsafe static DecoderStatus InternalGetChar (
byte* bytes, int byteCount,
- char* chars, int charCount,
+ char* chars, int charCount,
out int bytesProcessed, out int charsProcessed,
ref uint leftBytes, ref uint leftBits, ref uint procBytes)
- {
+ {
uint ch;
bool checkByte;
// convert this character to UTF-16
if (leftBits < (uint) 0x10000) {
- if(chars != null) {
- if(charCount < 1)
+ if (chars != null) {
+ if (charCount < 1)
return DecoderStatus.InsufficientSpace;
*chars = (char) leftBits;
}
charsProcessed++;
} else {
- if(chars != null) {
- if(charCount < 2)
+ if (chars != null) {
+ if (charCount < 2)
return DecoderStatus.InsufficientSpace;
leftBits -= (uint) 0x10000;
*chars++ = (char) ((leftBits >> 10) + (uint) 0xD800);
// we've read a complete char... reset decoder status and finish
leftBytes = leftBits = procBytes = 0;
return DecoderStatus.Ok;
- }
+ }
internal unsafe static DecoderStatus InternalGetChars (
byte* bytes, int byteCount,
bytesProcessed = 0;
// byte processing loop
- while(byteCount - bytesProcessed > 0 && (chars == null || charCount - charsProcessed > 0)) {
+ while (byteCount - bytesProcessed > 0 && (chars == null || charCount - charsProcessed > 0)) {
// fetch a char from the input byte array
s = chars != null
? InternalGetChar (
charsProcessed += t_charsProcessed;
bytesProcessed += t_bytesProcessed;
- switch(s) {
+ switch (s) {
case DecoderStatus.Ok:
break; // everything OK :D
leftBytes = 0;
// call the fallback and cross fingers
fallbackBuffer.Fallback (bytesUnknown, bytesProcessed - extra);
- if(chars != null) {
+ if (chars != null) {
while (fallbackBuffer.Remaining > 0) {
if (charsProcessed >= charCount)
throw new ArgumentException ("Insufficient Space", "chars/fallback");
// INTERNAL ENCODING FUNCTION (CHAR/UTF16 -> UTF8)
///////////////////////////////////////////////////////////////////////
- internal enum EncoderStatus {
+ internal enum EncoderStatus {
Ok,
InputRunOut,
InsufficientSpace,
charCount--;
if (ch < (uint) 0x80) {
if (bytes != null) {
- if(byteCount < 1)
+ if (byteCount < 1)
return EncoderStatus.InsufficientSpace;
*bytes++ = (byte) ch;
byteCount--;
if (ch >= (uint) 0xDC00 && ch <= (uint) 0xDFFF) {
// We have a correct surrogate pair.
ch = 0x10000 + (uint) ch - (uint) 0xDC00
- + ((leftChar - (uint) 0xD800) << 10);
+ + ((leftChar - (uint) 0xD800) << 10);
if (bytes != null) {
if (byteCount < 4)
return EncoderStatus.InsufficientSpace;
// 'InvalidSurrogate'
return s;
}
- if(t_charsProcessed >= 1) {
+ if (t_charsProcessed >= 1) {
// one-char invalid UTF-16 or an
// invalid surrogate
fallbackBuffer.Fallback (
InternalGetChars (
bytes, index, count,
null, 0,
- DecoderFallback.CreateFallbackBuffer(),
+ DecoderFallback.CreateFallbackBuffer (),
out bytesProcessed, out charsProcessed,
ref leftBytes, ref leftBits, ref procBytes);
return charsProcessed;
InternalGetChars (
bytes, count,
null, 0,
- DecoderFallback.CreateFallbackBuffer(),
+ DecoderFallback.CreateFallbackBuffer (),
out bytesProcessed, out charsProcessed,
ref leftBytes, ref leftBits, ref procBytes);
return charsProcessed;
InternalGetChars (
bytes, byteIndex, byteCount,
chars, charIndex,
- DecoderFallback.CreateFallbackBuffer(),
+ DecoderFallback.CreateFallbackBuffer (),
out bytesProcessed, out charsProcessed,
ref leftBytes, ref leftBits, ref procBytes);
return charsProcessed;
InternalGetChars (
bytes, byteCount,
chars, charCount,
- DecoderFallback.CreateFallbackBuffer(),
+ DecoderFallback.CreateFallbackBuffer (),
out bytesProcessed, out charsProcessed,
ref leftBytes, ref leftBits, ref procBytes);
return charsProcessed;
public override void Reset ()
{
- base.Reset();
+ base.Reset ();
leftBytes = 0;
leftBits = 0;
procBytes = 0;
}
public override int GetByteCount (char[] chars, int index,
- int count, bool flush)
+ int count, bool flush)
{
int charsProcessed, bytesProcessed, preambleSize = 0;
if (emitIdentifier && !emittedIdentifier) {
}
public override int GetBytes (char[] chars, int charIndex,
- int charCount, byte[] bytes, int byteIndex, bool flush)
+ int charCount, byte[] bytes,
+ int byteIndex, bool flush)
{
int charsProcessed, bytesProcessed, preambleSize = 0;
if (emitIdentifier && !emittedIdentifier) {
public override void Reset ()
{
- base.Reset();
+ base.Reset ();
this.leftChar = 0;
this.emittedIdentifier = false;
}