6.5.1 String Comparison by Using Sort Keys

To compare strings, the implementer needs to get a "sort key" for each string. A binary comparison of the sort keys can then be used to arrange the strings in any desired order.

This section utilizes the GetWindowsSortKey and CompareSortKeys procedures, which are specified in [MS-UCODEREF].

The flags that need to be passed to GetWindowsSortKey depend on the comparison being performed. This is specified in the following table.

Comparison being performed

Flags (from [MS-UCODEREF])

UnicodeString Comparison Rule (section 3.1.1.2.2.4.13)

LDAP_SERVER_SORT_OID sorting (section 3.1.1.3.4.1.13), except for phonetic display name sort

NORM_IGNORECASE | NORM_IGNOREKANATYPE | NORM_IGNORENONSPACE | NORM_IGNOREWIDTH

Phonetic display name sort (section 3.1.1.3.4.1.13)

NORM_IGNORECASE | NORM_IGNORENONSPACE

In order to compare two strings, StringA and StringB, the following procedure is used. The value of flags is as specified in the table above. The value of LCID is the locale identifier (section 2.2.1) for the locale being used to compare the strings. To determine what value to pass for LCID, see sections 3.1.1.2.2.4.13 and 3.1.1.3.4.1.13. Note that when performing phonetic display name sort, LCID MUST be set equal to "1.2.840.113556.1.4.1538" (the Japanese sort order).

 set SortKeyA to call GetWindowsSortKey(StringA, LCID, flags)
 set SortKeyB to call GetWindowsSortKey(StringB, LCID, flags)
 set Result to call CompareSortKeys(SortKeyA, SortKeyB)
 if Result is "SortKeyA is equal to SortKeyB"
  StringA is considered equal to StringB
 else if Result is "SortKeyA is less than SortKeyB"
  StringA is sorted prior to StringB
 else
  assert Result must be "SortKeyA is greater than SortKeyB"
  StringA is sorted after StringB
 endif

Any sorting mechanism can be used to arrange these strings by comparing their sort keys.