< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 18
Coverable lines: 18
Total lines: 70
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
Compare(...)100%110%
Equals(...)0%220%
GetHashCode()100%110%
ToString()100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Private.CoreLib/src/System/Globalization/SortKey.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Diagnostics;
 5using System.Diagnostics.CodeAnalysis;
 6
 7namespace System.Globalization
 8{
 9    /// <summary>Represents the result of mapping a string to its sort key.</summary>
 10    public sealed partial class SortKey
 11    {
 12        private readonly CompareInfo _compareInfo;
 13        private readonly CompareOptions _options;
 14        private readonly string _string;
 15        private readonly byte[] _keyData;
 16
 17        /// <summary>
 18        /// The following constructor is designed to be called from CompareInfo to get the
 19        /// the sort key of specific string for synthetic culture
 20        /// </summary>
 021        internal SortKey(CompareInfo compareInfo, string str, CompareOptions options, byte[] keyData)
 22        {
 023            _keyData = keyData;
 024            _compareInfo = compareInfo;
 025            _options = options;
 026            _string = str;
 027        }
 28
 29        /// <summary>
 30        /// Returns the original string used to create the current instance
 31        /// of SortKey.
 32        /// </summary>
 033        public string OriginalString => _string;
 34
 35        /// <summary>
 36        /// Returns a byte array representing the current instance of the
 37        /// sort key.
 38        /// </summary>
 039        public byte[] KeyData => (byte[])_keyData.Clone();
 40
 41        /// <summary>
 42        /// Compares the two sort keys.  Returns 0 if the two sort keys are
 43        /// equal, a number less than 0 if sortkey1 is less than sortkey2,
 44        /// and a number greater than 0 if sortkey1 is greater than sortkey2.
 45        /// </summary>
 46        public static int Compare(SortKey sortkey1, SortKey sortkey2)
 47        {
 048            ArgumentNullException.ThrowIfNull(sortkey1);
 049            ArgumentNullException.ThrowIfNull(sortkey2);
 50
 051            byte[] key1Data = sortkey1._keyData;
 052            byte[] key2Data = sortkey2._keyData;
 53
 054            Debug.Assert(key1Data != null);
 055            Debug.Assert(key2Data != null);
 56
 57            // SortKey comparisons are done as an ordinal comparison by the raw sort key bytes.
 58
 059            return new ReadOnlySpan<byte>(key1Data).SequenceCompareTo(key2Data);
 60        }
 61
 62        public override bool Equals([NotNullWhen(true)] object? value) =>
 063            value is SortKey other && new ReadOnlySpan<byte>(_keyData).SequenceEqual(other._keyData);
 64
 065        public override int GetHashCode() => _compareInfo.GetHashCode(_string, _options);
 66
 067        public override string ToString() => $"SortKey - {_compareInfo.Name}, {_options}, {_string}";
 68    }
 69}
 70