private int LinearIndexOf(string fieldName, CompareOptions compareOptions)
 {
     CompareInfo compareInfo = this._compareInfo;
     if (compareInfo == null)
     {
         if (-1 != this._defaultLocaleID)
         {
             compareInfo = CompareInfo.GetCompareInfo(this._defaultLocaleID);
         }
         if (compareInfo == null)
         {
             compareInfo = CultureInfo.InvariantCulture.CompareInfo;
         }
         this._compareInfo = compareInfo;
     }
     int length = this._fieldNames.Length;
     for (int i = 0; i < length; i++)
     {
         if (compareInfo.Compare(fieldName, this._fieldNames[i], compareOptions) == 0)
         {
             this._fieldNameLookup[fieldName] = i;
             return i;
         }
     }
     return -1;
 }
Exemplo n.º 2
0
 public Comparer(CultureInfo culture) {
     if (culture==null) {
         throw new ArgumentNullException("culture");
     }
     Contract.EndContractBlock();
     m_compareInfo = culture.CompareInfo;
 }
Exemplo n.º 3
0
		Comparer (CultureInfo culture)
		{
			if (culture == null)
				throw new ArgumentNullException ("culture");

			m_compareInfo = culture.CompareInfo;
		}
Exemplo n.º 4
0
 //--- Constructors ---
 /// <summary>
 /// Create comparer based on culture.
 /// </summary>
 /// <param name="culture">Culture to get <see cref="CompareInfo"/> from.</param>
 public CultureComparer(CultureInfo culture)
 {
     if(culture == null) {
         throw new ArgumentNullException("culture");
     }
     _cultureCompare = culture.CompareInfo;
 }
