Quick Links:

bal | bbl | bdl | bsl

Namespaces

Component bdlb_caselessstringviewequalto
[Package bdlb]

Provide a case-insensitive equality predicate for string views. More...

Namespaces

namespace  bdlb

Detailed Description

Outline
Purpose:
Provide a case-insensitive equality predicate for string views.
Classes:
bdlb::CaselessStringViewEqualTo case-insensitive string view comparison.
See also:
Component bdlb_caselessstringviewhash, Component 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.";
Now, we create an object of type bdlb::CaselessStringViewEqualTo to do the comparisons: 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));