From 1f9b218441fb6802950e05fda6c973f0ae6e6d95 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Tue, 24 Feb 2015 12:55:22 +0800 Subject: [PATCH] more BIGENDIAN fixes in UnicodeEncoding. --- .../mscorlib/system/text/unicodeencoding.cs | 27 +++++-------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/mcs/class/referencesource/mscorlib/system/text/unicodeencoding.cs b/mcs/class/referencesource/mscorlib/system/text/unicodeencoding.cs index f6830ec5a38..a5124cf0eb3 100644 --- a/mcs/class/referencesource/mscorlib/system/text/unicodeencoding.cs +++ b/mcs/class/referencesource/mscorlib/system/text/unicodeencoding.cs @@ -29,6 +29,9 @@ namespace System.Text // Unicode version 2.0 character size in bytes public const int CharSize = 2; + // endianness-based bit pattern mask. + static readonly ulong highLowPatternMask = ((ulong) 0xd800d800d800d800 | (BitConverter.IsLittleEndian ? (ulong) 0x0400000004000000 : (ulong) 0x0000040000000400)); + public UnicodeEncoding() : this(false, true) @@ -533,11 +536,7 @@ namespace System.Text // If they happen to be high/low/high/low, we may as well continue. Check the next // bit to see if its set (low) or not (high) in the right pattern -#if BIGENDIAN - if (((0xfc00fc00fc00fc00 & *longChars) ^ 0xd800dc00d800dc00) != 0) -#else - if (((0xfc00fc00fc00fc00 & *longChars) ^ 0xdc00d800dc00d800) != 0) -#endif + if (((0xfc00fc00fc00fc00 & *longChars) ^ highLowPatternMask) != 0) { // Either there weren't 4 surrogates, or the 0x0400 bit was set when a high // was hoped for or the 0x0400 bit wasn't set where a low was hoped for. @@ -823,11 +822,7 @@ namespace System.Text // If they happen to be high/low/high/low, we may as well continue. Check the next // bit to see if its set (low) or not (high) in the right pattern -#if BIGENDIAN - if (((0xfc00fc00fc00fc00 & *longChars) ^ 0xd800dc00d800dc00) != 0) -#else - if (((0xfc00fc00fc00fc00 & *longChars) ^ 0xdc00d800dc00d800) != 0) -#endif + if (((0xfc00fc00fc00fc00 & *longChars) ^ highLowPatternMask) != 0) { // Either there weren't 4 surrogates, or the 0x0400 bit was set when a high // was hoped for or the 0x0400 bit wasn't set where a low was hoped for. @@ -1228,11 +1223,7 @@ namespace System.Text // If they happen to be high/low/high/low, we may as well continue. Check the next // bit to see if its set (low) or not (high) in the right pattern -#if BIGENDIAN - if (((0xfc00fc00fc00fc00 & *longBytes) ^ 0xd800dc00d800dc00) != 0) -#else - if (((0xfc00fc00fc00fc00 & *longBytes) ^ 0xdc00d800dc00d800) != 0) -#endif + if (((0xfc00fc00fc00fc00 & *longBytes) ^ highLowPatternMask) != 0) { // Either there weren't 4 surrogates, or the 0x0400 bit was set when a high // was hoped for or the 0x0400 bit wasn't set where a low was hoped for. @@ -1560,11 +1551,7 @@ namespace System.Text // If they happen to be high/low/high/low, we may as well continue. Check the next // bit to see if its set (low) or not (high) in the right pattern -#if BIGENDIAN - if (((0xfc00fc00fc00fc00 & *longBytes) ^ 0xd800dc00d800dc00) != 0) -#else - if (((0xfc00fc00fc00fc00 & *longBytes) ^ 0xdc00d800dc00d800) != 0) -#endif + if (((0xfc00fc00fc00fc00 & *longBytes) ^ highLowPatternMask) != 0) { // Either there weren't 4 surrogates, or the 0x0400 bit was set when a high // was hoped for or the 0x0400 bit wasn't set where a low was hoped for. -- 2.25.1