Imported Upstream version 4.2.0.179

Former-commit-id: 0a113cb3a6feb7873f632839b1307cc6033cd595
This commit is contained in:
Xamarin Public Jenkins
2015-08-26 07:17:56 -04:00
committed by Jo Shields
parent 183bba2c9a
commit 6992685b86
7507 changed files with 90259 additions and 657307 deletions

View File

@@ -71,7 +71,7 @@ namespace System.Globalization {
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class CompareInfo
public partial class CompareInfo
#if FEATURE_SERIALIZATION
: IDeserializationCallback
#endif
@@ -122,7 +122,7 @@ namespace System.Globalization {
this.m_name = culture.m_name;
this.m_sortName = culture.SortName;
#if !FEATURE_CORECLR
#if !FEATURE_CORECLR && !MONO
IntPtr handleOrigin;
this.m_dataHandle = InternalInitSortHandle(m_sortName, out handleOrigin);
this.m_handleOrigin = handleOrigin;
@@ -243,10 +243,13 @@ namespace System.Globalization {
// A zero length string is not invalid, but it is also not sortable.
return(false);
}
#if MONO
return Mono.Globalization.Unicode.MSCompatUnicodeTable.IsSortable (text);
#else
CompareInfo c = CultureInfo.InvariantCulture.CompareInfo;
return (InternalIsSortable(c.m_dataHandle, c.m_handleOrigin, c.m_sortName, text, text.Length));
#endif
}
@@ -254,7 +257,7 @@ namespace System.Globalization {
#region Serialization
// the following fields are defined to keep the compatibility with Whidbey.
// don't change/remove the names/types of these fields.
#if FEATURE_USE_LCID
#if FEATURE_USE_LCID || MONO
[OptionalField(VersionAdded = 1)]
private int win32LCID; // mapped sort culture id of this instance
private int culture; // the culture ID used to create this instance.
@@ -280,7 +283,7 @@ namespace System.Globalization {
ci = CultureInfo.GetCultureInfo(m_name);
}
this.m_sortName = ci.SortName;
#if !FEATURE_CORECLR
#if !FEATURE_CORECLR && !MONO
IntPtr handleOrigin;
this.m_dataHandle = InternalInitSortHandle(m_sortName, out handleOrigin);
this.m_handleOrigin = handleOrigin;
@@ -441,7 +444,11 @@ namespace System.Globalization {
return (1); // non-null > null
}
#if MONO
return internal_compare_switch (string1, 0, string1.Length, string2, 0, string2.Length, options);
#else
return InternalCompareString(m_dataHandle, m_handleOrigin, m_sortName, string1, 0, string1.Length, string2, 0, string2.Length, GetNativeCompareFlags(options));
#endif
}
@@ -539,10 +546,14 @@ namespace System.Globalization {
return CompareOrdinal(string1, offset1, length1,
string2, offset2, length2);
}
#if MONO
return internal_compare_switch (string1, offset1, length1, string2, offset2, length2, options);
#else
return InternalCompareString(this.m_dataHandle, this.m_handleOrigin, this.m_sortName,
string1, offset1, length1,
string2, offset2, length2,
GetNativeCompareFlags(options));
#endif
}
[System.Security.SecurityCritical]
@@ -596,7 +607,14 @@ namespace System.Globalization {
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options");
}
#if MONO
if (UseManagedCollation)
return GetCollator ().IsPrefix (source, prefix, options);
if(source.Length < prefix.Length)
return false;
return Compare (source, 0, prefix.Length, prefix, 0, prefix.Length, options) == 0;
#else
// to let the sorting DLL do the call optimization in case of Ascii strings, we check if the strings are in Ascii and then send the flag RESERVED_FIND_ASCII_STRING to
// the sorting DLL API SortFindString so sorting DLL don't have to check if the string is Ascii with every call to SortFindString.
@@ -604,6 +622,7 @@ namespace System.Globalization {
m_dataHandle, m_handleOrigin, m_sortName,
GetNativeCompareFlags(options) | Win32Native.FIND_STARTSWITH | ((source.IsAscii() && prefix.IsAscii()) ? RESERVED_FIND_ASCII_STRING : 0),
source, source.Length, 0, prefix, prefix.Length) > -1);
#endif
}
public virtual bool IsPrefix(String source, String prefix)
@@ -649,12 +668,23 @@ namespace System.Globalization {
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options");
}
#if MONO
if (UseManagedCollation)
return GetCollator ().IsSuffix (source, suffix, options);
if (source.Length < suffix.Length)
return false;
return Compare (source, source.Length - suffix.Length, suffix.Length, suffix, 0, suffix.Length, options) == 0;
#else
// to let the sorting DLL do the call optimization in case of Ascii strings, we check if the strings are in Ascii and then send the flag RESERVED_FIND_ASCII_STRING to
// the sorting DLL API SortFindString so sorting DLL don't have to check if the string is Ascii with every call to SortFindString.
return InternalFindNLSStringEx(
m_dataHandle, m_handleOrigin, m_sortName,
GetNativeCompareFlags(options) | Win32Native.FIND_ENDSWITH | ((source.IsAscii() && suffix.IsAscii()) ? RESERVED_FIND_ASCII_STRING : 0),
source, source.Length, source.Length - 1, suffix, suffix.Length) >= 0;
#endif
}
@@ -795,12 +825,16 @@ namespace System.Globalization {
if ((options & ValidIndexMaskOffFlags) != 0 && (options != CompareOptions.Ordinal))
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options");
#if MONO
return internal_index_switch (source, startIndex, count, value, options, true);
#else
// to let the sorting DLL do the call optimization in case of Ascii strings, we check if the strings are in Ascii and then send the flag RESERVED_FIND_ASCII_STRING to
// the sorting DLL API SortFindString so sorting DLL don't have to check if the string is Ascii with every call to SortFindString.
return InternalFindNLSStringEx(
m_dataHandle, m_handleOrigin, m_sortName,
GetNativeCompareFlags(options) | Win32Native.FIND_FROMSTART | ((source.IsAscii() && (value <= '\x007f')) ? RESERVED_FIND_ASCII_STRING : 0),
source, count, startIndex, new String(value, 1), 1);
#endif
}
@@ -848,12 +882,16 @@ namespace System.Globalization {
if ((options & ValidIndexMaskOffFlags) != 0 && (options != CompareOptions.Ordinal))
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options");
#if MONO
return internal_index_switch (source, startIndex, count, value, options, true);
#else
// to let the sorting DLL do the call optimization in case of Ascii strings, we check if the strings are in Ascii and then send the flag RESERVED_FIND_ASCII_STRING to
// the sorting DLL API SortFindString so sorting DLL don't have to check if the string is Ascii with every call to SortFindString.
return InternalFindNLSStringEx(
m_dataHandle, m_handleOrigin, m_sortName,
GetNativeCompareFlags(options) | Win32Native.FIND_FROMSTART | ((source.IsAscii() && value.IsAscii()) ? RESERVED_FIND_ASCII_STRING : 0),
source, count, startIndex, value, value.Length);
#endif
}
////////////////////////////////////////////////////////////////////////
@@ -996,12 +1034,16 @@ namespace System.Globalization {
return source.LastIndexOf(value.ToString(), startIndex, count, StringComparison.OrdinalIgnoreCase);
}
#if MONO
return internal_index_switch (source, startIndex, count, value, options, false);
#else
// to let the sorting DLL do the call optimization in case of Ascii strings, we check if the strings are in Ascii and then send the flag RESERVED_FIND_ASCII_STRING to
// the sorting DLL API SortFindString so sorting DLL don't have to check if the string is Ascii with every call to SortFindString.
return InternalFindNLSStringEx(
m_dataHandle, m_handleOrigin, m_sortName,
GetNativeCompareFlags(options) | Win32Native.FIND_FROMEND | ((source.IsAscii() && (value <= '\x007f')) ? RESERVED_FIND_ASCII_STRING : 0),
source, count, startIndex, new String(value, 1), 1);
#endif
}
@@ -1051,12 +1093,16 @@ namespace System.Globalization {
return source.LastIndexOf(value, startIndex, count, StringComparison.OrdinalIgnoreCase);
}
#if MONO
return internal_index_switch (source, startIndex, count, value, options, false);
#else
// to let the sorting DLL do the call optimization in case of Ascii strings, we check if the strings are in Ascii and then send the flag RESERVED_FIND_ASCII_STRING to
// the sorting DLL API SortFindString so sorting DLL don't have to check if the string is Ascii with every call to SortFindString.
return InternalFindNLSStringEx(
m_dataHandle, m_handleOrigin, m_sortName,
GetNativeCompareFlags(options) | Win32Native.FIND_FROMEND | ((source.IsAscii() && value.IsAscii()) ? RESERVED_FIND_ASCII_STRING : 0),
source, count, startIndex, value, value.Length);
#endif
}
@@ -1067,7 +1113,7 @@ namespace System.Globalization {
// Gets the SortKey for the given string with the given options.
//
////////////////////////////////////////////////////////////////////////
#if !FEATURE_PAL
#if !FEATURE_PAL || MONO
public unsafe virtual SortKey GetSortKey(String source, CompareOptions options)
{
return CreateSortKey(source, options);
@@ -1106,7 +1152,9 @@ namespace System.Globalization {
// Fake value to test though so we can verify our flags
source = "\x0000";
}
#if MONO
return CreateSortKeyCore (source, options);
#else
int flags = GetNativeCompareFlags(options);
// Go ahead and call the OS
@@ -1134,6 +1182,7 @@ namespace System.Globalization {
}
return new SortKey(Name, source, options, keyData);
#endif
}
#endif // !FEATURE_PAL
@@ -1230,9 +1279,13 @@ namespace System.Globalization {
return(0);
}
#if MONO
return GetSortKey (source, options).GetHashCode ();
#else
//
////////////////////////////////////////////////////////////////////////
return (InternalGetGlobalizedHashCode(m_dataHandle, m_handleOrigin, this.m_sortName, source, source.Length, GetNativeCompareFlags(options), forceRandomizedHashing, additionalEntropy));
#endif
}
////////////////////////////////////////////////////////////////////////
@@ -1260,7 +1313,7 @@ namespace System.Globalization {
}
#endif
#if !FEATURE_CORECLR
#if !FEATURE_CORECLR && !MONO
[System.Security.SecuritySafeCritical]
internal static IntPtr InternalInitSortHandle(String localeName, out IntPtr handleOrigin)
{
@@ -1326,7 +1379,7 @@ namespace System.Globalization {
[SuppressUnmanagedCodeSecurity]
private static extern IntPtr NativeInternalInitSortHandle(String localeName, out IntPtr handleOrigin);
#endif
#if !MONO
// Get a locale sensitive sort hash code from native code -- COMNlsInfo::InternalGetGlobalizedHashCode
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
@@ -1364,5 +1417,6 @@ namespace System.Globalization {
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
[SuppressUnmanagedCodeSecurity]
private static extern int InternalGetSortKey(IntPtr handle, IntPtr handleOrigin, String localeName, int flags, String source, int sourceCount, byte[] target, int targetCount);
#endif
}
}

View File

@@ -1 +1 @@
ee1a96998291d6ef2eb7539a917754849bbafa61
cc6bc05d4d040352118265e0dea3270c9253a790

View File

@@ -118,7 +118,11 @@ namespace System.Globalization
for (i = 0; i < lastCodePageItem; i++)
{
arrayEncodingInfo[i] = new EncodingInfo(codePageDataPtr[i].codePage, CodePageDataItem.CreateString(codePageDataPtr[i].Names, 0),
#if MONO
Environment.GetResourceStringEncodingName(codePageDataPtr[i].codePage));
#else
Environment.GetResourceString("Globalization.cp_" + codePageDataPtr[i].codePage));
#endif
}
return arrayEncodingInfo;

