public override int GetHashCode()
 {
     if (String == null)
         return 0;
     return Length == String.Length
         ? StringSegmentComparer.GetHashCodeOrdinal(String)
         : StringSegmentComparer.GetHashCodeOrdinal(String, Offset, Length);
 }
 internal int GetHashCodeOrdinalIgnoreCase()
 {
     if (String == null)
         return 0;
     return Length == String.Length
         ? StringSegmentComparer.GetHashCodeOrdinalIgnoreCase(String)
         : StringSegmentComparer.GetHashCodeOrdinalIgnoreCase(String, Offset, Length);
 }
Example #3
0
 internal int GetHashCodeOrdinalIgnoreCase()
 {
     if (str == null)
     {
         return(0);
     }
     return(length == str.Length
         ? StringSegmentComparer.GetHashCodeOrdinalIgnoreCase(str)
         : StringSegmentComparer.GetHashCodeOrdinalIgnoreCase(str, offset, length));
 }
Example #4
0
 public override int GetHashCode()
 {
     if (str == null)
     {
         return(0);
     }
     return(length == str.Length
         ? StringSegmentComparer.GetHashCodeOrdinal(str)
         : StringSegmentComparer.GetHashCodeOrdinal(str, offset, length));
 }
Example #5
0
        /// <summary>
        /// Returns the hash code for this <see cref="StringSegment"/> using the specified <paramref name="comparison"/>.
        /// </summary>
        /// <param name="comparison">A <see cref="StringComparison"/> value that specifies the way of generating the hash code.</param>
        /// <returns>A 32-bit signed integer hash code.</returns>
        /// <remarks>
        /// <para>If <paramref name="comparison"/> is <see cref="StringComparison.Ordinal"/> or <see cref="StringComparison.OrdinalIgnoreCase"/>, then no new string allocation occurs on any platforms.</para>
        /// <para>If <paramref name="comparison"/> is culture dependent (including the invariant culture), then depending on the targeted platform a new string allocation may occur.
        /// The .NET Core 3.0 and newer builds do not allocate a new string with any <paramref name="comparison"/> values.</para>
        /// </remarks>
        public int GetHashCode(StringComparison comparison)
        {
            switch (comparison)
            {
            case StringComparison.Ordinal:
                return(GetHashCode());

            case StringComparison.OrdinalIgnoreCase:
                return(GetHashCodeOrdinalIgnoreCase());

            case StringComparison.CurrentCulture:
            case StringComparison.CurrentCultureIgnoreCase:
            case StringComparison.InvariantCulture:
            case StringComparison.InvariantCultureIgnoreCase:
                return(StringSegmentComparer.FromComparison(comparison).GetHashCode(this));

            default:
                Throw.EnumArgumentOutOfRange(Argument.comparison, comparison);
                return(default);
            }
        }