Exemplo n.º 5
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="comparer">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);
            if(isDefault) {
                env.declareDefaultCollation(uri.ToString());
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Construct a new PatternMatcher using the specified culture.
        /// </summary>
        /// <param name="pattern">The pattern to make the pattern matcher for.</param>
        /// <param name="culture">The culture to use for string searching and comparison.</param>
        /// <param name="verbatimIdentifierPrefixIsWordCharacter">Whether to consider "@" as a word character</param>
        /// <param name="allowFuzzyMatching">Whether or not close matches should count as matches.</param>
        public PatternMatcher(
            string pattern,
            CultureInfo culture,
            bool verbatimIdentifierPrefixIsWordCharacter,
            bool allowFuzzyMatching)
        {
            pattern = pattern.Trim();
            _compareInfo = culture.CompareInfo;
            _allowFuzzyMatching = allowFuzzyMatching;

            _fullPatternSegment = new Segment(pattern, verbatimIdentifierPrefixIsWordCharacter, allowFuzzyMatching);

            if (pattern.IndexOf('.') < 0)
            {
                // PERF: Avoid string.Split allocations when the pattern doesn't contain a dot.
                _dotSeparatedSegments = pattern.Length > 0
                    ? new Segment[1] { _fullPatternSegment }
                    : Array.Empty<Segment>();
            }
            else
            {
                _dotSeparatedSegments = pattern.Split(s_dotCharacterArray, StringSplitOptions.RemoveEmptyEntries)
                                                .Select(text => new Segment(text.Trim(), verbatimIdentifierPrefixIsWordCharacter, allowFuzzyMatching))
                                                .ToArray();
            }

            _invalidPattern = _dotSeparatedSegments.Length == 0 || _dotSeparatedSegments.Any(s => s.IsInvalid);
        }
 public SqlString(int lcid, System.Data.SqlTypes.SqlCompareOptions compareOptions, byte[] data, int index, int count, bool fUnicode)
 {
     this.m_lcid = lcid;
     ValidateSqlCompareOptions(compareOptions);
     this.m_flag = compareOptions;
     if (data == null)
     {
         this.m_fNotNull = false;
         this.m_value = null;
         this.m_cmpInfo = null;
     }
     else
     {
         this.m_fNotNull = true;
         this.m_cmpInfo = null;
         if (fUnicode)
         {
             this.m_value = x_UnicodeEncoding.GetString(data, index, count);
         }
         else
         {
             System.Globalization.CultureInfo info = new System.Globalization.CultureInfo(this.m_lcid);
             this.m_value = Encoding.GetEncoding(info.TextInfo.ANSICodePage).GetString(data, index, count);
         }
     }
 }
Exemplo n.º 8
0
 public CharacterTest()
 {
     _MarvelPublicKey = "67d146c4c462f0b55bf12bb7d60948af";
     _MarvelPrivateKey = "54fd1a8ac788767cc91938bcb96755186074970b";
     _Marvel = new Marvel(_MarvelPublicKey, _MarvelPrivateKey);
     _Comparer = CompareInfo.GetCompareInfo("en-US");
 }
 public CaseInsensitiveComparer(CultureInfo culture)
 {
     if (culture == null)
     {
         throw new ArgumentNullException("culture");
     }
     this.m_compareInfo = culture.CompareInfo;
 }
 public CaseInsensitiveHashCodeProvider(CultureInfo culture)
 {
     if (culture == null)
     {
         throw new ArgumentNullException(nameof(culture));
     }
     _compareInfo = culture.CompareInfo;
 }
 private SqlString(bool fNull)
 {
     this.m_value = null;
     this.m_cmpInfo = null;
     this.m_lcid = 0;
     this.m_flag = System.Data.SqlTypes.SqlCompareOptions.None;
     this.m_fNotNull = false;
 }
Exemplo n.º 12
0
 public CaseInsensitiveComparer(CultureInfo culture)
 {
     if (culture == null)
     {
         throw new ArgumentNullException(nameof(culture));
     }
     Contract.EndContractBlock();
     _compareInfo = culture.CompareInfo;
 }
Exemplo n.º 13
0
	void AssertCompare (string message, int result, string s1, string s2,
		CompareOptions opt, CompareInfo ci)
	{
		int ret = ci.Compare (s1, s2, opt);
		if (result == 0)
			AssertEquals (message, 0, ret);
		else if (result < 0)
			Assert.IsTrue (message + String.Format ("(neg: {0})", ret), ret < 0);
		else
			Assert.IsTrue (message + String.Format ("(pos: {0})", ret), ret > 0);
	}
Exemplo n.º 14
0
 private Comparer(SerializationInfo info, StreamingContext context) {            
     m_compareInfo = null;
     SerializationInfoEnumerator enumerator = info.GetEnumerator();                        
     while( enumerator.MoveNext()) {
         switch( enumerator.Name) {
             case CompareInfoName:
                 m_compareInfo = (CompareInfo) info.GetValue(CompareInfoName, typeof(CompareInfo));
                 break;
         }
     }
 }
Exemplo n.º 15
0
 private Comparer(SerializationInfo info, StreamingContext context)
 {
     this.m_compareInfo = null;
     SerializationInfoEnumerator enumerator = info.GetEnumerator();
     while (enumerator.MoveNext())
     {
         string str;
         if (((str = enumerator.Name) != null) && (str == "CompareInfo"))
         {
             this.m_compareInfo = (CompareInfo) info.GetValue("CompareInfo", typeof(CompareInfo));
         }
     }
 }
Exemplo n.º 16
0
    private static string GetRelativePath(string fullPath)
    {
        string currentDir = Directory.GetCurrentDirectory();

        if (currentDir == null || currentDir.Length == 0)
        {
            return(fullPath);
        }
        System.Globalization.CompareInfo compInfo = System.Globalization.CultureInfo.InvariantCulture.CompareInfo;
        if (compInfo.IsPrefix(fullPath, currentDir, System.Globalization.CompareOptions.IgnoreCase))
        {
            return(fullPath.Substring(currentDir.Length + 1));
        }
        return(fullPath);
    }
Exemplo n.º 17
0
		internal __DTString(string str, DateTimeFormatInfo dtfi)
		{
			this.Index = -1;
			this.Value = str;
			this.len = this.Value.Length;
			this.m_current = '\0';
			if (dtfi != null)
			{
				this.m_info = dtfi.CompareInfo;
				this.m_checkDigitToken = ((dtfi.FormatFlags & DateTimeFormatFlags.UseDigitPrefixInTokens) != DateTimeFormatFlags.None);
				return;
			}
			this.m_info = Thread.CurrentThread.CurrentCulture.CompareInfo;
			this.m_checkDigitToken = false;
		}
 public SqlString(string data, int lcid, System.Data.SqlTypes.SqlCompareOptions compareOptions)
 {
     this.m_lcid = lcid;
     ValidateSqlCompareOptions(compareOptions);
     this.m_flag = compareOptions;
     this.m_cmpInfo = null;
     if (data == null)
     {
         this.m_fNotNull = false;
         this.m_value = null;
     }
     else
     {
         this.m_fNotNull = true;
         this.m_value = data;
     }
 }
Exemplo n.º 19
0
 /// <summary>
 /// Attempts to match the specified string with the current point in the string in a case-insensitive
 /// manner, according to the given comparison info.
 /// </summary>
 internal bool MatchCaseInsensitive(string match, CompareInfo compareInfo)
 {
     unchecked
     {
         if (match.Length > Value.Length - Index)
         {
             return false;
         }
         // FIXME: This will fail if the length in the input string is different to the length in the
         // match string for culture-specific reasons. It's not clear how to handle that...
         if (compareInfo.Compare(Value, Index, match.Length, match, 0, match.Length, CompareOptions.IgnoreCase) == 0)
         {
             Move(Index + match.Length);
             return true;
         }
         return false;
     }
 }
        /*
         * <summary>Customised Compare Class</summary>
         * <remarks>
         * <para>
         * The Virtual Payment Client need to use an Ordinal comparison to Sort on
         * the field names to create the MD5 Signature for validation of the message.
         * This class provides a Compare method that is used to allow the sorted list
         * to be ordered using an Ordinal comparison.
         * </para>
         * </remarks>
         */

        public int Compare(Object a, Object b)
        {
            /*
             * <summary>Compare method using Ordinal comparison</summary>
             * <param name="a">The first string in the comparison.</param>
             * <param name="b">The second string in the comparison.</param>
             * <returns>An int containing the result of the comparison.</returns>
             */

            // Return if we are comparing the same object or one of the
            // objects is null, since we don't need to go any further.
            if (a == b)
            {
                return(0);
            }
            if (a == null)
            {
                return(-1);
            }
            if (b == null)
            {
                return(1);
            }

            // Ensure we have string to compare
            string sa = a as string;
            string sb = b as string;

            // Get the CompareInfo object to use for comparing
            System.Globalization.CompareInfo myComparer = System.Globalization.CompareInfo.GetCompareInfo("en-US");
            if (sa != null && sb != null)
            {
                // Compare using an Ordinal Comparison.
                return(myComparer.Compare(sa, sb, System.Globalization.CompareOptions.Ordinal));
            }
            throw new ArgumentException("a and b should be strings.");
        }
Exemplo n.º 21
0
 private int LinearIndexOf(string fieldName, CompareOptions compareOptions) {
     CompareInfo compareInfo = _compareInfo;
     if (null == compareInfo) {
         if (-1 != _defaultLocaleID) {
             compareInfo = CompareInfo.GetCompareInfo(_defaultLocaleID);
         }
         if (null == compareInfo) {
             compareInfo = CultureInfo.InvariantCulture.CompareInfo;
         }
         _compareInfo = compareInfo;
     }
     int length = _fieldNames.Length;
     for (int i = 0; i < length; ++i) {
         if (0 == compareInfo.Compare(fieldName, _fieldNames[i], compareOptions)) {
             _fieldNameLookup[fieldName] = i; // add an exact match for the future
             return i;
         }
     }
     return -1;
 }
Exemplo n.º 22
0
        // Constructor called by SQL Server's special munged culture - creates a culture with
        // a TextInfo and CompareInfo that come from a supplied alternate source. This object
        // is ALWAYS read-only.
        // Note that we really cannot use an LCID version of this override as the cached
        // name we create for it has to include both names, and the logic for this is in
        // the GetCultureInfo override *only*.
        internal CultureInfo(String cultureName, String textAndCompareCultureName)
        {
            if (cultureName == null)
            {
                throw new ArgumentNullException("cultureName",SR.ArgumentNull_String);
            }
            Contract.EndContractBlock();

            m_cultureData = CultureData.GetCultureData(cultureName, false);
            if (m_cultureData == null)
                throw new CultureNotFoundException("cultureName", cultureName, SR.Argument_CultureNotSupported);
            
            m_name = m_cultureData.CultureName;

            CultureInfo altCulture = GetCultureInfo(textAndCompareCultureName);
            compareInfo = altCulture.CompareInfo;
            textInfo = altCulture.TextInfo;
        }
 internal CultureAwareComparer(CultureInfo culture, bool ignoreCase)
 {
     _compareInfo = culture.CompareInfo;
     _ignoreCase = ignoreCase;
 }
Exemplo n.º 24
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;
            }
        }
