private static void GetEncodedBytes(byte[] originalBytes, int offset, int count, byte[] expandedBytes)
{
int pos = 0;
int end = offset + count;
Debug.Assert(offset < end && end <= originalBytes.Length);
for (int i = offset; i < end; i++)
{
#if DEBUG
// Make sure we never overwrite any bytes if originalBytes and
// expandedBytes refer to the same array
if (originalBytes == expandedBytes)
{
Debug.Assert(i >= pos);
}
#endif
byte b = originalBytes[i];
char ch = (char)b;
if (IsUrlSafeChar(ch))
{
expandedBytes[pos++] = b;
}
else if (ch == ' ')
{
expandedBytes[pos++] = (byte)'+';
}
else
{
expandedBytes[pos++] = (byte)'%';
expandedBytes[pos++] = (byte)IntToHex((b >> 4) & 0xf);
expandedBytes[pos++] = (byte)IntToHex(b & 0x0f);
}
}
}