private static Decode ( char pChars, char pCharsEndPos, byte pBytes, byte pBytesEndPos, bool &hasHalfByteCached, byte &cachedHalfByte, int &charsDecoded, int &bytesDecoded ) : void | ||
pChars | char | |
pCharsEndPos | char | |
pBytes | byte | |
pBytesEndPos | byte | |
hasHalfByteCached | bool | |
cachedHalfByte | byte | |
charsDecoded | int | |
bytesDecoded | int | |
Результат | void |
private static unsafe void Decode( char* pChars, char *pCharsEndPos,
byte* pBytes, byte* pBytesEndPos,
ref bool hasHalfByteCached, ref byte cachedHalfByte,
out int charsDecoded, out int bytesDecoded ) {
#if DEBUG
Debug.Assert( pCharsEndPos - pChars >= 0 );
Debug.Assert( pBytesEndPos - pBytes >= 0 );
#endif
char* pChar = pChars;
byte* pByte = pBytes;
XmlCharType xmlCharType = XmlCharType.Instance;
while ( pChar < pCharsEndPos && pByte < pBytesEndPos ) {
byte halfByte;
char ch = *pChar++;
if ( ch >= 'a' && ch <= 'f' ) {
halfByte = (byte)(ch - 'a' + 10);
}
else if ( ch >= 'A' && ch <= 'F' ) {
halfByte = (byte)(ch - 'A' + 10);
}
else if ( ch >= '0' && ch <= '9' ) {
halfByte = (byte)(ch - '0');
}
else if ( ( xmlCharType.charProperties[ch] & XmlCharType.fWhitespace ) != 0 ) { // else if ( xmlCharType.IsWhiteSpace( ch ) ) {
continue;
}
else {
throw new XmlException(Res.Xml_InvalidBinHexValue, new string( pChars, 0, (int)( pCharsEndPos - pChars ) ) );
}
if ( hasHalfByteCached ) {
*pByte++ = (byte)( ( cachedHalfByte << 4 ) + halfByte );
hasHalfByteCached = false;
}
else {
cachedHalfByte = halfByte;
hasHalfByteCached = true;
}
}
bytesDecoded = (int)(pByte - pBytes);
charsDecoded = (int)(pChar - pChars);
}
}
internal static byte[] FromBinHexString(string s, bool allowOddCount) { if (s == null) { throw new ArgumentNullException("s"); } return(BinHexDecoder.Decode(s.ToCharArray(), allowOddCount)); }