Exemplo n.º 25
0
 internal CultureAwareComparer(CultureInfo culture, bool ignoreCase)
 {
     _compareInfo = culture.CompareInfo;
     _ignoreCase  = ignoreCase;
 }
Exemplo n.º 26
0
            private StringComparer(CultureInfo culture)
            {
                Debug.Assert(culture != null);

                _compareInfo = culture.CompareInfo;
            }
Exemplo n.º 27
0
 /// <summary> <strong>WARNING:</strong> Using this constructor and supplying a non-null
 /// value in the <c>collator</c> parameter will cause every single
 /// index Term in the Field referenced by lowerTerm and/or upperTerm to be
 /// examined.  Depending on the number of index Terms in this Field, the
 /// operation could be very slow.
 ///
 /// </summary>
 /// <param name="fieldName"></param>
 /// <param name="lowerTerm">The lower bound on this range
 /// </param>
 /// <param name="upperTerm">The upper bound on this range
 /// </param>
 /// <param name="includeLower">Does this range include the lower bound?
 /// </param>
 /// <param name="includeUpper">Does this range include the upper bound?
 /// </param>
 /// <param name="collator">The collator to use when determining range inclusion; set
 /// to null to use Unicode code point ordering instead of collation.
 /// </param>
 /// <throws>  IllegalArgumentException if both terms are null or if </throws>
 /// <summary>  lowerTerm is null and includeLower is true (similar for upperTerm
 /// and includeUpper)
 /// </summary>
 public TermRangeFilter(System.String fieldName, System.String lowerTerm, System.String upperTerm, bool includeLower, bool includeUpper, System.Globalization.CompareInfo collator) : base(new TermRangeQuery(fieldName, lowerTerm, upperTerm, includeLower, includeUpper, collator))
 {
 }
