Author: bkoz@redhat.com (Benjamin Kosnik)
Keywords: HOWTO, libstdc++, GCC, g++, libg++, STL

# Notes on the ctype implementation.

prepared by Benjamin Kosnik (bkoz@redhat.com) on August 30, 2000

## 1. Abstract

Woe is me.

## 2. What the standard says

## 3. Problems with "C" ctype : global locales, termination.

For the required specialization codecvt<wchar_t, char, mbstate_t> , conversions are made between the internal character set (always UCS4 on GNU/Linux) and whatever the currently selected locale for the LC_CTYPE category implements.

## 4. Design

The two required specializations are implemented as follows:

`ctype<char>`

This is simple specialization. Implementing this was a piece of cake.

`ctype<wchar_t>`

This specialization, by specifying all the template parameters, pretty much ties the hands of implementors. As such, the implementation is straightforward, involving mcsrtombs for the conversions between char to wchar_t and wcsrtombs for conversions between wchar_t and char.

Neither of these two required specializations deals with Unicode characters. As such, libstdc++-v3 implements

## 5. Examples

      typedef ctype<char> cctype;

More information can be found in the following testcases:

- testsuite/22_locale/ctype_char_members.cc
- testsuite/22_locale/ctype_wchar_t_members.cc

## 6. Unresolved Issues

- how to deal with the global locale issue?
- how to deal with different types than char, wchar_t?
- codecvt/ctype overlap: narrow/widen
- mask typedef in codecvt_base, argument types in codecvt. what is know about this type?
- why mask* argument in codecvt?
- can this be made (more) generic? is there a simple way to straighten out the configure-time mess that is a by-product of this class?
- get the ctype<wchar_t>::mask stuff under control. Need to make some kind of static table, and not do lookup evertime somebody hits the do_is... functions. Too bad we can't just redefine mask for ctype<wchar_t>
- rename abstract base class. See if just smash-overriding is a better approach. Clarify, add sanity to naming.

## 7. Acknowledgments

Ulrich Drepper for patient answering of late-night questions, skeletal examples, and C language expertise.

## 8. Bibliography / Referenced Documents

Drepper, Ulrich, GNU libc (glibc) 2.2 manual. In particular, Chapters "6. Character Set Handling" and "7 Locales and Internationalization"

Drepper, Ulrich, Numerous, late-night email correspondence

ISO/IEC 14882:1998 Programming languages - C++

ISO/IEC 9899:1999 Programming languages - C

Langer, Angelika and Klaus Kreft, Standard C++ IOStreams and Locales, Advanced Programmer's Guide and Reference, Addison Wesley Longman, Inc. 2000

Stroustrup, Bjarne, Appendix D, The C++ Programming Language, Special Edition, Addison Wesley, Inc. 2000

System Interface Definitions, Issue 6 (IEEE Std. 1003.1-200x) The Open Group/The Institute of Electrical and Electronics Engineers, Inc. http://www.opennc.org/austin/docreg.html