| Home | Libraries | People | FAQ | More

## Struct template c_regex_traits

boost::xpressive::c_regex_traits — Encapsaulates the standard C locale functions for use by the basic_regex<> class template.

## Synopsis

    // In header: <boost/xpressive/traits/c_regex_traits.hpp>

    template<typename Char>
    struct c_regex_traits {
      // types
      typedef Char                           char_type;
      typedef std::basic_string< char_type > string_type;
      typedef unspecified                    locale_type;
      typedef unspecified                    char_class_type;
      typedef regex_traits_version_2_tag     version_tag;
      typedef unspecified                    base_type;

      // construct/copy/destruct
      c_regex_traits(locale_type const & = locale_type());

      // public member functions
      bool operator==(c_regex_traits< char_type > const &) const;
      bool operator!=(c_regex_traits< char_type > const &) const;
      string_type fold_case(char_type) const;
      locale_type imbue(locale_type);
      template<> char widen(char);
      template<> wchar_t widen(char);
      template<> unsigned char hash(char);
      template<> unsigned char hash(wchar_t);
      template<> int value(char, int);
      template<> int value(wchar_t, int);

      // public static functions
      static char_type widen(char);
      static unsigned char hash(char_type);
      static char_type translate(char_type);
      static char_type translate_nocase(char_type);
      static char_type tolower(char_type);
      static char_type toupper(char_type);
      static bool in_range(char_type, char_type, char_type);
      static bool in_range_nocase(char_type, char_type, char_type);
      template<typename FwdIter> static string_type transform(FwdIter, FwdIter);
      template<typename FwdIter>
        static string_type transform_primary(FwdIter, FwdIter);
      template<typename FwdIter>
        static string_type lookup_collatename(FwdIter, FwdIter);
      template<typename FwdIter>
        static char_class_type lookup_classname(FwdIter, FwdIter, bool);
      static bool isctype(char_type, char_class_type);
      static int value(char_type, int);
      static locale_type getloc();
    };

## Description

### `c_regex_traits` public construct/copy/destruct

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

   Initialize a c_regex_traits object to use the global C locale.

### `c_regex_traits` public member functions

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

   Checks two c_regex_traits objects for equality

   Returns: | true.

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

   Checks two c_regex_traits objects for inequality

   Returns: | false.

3.     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<c_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

4.     locale_type imbue(locale_type loc);

   No-op

5.     template<> char widen(char ch);

6.     template<> wchar_t widen(char ch);

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

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

9.     template<> int value(char ch, int radix);

10.     template<> int value(wchar_t ch, int radix);

### `c_regex_traits` public static functions

1.     static char_type widen(char ch);

   Convert a char to a Char

   Parameters: |
   `ch` | The source character.
   Returns: | ch if Char is char, std::btowc(ch) if Char is wchar_t.

2.     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.

3.     static char_type translate(char_type ch);

   No-op

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

4.     static char_type translate_nocase(char_type ch);

   Converts a character to lower-case using the current global C locale.

   Parameters: |
   `ch` | The source character.
   Returns: | std::tolower(ch) if Char is char, std::towlower(ch) if Char is wchar_t.

5.     static char_type tolower(char_type ch);

   Converts a character to lower-case using the current global C locale.

   Parameters: |
   `ch` | The source character.
   Returns: | std::tolower(ch) if Char is char, std::towlower(ch) if Char is wchar_t.

6.     static char_type toupper(char_type ch);

   Converts a character to upper-case using the current global C locale.

   Parameters: |
   `ch` | The source character.
   Returns: | std::toupper(ch) if Char is char, std::towupper(ch) if Char is wchar_t.

7.     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.

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

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

   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)) || in_range(first, last, toupper(ch))
   Notes: | The default implementation doesn't do proper Unicode case folding, but this is the best we can do with the standard C locale functions.

9.     template<typename FwdIter>
         static string_type transform(FwdIter begin, FwdIter end);

   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) then v.transform(G1, G2) < v.transform(H1, H2).

   Notes: | Not currently used

10.     template<typename FwdIter>
          static string_type transform_primary(FwdIter begin, FwdIter end);

    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).

    Notes: | Not currently used

11.     template<typename FwdIter>
          static string_type lookup_collatename(FwdIter begin, FwdIter end);

    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.

    Notes: | Not currently used

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

    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.

13.     static bool isctype(char_type ch, char_class_type mask);

    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.

14.     static int value(char_type ch, int radix);

    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. If char_type is char, std::strtol is used for the conversion. If char_type is wchar_t, std::wcstol is used.

15.     static locale_type getloc();

    No-op