Exemplo n.º 28
0
 private SqlString(int lcid, System.Data.SqlTypes.SqlCompareOptions compareOptions, string data, System.Globalization.CompareInfo cmpInfo)
 {
     this.m_lcid = lcid;
     ValidateSqlCompareOptions(compareOptions);
     this.m_flag = compareOptions;
     if (data == null)
     {
         this.m_fNotNull = false;
         this.m_value    = null;
         this.m_cmpInfo  = null;
     }
     else
     {
         this.m_value    = data;
         this.m_cmpInfo  = cmpInfo;
         this.m_fNotNull = true;
     }
 }
Exemplo n.º 29
0
 /// <summary>Constructs a query selecting all terms greater/equal than
 /// <c>lowerTerm</c> but less/equal than <c>upperTerm</c>.
 /// <p/>
 /// If an endpoint is null, it is said 
 /// to be "open". Either or both endpoints may be open.  Open endpoints may not 
 /// be exclusive (you can't select all but the first or last term without 
 /// explicitly specifying the term to exclude.)
 /// <p/>
 /// If <c>collator</c> is not null, it will be used to decide whether
 /// index terms are within the given range, rather than using the Unicode code
 /// point order in which index terms are stored.
 /// <p/>
 /// <strong>WARNING:</strong> Using this constructor and supplying a non-null
 /// value in the <c>collator</c> parameter will cause every single 
 /// index Term in the Field referenced by lowerTerm and/or upperTerm to be
 /// examined.  Depending on the number of index Terms in this Field, the 
 /// operation could be very slow.
 /// 
 /// </summary>
 /// <param name="field"></param>
 /// <param name="lowerTerm">The Term text at the lower end of the range
 /// </param>
 /// <param name="upperTerm">The Term text at the upper end of the range
 /// </param>
 /// <param name="includeLower">If true, the <c>lowerTerm</c> is
 /// included in the range.
 /// </param>
 /// <param name="includeUpper">If true, the <c>upperTerm</c> is
 /// included in the range.
 /// </param>
 /// <param name="collator">The collator to use to collate index Terms, to determine
 /// their membership in the range bounded by <c>lowerTerm</c> and
 /// <c>upperTerm</c>.
 /// </param>
 public TermRangeQuery(System.String field, System.String lowerTerm, System.String upperTerm, bool includeLower, bool includeUpper, System.Globalization.CompareInfo collator)
 {
     this.field = field;
     this.lowerTerm = lowerTerm;
     this.upperTerm = upperTerm;
     this.includeLower = includeLower;
     this.includeUpper = includeUpper;
     this.collator = collator;
 }