View File

@@ -164,6 +164,9 @@ namespace System.Globalization
[System.Security.SecuritySafeCritical]
private String GetAsciiUsingOS(String unicode)
{
#if MONO
throw new NotSupportedException ();
#else
if (unicode.Length == 0)
{
throw new ArgumentException(Environment.GetResourceString(
@@ -208,6 +211,7 @@ namespace System.Globalization
}
return new String(output, 0, length);
#endif
}
// Gets Unicode version of the string. Normalized and limited to IDNA characters.
@@ -267,6 +271,9 @@ namespace System.Globalization
[System.Security.SecuritySafeCritical]
private string GetUnicodeUsingOS(string ascii)
{
#if MONO
throw new NotSupportedException ();
#else
uint flags = (uint)((AllowUnassigned ? IDN_ALLOW_UNASSIGNED : 0) | (UseStd3AsciiRules ? IDN_USE_STD3_ASCII_RULES : 0));
int length = IdnToUnicode(flags, ascii, ascii.Length, null, 0);
int lastError;
@@ -297,6 +304,7 @@ namespace System.Globalization
}
return new String(output, 0, length);
#endif
}
public override bool Equals(Object obj)
@@ -1118,8 +1126,7 @@ namespace System.Globalization
HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*/
#if !MONO
private const int IDN_ALLOW_UNASSIGNED = 0x1;
private const int IDN_USE_STD3_ASCII_RULES = 0x2;
@@ -1136,7 +1143,8 @@ namespace System.Globalization
[MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
String lpUnicodeCharStr,
int cchUnicodeChar,
[System.Runtime.InteropServices.OutAttribute()]
[System.Runtime.InteropServices.OutAttribute()]
char [] lpASCIICharStr,
int cchASCIIChar);
@@ -1150,9 +1158,11 @@ namespace System.Globalization
[MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
string lpASCIICharStr,
int cchASCIIChar,
int cchASCIIChar,
[System.Runtime.InteropServices.OutAttribute()]
char [] lpUnicodeCharStr,
int cchUnicodeChar);
#endif
}
}

