| Home | Libraries | People | FAQ | More

## Struct template cpp_regex_traits

boost::xpressive::cpp_regex_traits — Encapsaulates a `std::locale` for use by the `basic_regex<>` class template.

## Synopsis

    // In header: <boost/xpressive/xpressive_fwd.hpp>

    template<typename Char>
    struct cpp_regex_traits {
      // construct/copy/destruct
      cpp_regex_traits(locale_type const & = locale_type());

      // public member functions
      bool operator==(cpp_regex_traits< char_type > const &) const;
      bool operator!=(cpp_regex_traits< char_type > const &) const;
      char_type widen(char) const;
      char_type translate_nocase(char_type) const;
      char_type tolower(char_type) const;
      char_type toupper(char_type) const;
      string_type fold_case(char_type) const;
      bool in_range_nocase(char_type, char_type, char_type) const;
      template<typename FwdIter>
        string_type transform_primary(FwdIter, FwdIter) const;
      template<typename FwdIter>
        string_type lookup_collatename(FwdIter, FwdIter) const;
      template<typename FwdIter>
        char_class_type lookup_classname(FwdIter, FwdIter, bool) const;
      bool isctype(char_type, char_class_type) const;
      int value(char_type, int) const;
      locale_type imbue(locale_type);
      locale_type getloc() const;
      template<> unsigned char hash(unsigned char);
      template<> unsigned char hash(char);
      template<> unsigned char hash(signed char);
      template<> unsigned char hash(wchar_t);

      // public static functions
      static unsigned char hash(char_type);
      static char_type translate(char_type);
      static bool in_range(char_type, char_type, char_type);
    };

## Description

### `cpp_regex_traits` public construct/copy/destruct

1.     cpp_regex_traits(locale_type const & loc = locale_type());

   Initialize a `cpp_regex_traits` object to use the specified std::locale, or the global std::locale if none is specified.

### `cpp_regex_traits` public member functions

1.     bool operator==(cpp_regex_traits< char_type > const & that) const;

   Checks two `cpp_regex_traits` objects for equality

   Returns: | this->getloc() == that.getloc().

2.     bool operator!=(cpp_regex_traits< char_type > const & that) const;

   Checks two `cpp_regex_traits` objects for inequality

   Returns: | this->getloc() != that.getloc().

3.     char_type widen(char ch) const;

   Convert a char to a Char

   Parameters: |
   `ch` | The source character.
   Returns: | std::use_facet<std::ctype<char_type> >(this->getloc()).widen(ch).

4.     char_type translate_nocase(char_type ch) const;

   Converts a character to lower-case using the internally-stored std::locale.

   Parameters: |
   `ch` | The source character.
   Returns: | std::tolower(ch, this->getloc()).

5.     char_type tolower(char_type ch) const;

   Converts a character to lower-case using the internally-stored std::locale.

   Parameters: |
   `ch` | The source character.
   Returns: | std::tolower(ch, this->getloc()).

6.     char_type toupper(char_type ch) const;

   Converts a character to upper-case using the internally-stored std::locale.

   Parameters: |
   `ch` | The source character.
   Returns: | std::toupper(ch, this->getloc()).

7.     string_type fold_case(char_type ch) const;

   Returns a `string_type` containing all the characters that compare equal disregrarding case to the one passed in. This function can only be called if ``has_fold_case`<`cpp_regex_traits`<Char> >::value` is `true`.

   Parameters: |
   `ch` | The source character.
   Returns: | `string_type` containing all chars which are equal to `ch` when disregarding case

8.     bool in_range_nocase(char_type first, char_type last, char_type ch) const;

   Checks to see if a character is within a character range, irregardless of case.

   | Note
   The default implementation doesn't do proper Unicode case folding, but this is the best we can do with the standard ctype facet.

   Parameters: |
   `ch` | The source character.
   `first` | The bottom of the range, inclusive.
   `last` | The top of the range, inclusive.
   Returns: | in_range(first, last, ch) || in_range(first, last, tolower(ch, this->getloc())) || in_range(first, last, toupper(ch, this->getloc()))

9.     template<typename FwdIter>
         string_type transform_primary(FwdIter, FwdIter) const;

   Returns a sort key for the character sequence designated by the iterator range [F1, F2) such that if the character sequence [G1, G2) sorts before the character sequence [H1, H2) when character case is not considered then v.transform_primary(G1, G2) < v.transform_primary(H1, H2).

   | Note
   Not currently used

10.     template<typename FwdIter>
          string_type lookup_collatename(FwdIter, FwdIter) const;

    Returns a sequence of characters that represents the collating element consisting of the character sequence designated by the iterator range [F1, F2). Returns an empty string if the character sequence is not a valid collating element.

    | Note
    Not currently used

11.     template<typename FwdIter>
          char_class_type
          lookup_classname(FwdIter begin, FwdIter end, bool icase) const;

    For the character class name represented by the specified character sequence, return the corresponding bitmask representation.

    Parameters: |
    `begin` | A forward iterator to the start of the character sequence representing the name of the character class.
    `end` | The end of the character sequence.
    `icase` | Specifies whether the returned bitmask should represent the case-insensitive version of the character class.
    Returns: | A bitmask representing the character class.

12.     bool isctype(char_type ch, char_class_type mask) const;

    Tests a character against a character class bitmask.

    Parameters: |
    `ch` | The character to test.
    `mask` | The character class bitmask against which to test.
    Requires: | mask is a bitmask returned by lookup_classname, or is several such masks bit-or'ed together.
    Returns: | true if the character is a member of any of the specified character classes, false otherwise.

13.     int value(char_type ch, int radix) const;

    Convert a digit character into the integer it represents.

    Parameters: |
    `ch` | The digit character.
    `radix` | The radix to use for the conversion.
    Requires: | radix is one of 8, 10, or 16.
    Returns: | -1 if ch is not a digit character, the integer value of the character otherwise. The conversion is performed by imbueing a std::stringstream with this->getloc(); setting the radix to one of oct, hex or dec; inserting ch into the stream; and extracting an int.

14.     locale_type imbue(locale_type loc);

    Imbues *this with loc

    Parameters: |
    `loc` | A std::locale.
    Returns: | the previous std::locale used by *this.

15.     locale_type getloc() const;

    Returns the current std::locale used by *this.

16.     template<> unsigned char hash(unsigned char ch);

17.     template<> unsigned char hash(char ch);

18.     template<> unsigned char hash(signed char ch);

19.     template<> unsigned char hash(wchar_t ch);

### `cpp_regex_traits` public static functions

1.     static unsigned char hash(char_type ch);

   Returns a hash value for a Char in the range [0, UCHAR_MAX]

   Parameters: |
   `ch` | The source character.
   Returns: | a value between 0 and UCHAR_MAX, inclusive.

2.     static char_type translate(char_type ch);

   No-op

   Parameters: |
   `ch` | The source character.
   Returns: | ch

3.     static bool in_range(char_type first, char_type last, char_type ch);

   Checks to see if a character is within a character range.

   Parameters: |
   `ch` | The source character.
   `first` | The bottom of the range, inclusive.
   `last` | The top of the range, inclusive.
   Returns: | first <= ch && ch <= last.