BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlb_caselessstringviewequalto

Detailed Description

Outline

Purpose

Provide a case-insensitive equality predicate for string views.

Classes

See also
bdlb_caselessstringviewhash, bdlb_caselessstringviewless

Description

This component provides a struct, bdlb::CaselessStringViewEqualTo, that defines a functor that checks two string views for equality using a case-insensitive string comparison. This comparison functor is suitable for supporting bsl::strings or bsl::string_views as keys in unordered associative containers.

Note that using this component to do comparisons of keys in a container is less efficient than converting all the keys to the same case prior to insertion and then just doing straight string comparisons.

Usage

This section illustrates intended use of this component.

Example 1: Basic Use of bdlb::CaselessStringViewEqualTo

Suppose we have some strings that compare equal, some that don't, and some of which are equal except for the cases of some of the letters.

const bsl::string_view a = "To be or not to be, that is the question.";
const bsl::string_view b = "To be or not to be, THAT IS THE QUESTION.";
const bsl::string_view c = "Sein oder nicht sein, das ist die frage.";
Definition bslstl_stringview.h:441

Now, we create an object of type bdlb::CaselessStringViewEqualTo to do the comparisons:

Definition bdlb_caselessstringviewequalto.h:115

Finally, we observe that a matches b, but neither matches c:

assert( equals(a, b));
assert( equals(b, a));
assert(!equals(a, c));
assert(!equals(c, a));
assert(!equals(b, c));
assert(!equals(c, b));