public Comparer(CultureInfo culture)
		{
			if (culture == null)
				throw new ArgumentNullException("culture");

			m_compareInfo = culture.CompareInfo;
		}
Ejemplo n.º 2
0
 public void Equals(CompareInfo compare1, object value, bool expected)
 {
     Assert.Equal(expected, compare1.Equals(value));
     if (value is CompareInfo)
     {
         Assert.Equal(expected, compare1.GetHashCode().Equals(value.GetHashCode()));
     }
 }
Ejemplo n.º 3
0
 public void IsSuffix(CompareInfo compareInfo, string source, string value, CompareOptions options, bool expected)
 {
     if (options == CompareOptions.None)
     {
         Assert.Equal(expected, compareInfo.IsSuffix(source, value));
     }
     Assert.Equal(expected, compareInfo.IsSuffix(source, value, options));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Perform deep comparison of two model instances
 /// </summary>
 /// <param name="obj">First object to compare</param>
 /// <param name="value">Second object to compare</param>
 /// <param name="path">Location of the non-equal element found first</param>
 /// <returns>If both objects are equal</returns>
 public static bool Compare(this IBabelModel obj, IBabelModel value, out string path)
 {
     if (obj == null)
     {
         if (value == null)
         {
             path = null;
             return true;
         }
         else
         {
             path = "";
             return false;
         }
     }
     var ci = new CompareInfo { Model = value, Path = null, AreEqual = true};
     obj.RunOnChildren<CompareInfo>(CompareInternal, ci);
     path = ci.Path;
     return ci.AreEqual;
 }
        public void IndexOfTest(CompareInfo compareInfo, string source, string value, int startIndex, int indexOfExpected, int lastIndexOfExpected)
        {
            Assert.Equal(indexOfExpected, compareInfo.IndexOf(source, value, startIndex));
            if (value.Length > 0)
            {
                Assert.Equal(indexOfExpected, compareInfo.IndexOf(source, value[0], startIndex));
            }

            Assert.Equal(lastIndexOfExpected, compareInfo.LastIndexOf(source, value, startIndex));
            if (value.Length > 0)
            {
                Assert.Equal(lastIndexOfExpected, compareInfo.LastIndexOf(source, value[0], startIndex));
            }
        }
 public void LastIndexOf_Aesc_Ligature(CompareInfo compareInfo, string source, string value, int startIndex, int count, CompareOptions options, int expected)
 {
     LastIndexOf_String(compareInfo, source, value, startIndex, count, options, expected);
 }
Ejemplo n.º 7
0
            private StringComparer(CultureInfo culture)
            {
                Debug.Assert(culture != null);

                _compareInfo = culture.CompareInfo;
            }
Ejemplo n.º 8
0
 public static void Ctor(CompareInfo aThis, CultureInfo aCulture)
 {
 }
Ejemplo n.º 9
0
 public void Compare(CompareInfo compareInfo, string string1, int offset1, int length1, string string2, int offset2, int length2, CompareOptions options, int expected)
 {
     if (offset1 + length1 == (string1?.Length ?? 0) && offset2 + length2 == (string2?.Length ?? 0))
     {
         if (offset1 == 0 && offset2 == 0)
         {
             if (options == CompareOptions.None)
             {
                 // Use Compare(string, string)
                 Assert.Equal(expected, Math.Sign(compareInfo.Compare(string1, string2)));
                 Assert.Equal(-expected, Math.Sign(compareInfo.Compare(string2, string1)));
             }
             // Use Compare(string, string, CompareOptions)
             Assert.Equal(expected, Math.Sign(compareInfo.Compare(string1, string2, options)));
             Assert.Equal(-expected, Math.Sign(compareInfo.Compare(string2, string1, options)));
         }
         if (options == CompareOptions.None)
         {
             // Use Compare(string, int, string, int)
             Assert.Equal(expected, Math.Sign(compareInfo.Compare(string1, offset1, string2, offset2)));
             Assert.Equal(-expected, Math.Sign(compareInfo.Compare(string2, offset2, string1, offset1)));
         }
         // Use Compare(string, int, string, int, CompareOptions)
         Assert.Equal(expected, Math.Sign(compareInfo.Compare(string1, offset1, string2, offset2, options)));
         Assert.Equal(-expected, Math.Sign(compareInfo.Compare(string2, offset2, string1, offset1, options)));
     }
     if (options == CompareOptions.None)
     {
         // Use Compare(string, int, int, string, int, int)
         Assert.Equal(expected, Math.Sign(compareInfo.Compare(string1, offset1, length1, string2, offset2, length2)));
         Assert.Equal(-expected, Math.Sign(compareInfo.Compare(string2, offset2, length2, string1, offset1, length1)));
     }
     // Use Compare(string, int, int, string, int, int, CompareOptions)
     Assert.Equal(expected, Math.Sign(compareInfo.Compare(string1, offset1, length1, string2, offset2, length2, options)));
     Assert.Equal(-expected, Math.Sign(compareInfo.Compare(string2, offset2, length2, string1, offset1, length1, options)));
 }
        public override string GetSavedLicenseKey(Type type, Assembly resourceAssembly)
        {
            if (_savedLicenseKeys == null || _savedLicenseKeys[type.AssemblyQualifiedName] == null)
            {
                Debug.WriteLineIf(s_runtimeLicenseContextSwitch.TraceVerbose, "savedLicenseKey is null or doesn't contain our type");
                if (_savedLicenseKeys == null)
                {
                    _savedLicenseKeys = new Hashtable();
                }

                if (resourceAssembly == null)
                {
                    resourceAssembly = Assembly.GetEntryAssembly();
                }

                if (resourceAssembly == null)
                {
                    Debug.WriteLineIf(s_runtimeLicenseContextSwitch.TraceVerbose, "resourceAssembly is null");
                    // If Assembly.EntryAssembly returns null, then we will
                    // try everything.
                    foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
                    {
                        // Though, I could not repro this, we seem to be hitting an AssemblyBuilder
                        // when walking through all the assemblies in the current app domain. This throws an
                        // exception on Assembly.CodeBase and we bail out. Catching exceptions here is not a
                        // bad thing.
                        if (asm.IsDynamic)
                        {
                            continue;
                        }

                        // file://fullpath/foo.exe
                        string fileName = GetLocalPath(asm.EscapedCodeBase);
                        fileName = new FileInfo(fileName).Name;

                        Stream s = asm.GetManifestResourceStream(fileName + ".licenses");
                        if (s == null)
                        {
                            // Since the casing may be different depending on how the assembly was loaded,
                            // we'll do a case insensitive lookup for this manifest resource stream...
                            s = CaseInsensitiveManifestResourceStreamLookup(asm, fileName + ".licenses");
                        }

                        if (s != null)
                        {
                            DesigntimeLicenseContextSerializer.Deserialize(s, fileName.ToUpper(CultureInfo.InvariantCulture), this);
                            break;
                        }
                    }
                }
                else if (!resourceAssembly.IsDynamic)
                {
                    // EscapedCodeBase won't be supported by emitted assemblies anyway
                    Debug.WriteLineIf(s_runtimeLicenseContextSwitch.TraceVerbose, "resourceAssembly is not null");
                    string fileName;

                    fileName = GetLocalPath(resourceAssembly.EscapedCodeBase);

                    fileName = Path.GetFileName(fileName);
                    string licResourceName = fileName + ".licenses";

                    // First try the filename
                    Stream s = resourceAssembly.GetManifestResourceStream(licResourceName);
                    if (s == null)
                    {
                        string      resolvedName      = null;
                        CompareInfo comparer          = CultureInfo.InvariantCulture.CompareInfo;
                        string      shortAssemblyName = resourceAssembly.GetName().Name;
                        // If the assembly has been renamed, we try our best to find a good match in the available resources
                        // by looking at the assembly name (which doesn't change even after a file rename) + ".exe.licenses" or + ".dll.licenses"
                        foreach (string existingName in resourceAssembly.GetManifestResourceNames())
                        {
                            if (comparer.Compare(existingName, licResourceName, CompareOptions.IgnoreCase) == 0 ||
                                comparer.Compare(existingName, shortAssemblyName + ".exe.licenses", CompareOptions.IgnoreCase) == 0 ||
                                comparer.Compare(existingName, shortAssemblyName + ".dll.licenses", CompareOptions.IgnoreCase) == 0)
                            {
                                resolvedName = existingName;
                                break;
                            }
                        }
                        if (resolvedName != null)
                        {
                            s = resourceAssembly.GetManifestResourceStream(resolvedName);
                        }
                    }
                    if (s != null)
                    {
                        DesigntimeLicenseContextSerializer.Deserialize(s, fileName.ToUpper(CultureInfo.InvariantCulture), this);
                    }
                }
            }
            Debug.WriteLineIf(s_runtimeLicenseContextSwitch.TraceVerbose, $"returning : {(string)_savedLicenseKeys[type.AssemblyQualifiedName]}");
            return((string)_savedLicenseKeys[type.AssemblyQualifiedName]);
        }
Ejemplo n.º 11
0
        static void TestIndexOf()
        {
            // based on examples in documentation page for
            // System.Globalization.CompareInfo.IndexOf methods

            CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;
            int         iS     = 20;
            String      myT1;
            String      myStr = "Is AE or ae the same as Æ or æ?";

            myT1 = new String('-', iS);
            //Console.WriteLine( "IndexOf( String, *, {0}, * )", iS );
            //Console.WriteLine( "Original      : {0}", myStr );
            //Console.WriteLine( "No options    : {0}{1}", myT1, myStr.Substring( iS ) );
            PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", iS), -1);
            PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", iS), -1);
            PrintMarker("            Æ : ", myComp.IndexOf(myStr, 'Æ', iS), -1);
            PrintMarker("            æ : ", myComp.IndexOf(myStr, 'æ', iS), -1);
            Console.WriteLine(/* "Ordinal       : {0}{1}", myT1, myStr.Substring( iS ) */);
            PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", iS, CompareOptions.Ordinal), -1);
            PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", iS, CompareOptions.Ordinal), -1);
            PrintMarker("            Æ : ", myComp.IndexOf(myStr, 'Æ', iS, CompareOptions.Ordinal), -1);
            PrintMarker("            æ : ", myComp.IndexOf(myStr, 'æ', iS, CompareOptions.Ordinal), -1);
            Console.WriteLine(/* "IgnoreCase    : {0}{1}", myT1, myStr.Substring( iS ) */);
            PrintMarker("           AE : ", myComp.IndexOf(myStr, "AE", iS, CompareOptions.IgnoreCase), -1);
            PrintMarker("           ae : ", myComp.IndexOf(myStr, "ae", iS, CompareOptions.IgnoreCase), -1);
            PrintMarker("            Æ : ", myComp.IndexOf(myStr, 'Æ', iS, CompareOptions.IgnoreCase), -1);
            PrintMarker("            æ : ", myComp.IndexOf(myStr, 'æ', iS, CompareOptions.IgnoreCase), -1);
            Console.WriteLine();

            myT1 = new String('-', myStr.Length - iS - 1);
            //Console.WriteLine( "LastIndexOf( String, *, {0}, * )", iS );
            //Console.WriteLine( "Original      : {0}", myStr );
            //Console.WriteLine( "No options    : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
            PrintMarker("           AE : ", -1, myComp.LastIndexOf(myStr, "AE", iS));
            PrintMarker("           ae : ", -1, myComp.LastIndexOf(myStr, "ae", iS));
            PrintMarker("            Æ : ", -1, myComp.LastIndexOf(myStr, 'Æ', iS));
            PrintMarker("            æ : ", -1, myComp.LastIndexOf(myStr, 'æ', iS));
            Console.WriteLine(/* "Ordinal       : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 */);
            PrintMarker("           AE : ", -1, myComp.LastIndexOf(myStr, "AE", iS, CompareOptions.Ordinal));
            PrintMarker("           ae : ", -1, myComp.LastIndexOf(myStr, "ae", iS, CompareOptions.Ordinal));
            PrintMarker("            Æ : ", -1, myComp.LastIndexOf(myStr, 'Æ', iS, CompareOptions.Ordinal));
            PrintMarker("            æ : ", -1, myComp.LastIndexOf(myStr, 'æ', iS, CompareOptions.Ordinal));
            Console.WriteLine(/* "IgnoreCase    : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 */);
            PrintMarker("           AE : ", -1, myComp.LastIndexOf(myStr, "AE", iS, CompareOptions.IgnoreCase));
            PrintMarker("           ae : ", -1, myComp.LastIndexOf(myStr, "ae", iS, CompareOptions.IgnoreCase));
            PrintMarker("            Æ : ", -1, myComp.LastIndexOf(myStr, 'Æ', iS, CompareOptions.IgnoreCase));
            PrintMarker("            æ : ", -1, myComp.LastIndexOf(myStr, 'æ', iS, CompareOptions.IgnoreCase));
            Console.WriteLine();

            // Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
            myStr = "Is \u0055\u0308 or \u0075\u0308 the same as \u00DC or \u00FC?";

            myT1 = new String('-', iS);
            //Console.WriteLine( "IndexOf( String, *, {0}, * )", iS );
            //Console.WriteLine( "Original      : {0}", myStr );
            //Console.WriteLine( "No options    : {0}{1}", myT1, myStr.Substring( iS ) );
            PrintMarker("           U\u0308 : ", myComp.IndexOf(myStr, "U\u0308", iS), -1);
            PrintMarker("           u\u0308 : ", myComp.IndexOf(myStr, "u\u0308", iS), -1);
            PrintMarker("            Ü : ", myComp.IndexOf(myStr, 'Ü', iS), -1);
            PrintMarker("            ü : ", myComp.IndexOf(myStr, 'ü', iS), -1);
            Console.WriteLine(/* "Ordinal       : {0}{1}", myT1, myStr.Substring( iS ) */);
            PrintMarker("           U\u0308 : ", myComp.IndexOf(myStr, "U\u0308", iS, CompareOptions.Ordinal), -1);
            PrintMarker("           u\u0308 : ", myComp.IndexOf(myStr, "u\u0308", iS, CompareOptions.Ordinal), -1);
            PrintMarker("            Ü : ", myComp.IndexOf(myStr, 'Ü', iS, CompareOptions.Ordinal), -1);
            PrintMarker("            ü : ", myComp.IndexOf(myStr, 'ü', iS, CompareOptions.Ordinal), -1);
            Console.WriteLine(/* "IgnoreCase    : {0}{1}", myT1, myStr.Substring( iS ) */);
            PrintMarker("           U\u0308 : ", myComp.IndexOf(myStr, "U\u0308", iS, CompareOptions.IgnoreCase), -1);
            PrintMarker("           u\u0308 : ", myComp.IndexOf(myStr, "u\u0308", iS, CompareOptions.IgnoreCase), -1);
            PrintMarker("            Ü : ", myComp.IndexOf(myStr, 'Ü', iS, CompareOptions.IgnoreCase), -1);
            PrintMarker("            ü : ", myComp.IndexOf(myStr, 'ü', iS, CompareOptions.IgnoreCase), -1);
            Console.WriteLine();

            myT1 = new String('-', myStr.Length - iS - 1);
            //Console.WriteLine( "LastIndexOf( String, *, {0}, * )", iS );
            //Console.WriteLine( "Original      : {0}", myStr );
            //Console.WriteLine( "No options    : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 );
            PrintMarker("           U\u0308 : ", -1, myComp.LastIndexOf(myStr, "U\u0308", iS));
            PrintMarker("           u\u0308 : ", -1, myComp.LastIndexOf(myStr, "u\u0308", iS));
            PrintMarker("            Ü : ", -1, myComp.LastIndexOf(myStr, 'Ü', iS));
            PrintMarker("            ü : ", -1, myComp.LastIndexOf(myStr, 'ü', iS));
            Console.WriteLine(/* "Ordinal       : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 */);
            PrintMarker("           U\u0308 : ", -1, myComp.LastIndexOf(myStr, "U\u0308", iS, CompareOptions.Ordinal));
            PrintMarker("           u\u0308 : ", -1, myComp.LastIndexOf(myStr, "u\u0308", iS, CompareOptions.Ordinal));
            PrintMarker("            Ü : ", -1, myComp.LastIndexOf(myStr, 'Ü', iS, CompareOptions.Ordinal));
            PrintMarker("            ü : ", -1, myComp.LastIndexOf(myStr, 'ü', iS, CompareOptions.Ordinal));
            Console.WriteLine(/* "IgnoreCase    : {0}{1}", myStr.Substring( 0, iS + 1 ), myT1 */);
            PrintMarker("           U\u0308 : ", -1, myComp.LastIndexOf(myStr, "U\u0308", iS, CompareOptions.IgnoreCase));
            PrintMarker("           u\u0308 : ", -1, myComp.LastIndexOf(myStr, "u\u0308", iS, CompareOptions.IgnoreCase));
            PrintMarker("            Ü : ", -1, myComp.LastIndexOf(myStr, 'Ü', iS, CompareOptions.IgnoreCase));
            PrintMarker("            ü : ", -1, myComp.LastIndexOf(myStr, 'ü', iS, CompareOptions.IgnoreCase));
            Console.WriteLine();
Ejemplo n.º 12
0
        /// <summary>
        /// Create a collation based on a given <c>CompareInfo</c> and <c>CompareOptions</c>
        /// </summary>
        /// <param name="uri">The collation URI to be used within the XPath expression to refer to this collation</param>
        /// <param name="compareInfo">The <c>CompareInfo</c>, which determines the language-specific
        /// collation rules to be used</param>
        /// <param name="options">Options to be used in performing comparisons, for example
        /// whether they are to be case-blind and/or accent-blind</param>
        /// <param name="isDefault">If true, this collation will be used as the default collation</param>

        public void DeclareCollation(Uri uri, CompareInfo compareInfo, CompareOptions options, Boolean isDefault)
        {
            DotNetComparator comparator = new DotNetComparator(compareInfo, options);

            env.declareCollation(uri.ToString(), comparator, isDefault);
        }
Ejemplo n.º 13
0
 public static IComparer <string> ToComparer <T>(this CompareInfo compareInfo)
 {
     Contract.Requires(compareInfo != null);
     return(new FuncComparer <string>(compareInfo.Compare));
 }
Ejemplo n.º 14
0
 internal Max(CompareInfo compareInfo, CompareOptions compareOptions)
 {
     m_currentMax     = null;
     m_compareInfo    = compareInfo;
     m_compareOptions = compareOptions;
 }
Ejemplo n.º 15
0
 public CultureAwareComparer(CultureInfo ci, bool ignore_case)
 {
     _compareInfo = ci.CompareInfo;
     _ignoreCase  = ignore_case;
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Serves as a hash function for the current System.Globalization.SortKey object
 /// that is suitable for hashing algorithms and data structures such as a hash table.
 /// </summary>
 /// <returns>A hash code for the current System.Globalization.SortKey object.</returns>
 public override int GetHashCode()
 {
     return(CompareInfo.GetCompareInfo(localeName).GetHashCode(m_String, options));
 }
Ejemplo n.º 17
0
        internal __DTString(String str, DateTimeFormatInfo dtfi)
        {
            Index = -1;
            Value = str;
            len = Value.Length;

            m_current = '\0';            
            if (dtfi != null)
            {
                m_info = dtfi.CompareInfo;
                m_checkDigitToken = ((dtfi.FormatFlags & DateTimeFormatFlags.UseDigitPrefixInTokens) != 0);
            } else
            {
                m_info = Thread.CurrentThread.CurrentCulture.CompareInfo;
                m_checkDigitToken = false;
            }
        }
Ejemplo n.º 18
0
    public static void Main()
    {
        CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;

        int position = 0;

        string s1 = "ani\u00ADmal";
        string s2 = "animal";

        // Use culture-sensitive comparison for the following searches:
        Console.WriteLine("Culture-sensitive comparisons:");
        // Find the index of the soft hyphen.
        position = ci.LastIndexOf(s1, "m");
        Console.WriteLine("'m' at position {0}", position);
        if (position >= 0)
        {
            Console.WriteLine(ci.LastIndexOf(s1, "\u00AD", position, CompareOptions.None));
        }

        position = ci.LastIndexOf(s2, "m");
        Console.WriteLine("'m' at position {0}", position);
        if (position >= 0)
        {
            Console.WriteLine(ci.LastIndexOf(s2, "\u00AD", position, CompareOptions.None));
        }

        // Find the index of the soft hyphen followed by "n".
        position = ci.LastIndexOf(s1, "m");
        Console.WriteLine("'m' at position {0}", position);
        if (position >= 0)
        {
            Console.WriteLine(ci.LastIndexOf(s1, "\u00ADn", position, CompareOptions.IgnoreCase));
        }

        position = ci.LastIndexOf(s2, "m");
        Console.WriteLine("'m' at position {0}", position);
        if (position >= 0)
        {
            Console.WriteLine(ci.LastIndexOf(s2, "\u00ADn", position, CompareOptions.IgnoreCase));
        }

        // Find the index of the soft hyphen followed by "m".
        position = ci.LastIndexOf(s1, "m");
        Console.WriteLine("'m' at position {0}", position);
        if (position >= 0)
        {
            Console.WriteLine(ci.LastIndexOf(s1, "\u00ADm", position, CompareOptions.IgnoreCase));
        }

        position = ci.LastIndexOf(s2, "m");
        Console.WriteLine("'m' at position {0}", position);
        if (position >= 0)
        {
            Console.WriteLine(ci.LastIndexOf(s2, "\u00ADm", position, CompareOptions.IgnoreCase));
        }

        Console.WriteLine();
        // Use ordinal comparison for the following searches:
        Console.WriteLine("Ordinal comparisons:");
        // Find the index of the soft hyphen.
        position = ci.LastIndexOf(s1, "m");
        Console.WriteLine("'m' at position {0}", position);
        if (position >= 0)
        {
            Console.WriteLine(ci.LastIndexOf(s1, "\u00AD", position, CompareOptions.Ordinal));
        }

        position = ci.LastIndexOf(s2, "m");
        Console.WriteLine("'m' at position {0}", position);
        if (position >= 0)
        {
            Console.WriteLine(ci.LastIndexOf(s2, "\u00AD", position, CompareOptions.Ordinal));
        }

        // Find the index of the soft hyphen followed by "n".
        position = ci.LastIndexOf(s1, "m");
        Console.WriteLine("'m' at position {0}", position);
        if (position >= 0)
        {
            Console.WriteLine(ci.LastIndexOf(s1, "\u00ADn", position, CompareOptions.Ordinal));
        }

        position = ci.LastIndexOf(s2, "m");
        Console.WriteLine("'m' at position {0}", position);
        if (position >= 0)
        {
            Console.WriteLine(ci.LastIndexOf(s2, "\u00ADn", position, CompareOptions.Ordinal));
        }

        // Find the index of the soft hyphen followed by "m".
        position = ci.LastIndexOf(s1, "m");
        Console.WriteLine("'m' at position {0}", position);
        if (position >= 0)
        {
            Console.WriteLine(ci.LastIndexOf(s1, "\u00ADm", position, CompareOptions.Ordinal));
        }

        position = ci.LastIndexOf(s2, "m");
        Console.WriteLine("'m' at position {0}", position);
        if (position >= 0)
        {
            Console.WriteLine(ci.LastIndexOf(s2, "\u00ADm", position, CompareOptions.Ordinal));
        }
    }
Ejemplo n.º 19
0
 public void LastIndexOf_Aesc_Ligature(CompareInfo compareInfo, string source, string value, int startIndex, int count, CompareOptions options, int expected)
 {
     // TODO: Remove this function, and combine into LastIndexOf_String once 5463 is fixed
     LastIndexOf_String(compareInfo, source, value, startIndex, count, options, expected);
 }
Ejemplo n.º 20
0
 private Comparer()
 {
     this.m_compareInfo = (CompareInfo)null;
 }
Ejemplo n.º 21
0
 public void GetCompareInfo_Null_ThrowsArgumentNullException()
 {
     AssertExtensions.Throws <ArgumentNullException>("name", () => CompareInfo.GetCompareInfo(null));
 }
Ejemplo n.º 22
0
 public void SortKeyKanaTest(CompareInfo compareInfo, string string1, string string2, CompareOptions options, int expected)
 {
     SortKeyTest(compareInfo, string1, string2, options, expected);
 }
 public void Compare(CompareInfo compareInfo, string string1, string string2, CompareOptions options, int expected)
 {
     if (options == CompareOptions.None)
     {
         // Use Compare(string, string)
         Assert.Equal(expected, NormalizeCompare(compareInfo.Compare(string1, string2)));
         Assert.Equal(-expected, NormalizeCompare(compareInfo.Compare(string2, string1)));
     }
     // Use Compare(string, string, CompareOptions)
     Assert.Equal(expected, NormalizeCompare(compareInfo.Compare(string1, string2, options)));
     Assert.Equal(-expected, NormalizeCompare(compareInfo.Compare(string2, string1, options)));
 }
Ejemplo n.º 24
0
        public void GetHashCode(string source1, CompareOptions options1, string source2, CompareOptions options2, bool expected)
        {
            CompareInfo invariantCompare = CultureInfo.InvariantCulture.CompareInfo;

            Assert.Equal(expected, invariantCompare.GetHashCode(source1, options1).Equals(invariantCompare.GetHashCode(source2, options2)));
        }
Ejemplo n.º 25
0
        static bool CompareInternal(string name, object data1, object data2, out string path)
        {
            if (data1 == null)
            {
                if (data2 == null)
                {
                    path = null;
                    return true;
                }
                else
                {
                    path = name;
                    return false;
                }
            }

            if (data2 == null) //data1 != null
            {
                path = name;
                return false;
            }

            var dict1 = data1 as IDictionary;
            if(dict1 != null)
            {
                var dict2 = data2 as IDictionary;
                if (dict2 == null)
                {
                    path = name;
                    return false;
                    //"Both or none supposed to be dictionaries: " + name);
                }

                if(dict1.Count != dict2.Count)
                {
                    path = name;
                    return false;
                }

                foreach(DictionaryEntry kv in dict1)
                {
                    if (!CompareInternal(string.Format("{0}[{1}]", name, kv.Key), kv.Value, dict2[kv.Key], out path))
                    {
                        return false;
                    }
                }

                path = null;
                return true;
            }
            else
            {
                var ba1 = data1 as byte[];
                if(ba1 != null)
                {
                    var ba2 = data2 as byte[];
                    if (ba2 == null || ba1.Length != ba2.Length)
                    {
                        path = name;
                        return false;
                    }

                    for(int i = 0; i < ba1.Length; i++)
                    {
                        if (ba1[i] != ba2[i])
                        {
                            path = string.Format("{0}[{1}]", name, i);
                            return false;
                        }
                    }

                    path = null;
                    return true;
            }

                else
                {
                    var list1 = data1 as IList;
                    if(list1 != null)
                    {
                        var list2 = data2 as IList;
                        if(list2 == null || list1.Count != list2.Count)
                        {
                            path = name;
                            return false;
                        }

                        for(int i = 0; i < list1.Count; i++)
                        {
                            if(!CompareInternal(string.Format("{0}[{1}]", name, i), list1[i], list2[i], out path))
                            {
                                return false;
                            }
                        }

                        path = null;
                        return true;
                    }
                    else
                    {
                        if(data1 is DateTime)
                        {
                            if (!(data2 is DateTime))
                            {
                                path = name;
                                return false;
                            }

                            if(Math.Abs((((DateTime)data1) - ((DateTime)data2)).TotalMilliseconds) > 5)
                            {
                                path = name;
                                return false;
                            }
                            else
                            {
                                path = null;
                                return true;
                            }

                        }
                        else
                        {
                            var m1 = data1 as IBabelModel;
                            if(m1 != null)
                            {
                                var m2 = data2 as IBabelModel;
                                if (m2 == null)
                                {
                                        path = name;
                                        return false;
                                }

                                var cd = new CompareInfo { Model = m2, AreEqual = true };
                                m1.RunOnChildren<CompareInfo>(CompareInternal, cd);
                                path = cd.AreEqual ? null : name + "/" + cd.Path;
                                return cd.AreEqual;
                            }
                            else
                            {
                                if (data1.Equals(data2))
                                {
                                    path = null;
                                    return true;
                                }
                                else
                                {
                                    path = name;
                                    return false;
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 26
0
 private Comparer()
 {
     m_compareInfo = null;
 }
Ejemplo n.º 27
0
        static object CompareInternal(string name, System.Type itemType, object itemData, CompareInfo auxData)
        {
            if (!auxData.AreEqual)
            {
                return itemData; //No reason to proceed
            }

            var data = new DataWrapper();
            auxData.Model.RunOnChild<DataWrapper>(name, GetProperty, data); //Get named element from the second model

            auxData.AreEqual = CompareInternal(name, itemData, data.Data, out auxData.Path);
            return itemData;
        }
Ejemplo n.º 28
0
 public bool Equals([NotNull] string x, [NotNull] string y)
 => CompareInfo.Compare(x, y, CompareOptions.IgnoreWidth | CompareOptions.IgnoreCase) == 0;
Ejemplo n.º 29
0
        public void SortKeyTest(CompareInfo compareInfo, string string1, string string2, CompareOptions options, int expected)
        {
            SortKey sk1 = compareInfo.GetSortKey(string1, options);
            SortKey sk2 = compareInfo.GetSortKey(string2, options);

            Assert.Equal(expected, SortKey.Compare(sk1, sk2));
            Assert.Equal(string1, sk1.OriginalString);
            Assert.Equal(string2, sk2.OriginalString);
        }
Ejemplo n.º 30
0
        private int CompareNatural(string strA, string strB, CultureInfo culture, CompareOptions options)
        {
            CompareInfo cmp              = culture.CompareInfo;
            int         iA               = 0;
            int         iB               = 0;
            int         softResult       = 0;
            int         softResultWeight = 0;

            while (iA < strA.Length && iB < strB.Length)
            {
                bool isDigitA = char.IsDigit(strA[iA]);
                bool isDigitB = char.IsDigit(strB[iB]);
                if (isDigitA != isDigitB)
                {
                    return(cmp.Compare(strA, iA, strB, iB, options));
                }

                if (!isDigitA)
                {
                    int jA = iA + 1;
                    int jB = iB + 1;
                    while (jA < strA.Length && !char.IsDigit(strA[jA]))
                    {
                        jA++;
                    }
                    while (jB < strB.Length && !char.IsDigit(strB[jB]))
                    {
                        jB++;
                    }
                    int cmpResult = cmp.Compare(strA, iA, jA - iA, strB, iB, jB - iB, options);
                    if (cmpResult != 0)
                    {
                        // Certain strings may be considered different due to "soft" differences that are
                        // ignored if more significant differences follow, e.g. a hyphen only affects the
                        // comparison if no other differences follow
                        string sectionA = strA.Substring(iA, jA - iA);
                        string sectionB = strB.Substring(iB, jB - iB);
                        if (cmp.Compare(sectionA + "1", sectionB + "2", options) ==
                            cmp.Compare(sectionA + "2", sectionB + "1", options))
                        {
                            return(cmp.Compare(strA, iA, strB, iB, options));
                        }

                        if (softResultWeight < 1)
                        {
                            softResult       = cmpResult;
                            softResultWeight = 1;
                        }
                    }

                    iA = jA;
                    iB = jB;
                }
                else
                {
                    char zeroA = (char)(strA[iA] - (int)Char.GetNumericValue(strA[iA]));
                    char zeroB = (char)(strB[iB] - (int)Char.GetNumericValue(strB[iB]));
                    int  jA    = iA;
                    int  jB    = iB;
                    while (jA < strA.Length && strA[jA] == zeroA)
                    {
                        jA++;
                    }
                    while (jB < strB.Length && strB[jB] == zeroB)
                    {
                        jB++;
                    }
                    int resultIfSameLength = 0;
                    do
                    {
                        isDigitA = jA < strA.Length && Char.IsDigit(strA[jA]);
                        isDigitB = jB < strB.Length && Char.IsDigit(strB[jB]);
                        int numA = isDigitA ? (int)Char.GetNumericValue(strA[jA]) : 0;
                        int numB = isDigitB ? (int)Char.GetNumericValue(strB[jB]) : 0;
                        if (isDigitA && (char)(strA[jA] - numA) != zeroA)
                        {
                            isDigitA = false;
                        }
                        if (isDigitB && (char)(strB[jB] - numB) != zeroB)
                        {
                            isDigitB = false;
                        }
                        if (isDigitA && isDigitB)
                        {
                            if (numA != numB && resultIfSameLength == 0)
                            {
                                resultIfSameLength = numA < numB ? -1 : 1;
                            }

                            jA++;
                            jB++;
                        }
                    } while (isDigitA && isDigitB);

                    if (isDigitA != isDigitB)
                    {
                        // One number has more digits than the other (ignoring leading zeros) - the longer
                        // number must be larger
                        return(isDigitA ? 1 : -1);
                    }

                    if (resultIfSameLength != 0)
                    {
                        // Both numbers are the same length (ignoring leading zeros) and at least one of
                        // the digits differed - the first difference determines the result
                        return(resultIfSameLength);
                    }

                    int lA = jA - iA;
                    int lB = jB - iB;
                    if (lA != lB)
                    {
                        // Both numbers are equivalent but one has more leading zeros
                        return(lA > lB ? -1 : 1);
                    }

                    if (zeroA != zeroB && softResultWeight < 2)
                    {
                        softResult       = cmp.Compare(strA, iA, 1, strB, iB, 1, options);
                        softResultWeight = 2;
                    }

                    iA = jA;
                    iB = jB;
                }
            }

            if (iA < strA.Length || iB < strB.Length)
            {
                return(iA < strA.Length ? 1 : -1);
            }

            if (softResult != 0)
            {
                return(softResult);
            }

            return(0);
        }
Ejemplo n.º 31
0
 public CaseInsensitiveHashCodeProvider()
 {
     _compareInfo = CultureInfo.CurrentCulture.CompareInfo;
 }
Ejemplo n.º 32
0
        /// <summary>
        /// Searches a directory recursively for files and directories matching
        /// the search criteria.
        /// </summary>
        /// <param name="path">Directory in which to search (absolute canonical path)</param>
        /// <param name="recursive">Whether to scan recursively or not</param>
        private void ScanDirectory(string path, bool recursive)
        {
            // scan each directory only once
            if (_scannedDirectories.Contains(path))
            {
                return;
            }

            // add directory to list of scanned directories
            _scannedDirectories.Add(path);

            // if the path doesn't exist, return.
            if (!Directory.Exists(path))
            {
                return;
            }

            // check whether directory is on case-sensitive volume
            bool   caseSensitive = IsCaseSensitiveFileSystem(path);
            string pathCompare   = path;

            if (!caseSensitive)
            {
                pathCompare = pathCompare.ToLower();
            }

            CompareOptions compareOptions = CompareOptions.None;
            CompareInfo    compare        = CultureInfo.InvariantCulture.CompareInfo;

            if (!caseSensitive)
            {
                compareOptions |= CompareOptions.IgnoreCase;
            }

            ArrayList includedPatterns = new ArrayList();
            ArrayList excludedPatterns = new ArrayList();

            // Only include the valid patterns for this path
            foreach (RegexEntry entry in _includePatterns)
            {
                string baseDirectory = (caseSensitive ? entry.BaseDirectory : entry.BaseDirectory.ToLower());

                // check if the directory being searched is equal to the
                // basedirectory of the RegexEntry
                if (compare.Compare(path, baseDirectory, compareOptions) == 0)
                {
                    includedPatterns.Add(entry);
                }
                else
                {
                    // check if the directory being searched is subdirectory of
                    // basedirectory of RegexEntry

                    if (!entry.IsRecursive)
                    {
                        continue;
                    }

                    // make sure basedirectory ends with directory separator
                    if (!StringUtils.EndsWith(baseDirectory, Path.DirectorySeparatorChar))
                    {
                        baseDirectory += Path.DirectorySeparatorChar;
                    }

                    if (pathCompare.StartsWith(baseDirectory))
                    {
                        includedPatterns.Add(entry);
                    }
                }
            }

            foreach (RegexEntry entry in _excludePatterns)
            {
                string baseDirectory = (caseSensitive ? entry.BaseDirectory : entry.BaseDirectory.ToLower());

                if (entry.BaseDirectory.Length == 0 || compare.Compare(path, baseDirectory, compareOptions) == 0)
                {
                    excludedPatterns.Add(entry);
                }
                else
                {
                    // check if the directory being searched is subdirectory of
                    // basedirectory of RegexEntry

                    if (!entry.IsRecursive)
                    {
                        continue;
                    }

                    // make sure basedirectory ends with directory separator
                    if (!StringUtils.EndsWith(baseDirectory, Path.DirectorySeparatorChar))
                    {
                        baseDirectory += Path.DirectorySeparatorChar;
                    }

                    if (pathCompare.StartsWith(baseDirectory))
                    {
                        excludedPatterns.Add(entry);
                    }
                }
            }

            foreach (string directoryPath in Directory.GetDirectories(path))
            {
                if (recursive)
                {
                    // scan subfolders if we are running recursively
                    ScanDirectory(directoryPath, true);
                }
                else
                {
                    // otherwise just test to see if the subdirectories are included
                    if (IsPathIncluded(directoryPath, caseSensitive, includedPatterns, excludedPatterns))
                    {
                        _directoryNames.Add(directoryPath);
                    }
                }
            }

            // scan files
            foreach (string filePath in Directory.GetFiles(path))
            {
                string filename = filePath;
                if (!caseSensitive)
                {
                    filename = filename.ToLower();
                }
                if (IsPathIncluded(filename, caseSensitive, includedPatterns, excludedPatterns))
                {
                    _fileNames.Add(filePath);
                }
            }

            // check current path last so that delete task will correctly
            // delete empty directories.  This may *seem* like a special case
            // but it is more like formalizing something in a way that makes
            // writing the delete task easier :)
            if (IsPathIncluded(path, caseSensitive, includedPatterns, excludedPatterns))
            {
                _directoryNames.Add(path);
            }
        }
 public void IndexOf_String(CompareInfo compareInfo, string source, string value, int startIndex, int count, CompareOptions options, int expected)
 {
     if (value.Length == 1)
     {
         IndexOf_Char(compareInfo, source, value[0], startIndex, count, options, expected);
     }
     if (options == CompareOptions.None)
     {
         // Use IndexOf(string, string, int, int) or IndexOf(string, string)
         if (startIndex == 0 && count == source.Length)
         {
             // Use IndexOf(string, string)
             Assert.Equal(expected, compareInfo.IndexOf(source, value));
         }
         // Use IndexOf(string, string, int, int)
         Assert.Equal(expected, compareInfo.IndexOf(source, value, startIndex, count));
     }
     if (startIndex + count == source.Length)
     {
         // Use IndexOf(string, string, int, CompareOptions) or IndexOf(string, string, CompareOptions)
         if (startIndex == 0)
         {
             // Use IndexOf(string, string, CompareOptions)
             Assert.Equal(expected, compareInfo.IndexOf(source, value, options));
         }
         // Use IndexOf(string, string, int, CompareOptions)
         Assert.Equal(expected, compareInfo.IndexOf(source, value, startIndex, options));
     }
     // Use IndexOf(string, string, int, int, CompareOptions)
     Assert.Equal(expected, compareInfo.IndexOf(source, value, startIndex, count, options));
 }
Ejemplo n.º 34
0
        private bool IsPathIncluded(string path, bool caseSensitive, ArrayList includedPatterns, ArrayList excludedPatterns)
        {
            bool included = false;

            CompareOptions compareOptions = CompareOptions.None;
            CompareInfo    compare        = CultureInfo.InvariantCulture.CompareInfo;

            if (!caseSensitive)
            {
                compareOptions |= CompareOptions.IgnoreCase;
            }

#if DEBUG_REGEXES
            Console.WriteLine("Test: {0}", path);
#endif

            // check path against include names
            foreach (string name in _includeNames)
            {
#if DEBUG_REGEXES
                Console.WriteLine("Test include name: '{0}'", name);
#endif
                if (compare.Compare(name, path, compareOptions) == 0)
                {
                    included = true;
#if DEBUG_REGEXES
                    Console.WriteLine("Included by name: {0}", name);
#endif
                    break;
                }
            }

            // check path against include regexes
            if (!included)
            {
                foreach (RegexEntry entry in includedPatterns)
                {
#if DEBUG_REGEXES
                    Console.Write("Test include pattern: ");
#endif
                    if (TestRegex(path, entry, caseSensitive))
                    {
                        included = true;
#if DEBUG_REGEXES
                        Console.WriteLine("Included by pattern: {0}", entry.Pattern);
#endif
                        break;
                    }
                }
            }

            // check path against exclude names
            if (included)
            {
                foreach (string name in _excludeNames)
                {
#if DEBUG_REGEXES
                    Console.WriteLine("Test exclude name: '{0}'", name);
#endif
                    if (compare.Compare(name, path, compareOptions) == 0)
                    {
                        included = false;
#if DEBUG_REGEXES
                        Console.WriteLine("Excluded by name: {0}", name);
#endif
                        break;
                    }
                }
            }

            // check path against exclude regexes
            if (included)
            {
                foreach (RegexEntry entry in excludedPatterns)
                {
#if DEBUG_REGEXES
                    Console.Write("Test exclude pattern: ");
#endif
                    if (TestRegex(path, entry, caseSensitive))
                    {
                        included = false;
#if DEBUG_REGEXES
                        Console.WriteLine("Excluded by pattern: {0}", entry.Pattern);
#endif
                        break;
                    }
                }
            }

 #if DEBUG_REGEXES
            Console.WriteLine("Result: {0}", included);
 #endif
            return(included);
        }
Ejemplo n.º 35
0
 public void Compare(CompareInfo compareInfo, string string1, string string2, CompareOptions options, int expected)
 {
     Compare(compareInfo, string1, 0, string1?.Length ?? 0, string2, 0, string2?.Length ?? 0, options, expected);
 }
        [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable
        private Stream CaseInsensitiveManifestResourceStreamLookup(RuntimeAssembly satellite, String name)
        {
            Contract.Requires(satellite != null, "satellite shouldn't be null; check caller");
            Contract.Requires(name != null, "name shouldn't be null; check caller");

            StringBuilder sb = new StringBuilder();

            if (_mediator.LocationInfo != null)
            {
                String nameSpace = _mediator.LocationInfo.Namespace;
                if (nameSpace != null)
                {
                    sb.Append(nameSpace);
                    if (name != null)
                    {
                        sb.Append(Type.Delimiter);
                    }
                }
            }
            sb.Append(name);

            String      givenName     = sb.ToString();
            CompareInfo comparer      = CultureInfo.InvariantCulture.CompareInfo;
            String      canonicalName = null;

            foreach (String existingName in satellite.GetManifestResourceNames())
            {
                if (comparer.Compare(existingName, givenName, CompareOptions.IgnoreCase) == 0)
                {
                    if (canonicalName == null)
                    {
                        canonicalName = existingName;
                    }
                    else
                    {
                        throw new MissingManifestResourceException(Environment.GetResourceString("MissingManifestResource_MultipleBlobs", givenName, satellite.ToString()));
                    }
                }
            }

#if !FEATURE_CORECLR
            if (FrameworkEventSource.IsInitialized)
            {
                if (canonicalName != null)
                {
                    FrameworkEventSource.Log.ResourceManagerCaseInsensitiveResourceStreamLookupSucceeded(_mediator.BaseName, _mediator.MainAssembly, satellite.GetSimpleName(), givenName);
                }
                else
                {
                    FrameworkEventSource.Log.ResourceManagerCaseInsensitiveResourceStreamLookupFailed(_mediator.BaseName, _mediator.MainAssembly, satellite.GetSimpleName(), givenName);
                }
            }
#endif

            if (canonicalName == null)
            {
                return(null);
            }
            // If we're looking in the main assembly AND if the main
            // assembly was the person who created the ResourceManager,
            // skip a security check for private manifest resources.
            bool           canSkipSecurityCheck = _mediator.MainAssembly == satellite && _mediator.CallingAssembly == _mediator.MainAssembly;
            StackCrawlMark stackMark            = StackCrawlMark.LookForMyCaller;
            Stream         s = satellite.GetManifestResourceStream(canonicalName, ref stackMark, canSkipSecurityCheck);
            // GetManifestResourceStream will return null if we don't have
            // permission to read this stream from the assembly.  For example,
            // if the stream is private and we're trying to access it from another
            // assembly (ie, ResMgr in mscorlib accessing anything else), we
            // require Reflection TypeInformation permission to be able to read
            // this.
#if !FEATURE_CORECLR
            if (s != null)
            {
                if (FrameworkEventSource.IsInitialized)
                {
                    FrameworkEventSource.Log.ResourceManagerManifestResourceAccessDenied(_mediator.BaseName, _mediator.MainAssembly, satellite.GetSimpleName(), canonicalName);
                }
            }
#endif
            return(s);
        }
Ejemplo n.º 37
0
 public void LastIndexOf_Char(CompareInfo compareInfo, string source, char value, int startIndex, int count, CompareOptions options, int expected)
 {
     if (options == CompareOptions.None)
     {
         // Use LastIndexOf(string, char, int, int) or LastIndexOf(string, char)
         if (startIndex + 1 == source.Length && count == source.Length)
         {
             // Use LastIndexOf(string, char)
             Assert.Equal(expected, compareInfo.LastIndexOf(source, value));
         }
         // Use LastIndexOf(string, char, int, int)
         Assert.Equal(expected, compareInfo.LastIndexOf(source, value, startIndex, count));
     }
     if (count - startIndex - 1 == 0)
     {
         // Use LastIndexOf(string, char, int, CompareOptions) or LastIndexOf(string, char, CompareOptions)
         if (startIndex == source.Length)
         {
             // Use LastIndexOf(string, char, CompareOptions)
             Assert.Equal(expected, compareInfo.LastIndexOf(source, value, options));
         }
         // Use LastIndexOf(string, char, int, CompareOptions)
         Assert.Equal(expected, compareInfo.LastIndexOf(source, value, startIndex, options));
     }
     // Use LastIndexOf(string, char, int, int, CompareOptions)
     Assert.Equal(expected, compareInfo.LastIndexOf(source, value, startIndex, count, options));
 }
Ejemplo n.º 38
0
        public void GetCompareInfo(string name)
        {
            CompareInfo compare = CompareInfo.GetCompareInfo(name);

            Assert.Equal(name, compare.Name);
        }
Ejemplo n.º 39
0
		public void FrameCompare(CompareInfo cCompareInfo, byte[] aFrameBytes)
        {
			_cInfo = cCompareInfo;
            //_aLayers = aLayers;
            //_aqQueue.Enqueue(this);
            //_cMREDone.WaitOne();
        }
Ejemplo n.º 40
0
 internal InvariantComparer()
 {
     m_compareInfo = CultureInfo.InvariantCulture.CompareInfo;
 }