Imported Upstream version 5.4.0.167

Former-commit-id: 5624ac747d633e885131e8349322922b6a59baaa
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-08-21 15:34:15 +00:00
parent e49d6f06c0
commit 536cd135cc
12856 changed files with 563812 additions and 223249 deletions

View File

@@ -300,17 +300,35 @@ public class UnixEncoding : Encoding
throw new ArgumentOutOfRangeException ("byteIndex", _("ArgRange_Array"));
}
unsafe {
fixed (char* p = s) {
fixed (byte* b = bytes) {
return GetBytes (p + charIndex, charCount, b + byteIndex, bytes.Length - byteIndex);
}
}
}
}
public unsafe override int GetBytes(char* chars, int charCount, byte* bytes, int byteCount)
{
if (bytes == null || chars == null)
throw new ArgumentNullException (bytes == null ? "bytes" : "chars");
if (charCount < 0 || byteCount < 0)
throw new ArgumentOutOfRangeException (charCount < 0 ? "charCount" : "byteCount");
// Convert the characters into bytes.
char ch;
int length = bytes.Length;
int length = byteCount;
uint pair;
int posn = byteIndex;
int posn = 0;
int charIndex = 0;
while (charCount > 0) {
// Fetch the next UTF-16 character pair value.
ch = s[charIndex++];
ch = chars [charIndex++];
if (ch >= '\uD800' && ch <= '\uDBFF' && charCount > 1) {
// This may be the start of a surrogate pair.
pair = (uint)(s[charIndex]);
pair = (uint)(chars[charIndex]);
if (pair >= (uint)0xDC00 && pair <= (uint)0xDFFF) {
pair = (pair - (uint)0xDC00) +
((((uint)ch) - (uint)0xD800) << 10) +
@@ -326,7 +344,7 @@ public class UnixEncoding : Encoding
}
charCount -= 2;
if (charCount >= 0) {
bytes[posn++] = (byte) s [charIndex++];
bytes[posn++] = (byte)chars [charIndex++];
}
continue;
} else {
@@ -365,7 +383,7 @@ public class UnixEncoding : Encoding
}
// Return the final count to the caller.
return posn - byteIndex;
return posn;
}
// Internal version of "GetCharCount" which can handle a rolling
@@ -394,7 +412,7 @@ public class UnixEncoding : Encoding
uint leftSoFar = (leftOverCount & (uint)0x0F);
uint leftSize = ((leftOverCount >> 4) & (uint)0x0F);
while (count > 0) {
ch = (uint)(bytes[index++]);
ch = (uint)(bytes [index++]);
++next_raw;
--count;
if (leftSize == 0) {