Exemplo n.º 30
0
 static StringExtensions()
 {
     _invariantCompareInfo = System.Globalization.CultureInfo.InvariantCulture.CompareInfo;
 }
Exemplo n.º 31
0
        internal bool SetLocaleValue(CultureInfo culture, bool userSet, bool resetIndexes) {
            Debug.Assert(null != culture, "SetLocaleValue: no locale");
            if (userSet || resetIndexes || (!_cultureUserSet && !_culture.Equals(culture))) {
                _culture = culture;
                _compareInfo = null;
                _formatProvider = null;
                _hashCodeProvider = null;

                foreach(DataColumn column in Columns) {
                    column._hashCode = GetSpecialHashCode(column.ColumnName);
                }
                if (resetIndexes) {
                    ResetIndexes();
                    foreach (Constraint constraint in Constraints) {
                        constraint.CheckConstraint();
                    }
                }
                return true;
            }
            return false;
        }
Exemplo n.º 32
0
	void AssertCompare (string message, int result,
		string s1, int idx1, int len1, string s2, int idx2, int len2,
		CompareOptions opt, CompareInfo ci)
	{
		int ret = ci.Compare (s1, idx1, len1, s2, idx2, len2, opt);
		if (result == 0)
			Assert.AreEqual (0, ret, message);
		else if (result < 0)
			Assert.IsTrue (ret < 0, message);
		else
			Assert.IsTrue (ret > 0, message);
	}
Exemplo n.º 33
0
 ////////////////////////////////////////////////////////////////////////
 //
 //  GetHashCode
 //
 //  Implements Object.GetHashCode().  Returns the hash code for the
 //  SortKey.  The hash code is guaranteed to be the same for
 //  SortKey A and B where A.Equals(B) is true.
 //
 ////////////////////////////////////////////////////////////////////////
 public override int GetHashCode()
 {
     return(CompareInfo.GetCompareInfo(_localeName).GetHashCodeOfString(_string, _options));
 }
