## ctype<char>

                ctype_base
    ctype<char>
               locale::facet

- Summary
- Data Type and Member Function Indexes
- Synopsis
- Description
- Interface
- Types
- Constructors
- Destructors
- Public Member Functions
- Facet ID
- Protected Member Functions
- See Also

### Summary

A specialization of the ctype facet.

### Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Data Types
char_type id

Member Functions
classic_table() do_tolower() do_toupper() is() narrow() scan_is() | scan_not() table() tolower() toupper() widen()

### Synopsis

    #include <locale>
    class ctype<char>;

### Description

This specialization of the ctype<charT> template includes inline versions of ctype's member functions. The facet has the same public interface and uses the same set of masks as the ctype template.

### Interface

    template <>
    class ctype<char> : public locale::facet, public ctype_base {
      public:
        typedef char char_type;
        explicit ctype(const mask* = 0, bool = false,
                       size_t = 0);
        bool         is(mask, char) const;
        const char* is(const char*,
                        const char*, mask*) const;
        const char* scan_is(mask,
                             const char*,
                             const char*) const;
        const char* scan_not(mask,
                              const char*,
                              const char*) const;
        char        toupper(char) const;
        const char* toupper(char*, const char*) const;
        char        tolower(char) const;
        const char* tolower(char*, const char*) const;
        char        widen(char) const;
        const char*  widen(const char*,
                         const char*, char*) const;
        char         narrow(char, char) const;
        const char* narrow(const char*, const char*,
                            char, char*) const;
        static locale::id id;
        static const size_t table_size = 256;

      protected:
        const mask* table() const throw();
        static const mask* classic_table() throw();

    ~ctype();  // virtual
        virtual char        do_toupper(char) const;
        virtual const char* do_toupper(char*,
                                        const char*) const;
        virtual char        do_tolower(char) const;
        virtual const char* do_tolower(char*,
                                        const char*) const;
    };

### Types

    char_type

Type of character the facet is instantiated on.

### Constructors

    explicit ctype(const mask* tbl = 0, bool del = false,
                   size_t refs = 0)

Construct a ctype facet. The three parameters set up the following conditions:

- The `tbl` argument must be either `0` or an array of at least `table_size` elements. If `tbl` is non-zero, then the supplied table is used for character classification.

- If `tbl` is non zero, and `del` is `true`, then the `tbl` array is deleted by the destructor, so the calling program need not concern itself with the lifetime of the table.

- If the `refs` argument is `0`, then destruction of the object itself is delegated to the locale, or locales, containing it. This allows the user to ignore lifetime management issues. On the other hand, if `refs` is `1`, then the object must be explicitly deleted; the locale does not do so.

### Destructors

    ~ctype();  // virtual and protected

Destroy the facet. If the constructor was called with a non-zero `tbl` argument and a `true` `del` argument, then the array supplied by the `tbl` argument is deleted.

### Public Member Functions

The public members of the ctype<char> facet specialization do not all serve the same purpose as the functions in the template. In many cases these functions implement functionality, rather than just forwarding a call to a protected implementation function.

    static const mask*
    classic_table() throw();

Returns a pointer to a table_size character array that represents the classifications of characters in the "C" locale.

    bool
    is(mask m, char c) const;

Determines if the character `c` has the classification indicated by the mask `m`. Returns `table()[(unsigned char)c]` and `m.`

    const char*
    is(const char* low,
       const char* high, mask* vec) const;

Fills `vec` with every mask from ctype_base that applies to the range of characters indicated by `[low,high)`. See ctype_base for a description of the masks. For instance, after the following call, the first five elements of `v` would contain: `alpha|lower|print|xdigit|graph`}:

    char a[] = "abcde";
    ctype_base::mask v[12];
    ctype<char>().do_is(a,a+5,v);

Returns `high`.

    char
    narrow(char c, char dfault) const;

Returns `c`.

    const char*
    narrow(const char* low, const char*, char dfault,
           char* to) const;

Performs `::memcpy(to,low,high-low)`. Returns `high.`

    const char*
    scan_is(mask m, const char*, const char* high) const;

Finds the first character in the range `[low,high)` that matches the classification indicated by the mask `m`. The classification is matched by checking for `table()[(unsigned char) p] & m`, where `p` is in the range `[low,high)`. Returns the first `p` that matches, or `high` if none do.

    const char*
    scan_not(mask m, const char* low, const char* high) const;

Finds the first character in the range `[low,high)` that does not match the classification indicated by the mask `m`. The classification is matched by checking for `!(table()[(unsigned char) p] & m)`, where `p` is in the range [low,high). Returns the first `p` that matches, or `high` if none do.

    const mask*
    table() const throw();

If the `tbl` argument that was passed to the constructor was non-zero, then this function returns that argument. Otherwise it returns `classic_table()`.

    char
    tolower(char c) const;
    const char*
    tolower(char* low, const char* high) const;

Returns `do_tolower(c)` or `do_tolower(low,high).`

    char
    toupper(char) const;
    const char*
    toupper(char* low, const char* high) const;

Returns `do_toupper(c)` or `do_toupper(low,high).`

    char
    widen(char c) const;

Returns `c.`

    const char*
    widen(const char* low, const char* high, char* to) const;

Performs `::memcpy(to,low,high-low)`. Returns `high.`

### Facet ID

    static locale::id id;

Unique identifier for this type of facet.

### Protected Member Functions

    virtual char
    do_tolower(char) const;

Returns the lower case representation of `c,` if such exists. Otherwise returns `c`.

    virtual const char*
    do_tolower(char* low, const char* high) const;

Converts each character in the range `[low,high)` to its lower case representation, if such exists. If a lower case representation does not exist, then the character is not changed. Returns `high`.

    virtual char
    do_toupper(char c) const;

Returns the upper case representation of `c,` if such exists. Otherwise returns `c`.

    virtual const char*
    do_toupper(char* low, const char* high) const;

Converts each character in the range `[low,high)` to its upper case representation, if such exists. If an upper case representation does not exist, then the character is not changed. Returns `high`.

### See Also

locale, facets, collate, ctype<char>, ctype_byname

Copyright (c) 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998