View File

@@ -32,7 +32,7 @@ namespace System.Globalization {
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class TextInfo : ICloneable, IDeserializationCallback
public partial class TextInfo : ICloneable, IDeserializationCallback
{
//--------------------------------------------------------------------//
// Internal Information //
@@ -73,8 +73,10 @@ namespace System.Globalization {
private String m_cultureName; // Name of the culture that created this text info
[NonSerialized]private CultureData m_cultureData; // Data record for the culture that made us, not for this textinfo
[NonSerialized]private String m_textInfoName; // Name of the text info we're using (ie: m_cultureData.STEXTINFO)
#if !MONO
[NonSerialized]private IntPtr m_dataHandle; // Sort handle
[NonSerialized]private IntPtr m_handleOrigin;
#endif
[NonSerialized]private bool? m_IsAsciiCasingSameAsInvariant;
@@ -103,7 +105,7 @@ namespace System.Globalization {
this.m_cultureData = cultureData;
this.m_cultureName = this.m_cultureData.CultureName;
this.m_textInfoName = this.m_cultureData.STEXTINFO;
#if !FEATURE_CORECLR
#if !FEATURE_CORECLR && !MONO
IntPtr handleOrigin;
this.m_dataHandle = CompareInfo.InternalInitSortHandle(m_textInfoName, out handleOrigin);
this.m_handleOrigin = handleOrigin;
@@ -178,7 +180,7 @@ namespace System.Globalization {
// Get the text info name belonging to that culture
this.m_cultureData = CultureInfo.GetCultureInfo(m_cultureName).m_cultureData;
this.m_textInfoName = this.m_cultureData.STEXTINFO;
#if !FEATURE_CORECLR
#if !FEATURE_CORECLR && !MONO
IntPtr handleOrigin;
this.m_dataHandle = CompareInfo.InternalInitSortHandle(m_textInfoName, out handleOrigin);
this.m_handleOrigin = handleOrigin;
@@ -231,7 +233,7 @@ namespace System.Globalization {
// (not necessarily true for sorting, but OK for casing & then we apply normal hash code rules)
return (Invariant.GetCaseInsensitiveHashCode(s, forceRandomizedHashing, additionalEntropy));
}
#if !MONO
[System.Security.SecuritySafeCritical]
[ResourceExposure(ResourceScope.None)]
[ResourceConsumption(ResourceScope.Process, ResourceScope.Process)]
@@ -239,7 +241,7 @@ namespace System.Globalization {
{
return InternalTryFindStringOrdinalIgnoreCase(searchFlags, source, count, startIndex, value, value.Length, ref foundIndex);
}
#endif
// This function doesn't check arguments. Please do check in the caller.
// The underlying unmanaged code will assert the sanity of arguments.
[System.Security.SecuritySafeCritical] // auto-generated
@@ -294,9 +296,11 @@ namespace System.Globalization {
string valueUpper = value.ToUpper(CultureInfo.InvariantCulture);
#else
// fast path
#if !MONO
int ret = -1;
if (TryFastFindStringOrdinalIgnoreCase(Microsoft.Win32.Win32Native.FIND_FROMSTART, source, startIndex, value, count, ref ret))
return ret;
#endif
#endif
// the search space within [source] starts at offset [startIndex] inclusive and includes
@@ -364,9 +368,11 @@ namespace System.Globalization {
string valueUpper = value.ToUpper(CultureInfo.InvariantCulture);
#else
// fast path
#if !MONO
int ret = -1;
if (TryFastFindStringOrdinalIgnoreCase(Microsoft.Win32.Win32Native.FIND_FROMEND, source, startIndex, value, count, ref ret))
return ret;
#endif
#endif
// the search space within [source] ends at offset [startIndex] inclusive
@@ -592,7 +598,11 @@ namespace System.Globalization {
{
return ToLowerAsciiInvariant(c);
}
#if MONO
return ToLowerInternal (c);
#else
return (InternalChangeCaseChar(this.m_dataHandle, this.m_handleOrigin, this.m_textInfoName, c, false));
#endif
}
[System.Security.SecuritySafeCritical] // auto-generated
@@ -601,6 +611,9 @@ namespace System.Globalization {
if (str == null) { throw new ArgumentNullException("str"); }
Contract.EndContractBlock();
#if MONO
return ToLowerInternal (str);
#else
String toLower = InternalChangeCaseString(this.m_dataHandle, this.m_handleOrigin, this.m_textInfoName, str, false);
#if __APPLE__
//
@@ -624,7 +637,7 @@ namespace System.Globalization {
}
#endif
return toLower;
#endif
}
static private Char ToLowerAsciiInvariant(Char c)
@@ -655,7 +668,12 @@ namespace System.Globalization {
{
return ToUpperAsciiInvariant(c);
}
#if MONO
return ToUpperInternal (c);
#else
return (InternalChangeCaseChar(this.m_dataHandle, this.m_handleOrigin, this.m_textInfoName, c, true));
#endif
}
@@ -664,6 +682,10 @@ namespace System.Globalization {
{
if (str == null) { throw new ArgumentNullException("str"); }
Contract.EndContractBlock();
#if MONO
return ToUpperInternal (str);
#else
String toUpper = InternalChangeCaseString(this.m_dataHandle, this.m_handleOrigin, this.m_textInfoName, str, true);
#if __APPLE__
//
@@ -687,6 +709,7 @@ namespace System.Globalization {
}
#endif
return toUpper;
#endif
}
static private Char ToUpperAsciiInvariant(Char c)
@@ -709,10 +732,14 @@ namespace System.Globalization {
{
if (m_IsAsciiCasingSameAsInvariant == null)
{
#if MONO
m_IsAsciiCasingSameAsInvariant = !(m_cultureData.SISO639LANGNAME == "az" || m_cultureData.SISO639LANGNAME == "tr");
#else
m_IsAsciiCasingSameAsInvariant =
CultureInfo.GetCultureInfo(m_textInfoName).CompareInfo.Compare("abcdefghijklmnopqrstuvwxyz",
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
CompareOptions.IgnoreCase) == 0;
#endif
}
return (bool)m_IsAsciiCasingSameAsInvariant;
}
@@ -1044,10 +1071,14 @@ namespace System.Globalization {
}
Contract.EndContractBlock();
#if MONO
return StringComparer.CurrentCultureIgnoreCase.GetHashCode (str);
#else
// Return our result
return (InternalGetCaseInsHash(this.m_dataHandle, this.m_handleOrigin, this.m_textInfoName, str, forceRandomizedHashing, additionalEntropy));
#endif
}
#if !MONO
// Change case (ToUpper/ToLower) -- COMNlsInfo::InternalChangeCaseChar
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
@@ -1083,6 +1114,7 @@ namespace System.Globalization {
[SuppressUnmanagedCodeSecurity]
[return: MarshalAs(UnmanagedType.Bool)]
private static unsafe extern bool InternalTryFindStringOrdinalIgnoreCase(int searchFlags, String source, int sourceCount, int startIndex, String target, int targetCount, ref int foundIndex);
#endif
}
}