Exemplo n.º 34
0
	void AssertLastIndexOf (string message, int expected, string source,
		string target, int idx, int len, CompareOptions opt, CompareInfo ci)
	{
		Assert.AreEqual (expected, ci.LastIndexOf (source, target, idx, len, opt), message);
	}
Exemplo n.º 35
0
	void AssertSortKey (string message, byte [] expected, string test, CompareOptions opt, CompareInfo ci)
	{
		byte [] actual = ci.GetSortKey (test, opt).KeyData;
		Assert.AreEqual (expected, actual, message);
	}
Exemplo n.º 36
0
        /// <summary>
        /// Construct a new PatternMatcher using the specified culture.
        /// </summary>
        /// <param name="pattern">The pattern to make the pattern matcher for.</param>
        /// <param name="culture">The culture to use for string searching and comparison.</param>
        /// <param name="verbatimIdentifierPrefixIsWordCharacter">Whether to consider "@" as a word character</param>
        public PatternMatcher(string pattern, CultureInfo culture, bool verbatimIdentifierPrefixIsWordCharacter)
        {
            pattern = pattern.Trim();
            _compareInfo = culture.CompareInfo;

            _fullPatternSegment = new Segment(pattern, verbatimIdentifierPrefixIsWordCharacter);
            _dotSeparatedSegements = pattern.Split(DotCharacterArray, StringSplitOptions.RemoveEmptyEntries)
                                            .Select(text => new Segment(text.Trim(), verbatimIdentifierPrefixIsWordCharacter))
                                            .ToArray();
            _invalidPattern = _dotSeparatedSegements.Length == 0 || _dotSeparatedSegements.Any(s => s.IsInvalid);
        }
Exemplo n.º 37
0
 public static System.StringComparer GetStringComparer(this System.Globalization.CompareInfo compareInfo, System.Globalization.CompareOptions options)
 {
     throw null;
 }
Exemplo n.º 38
0
 /// <summary>
 /// Construct a new PatternMatcher using the specified culture.
 /// </summary>
 /// <param name="culture">The culture to use for string searching and comparison.</param>
 /// <param name="verbatimIdentifierPrefixIsWordCharacter">Whether to consider "@" as a word character</param>
 public PatternMatcher(CultureInfo culture, bool verbatimIdentifierPrefixIsWordCharacter)
 {
     _compareInfo = culture.CompareInfo;
     _breakPatternIntoParts = (pattern) => BreakPatternIntoParts(pattern, verbatimIdentifierPrefixIsWordCharacter);
 }
Exemplo n.º 39
0
 private Comparer()
 {
     this.compareInfo = null;
 }
Exemplo n.º 40
0
        internal int Compare(string s1, string s2, CompareInfo comparer) {
            object obj1 = s1;
            object obj2 = s2;
            if (obj1 == obj2)
                return 0;
            if (obj1 == null)
                return -1;
            if (obj2 == null)
                return 1;

            int leng1 = s1.Length;
            int leng2 = s2.Length;

            for (; leng1 > 0; leng1--) {
                if (s1[leng1-1] != 0x20 && s1[leng1-1] != 0x3000) // 0x3000 is Ideographic Whitespace
                    break;
            }
            for (; leng2 > 0; leng2--) {
                if (s2[leng2-1] != 0x20 && s2[leng2-1] != 0x3000)
                    break;
            }

            return (comparer ?? this.CompareInfo).Compare(s1, 0, leng1, s2, 0, leng2, _compareFlags);
        }
Exemplo n.º 41
0
 internal CultureAwareComparer(CompareInfo compareInfo, CompareOptions options)
 {
     Debug.Assert((options & ValidCompareMaskOffFlags) == 0);
     _compareInfo = compareInfo;
     _options     = options;
 }