|
result in ( stateT& state,
const externT* from, const externT* from_end, const externT*& from_next,
internT* to, internT* to_limit, internT*& to_next ) const;
Translate in characters
Translates sequentially the characters in the range [from,from_end) and places them in the range starting at to. It does not attempt to store more characters once to_limit is reached.
When the function returns, from_next and to_next point to one beyond the last element successfully converted.
The translation stops if a character cannot be translated, in which case it returns codecvt::error.
If the destination range cannot absorb all the characters to be translated, or if the generation of a new translated character requires more characters beyond from_end, it returns codecvt::partial.
If both template parameters internT and externT are the same type, the function simply copies the contents and returns codecvt::noconv.
On success, it returns codecvt::ok.
During its operation, this function simply calls the virtual protected member codecvt::do_in, which is the member function in charge of performing the actions described above.
Parameters
- state
- State object to keep track of the state of a multibyte character conversion. Typically, this is an object of type mbstate_t.
stateT is the state type (i.e., the third template parameter of codecvt).
- from, from_end
- Pointer to the initial and final characters of the source sequence. The range used is [from,from_end), which contains all the characters between from and from_end, including the character pointed by from but not the character pointed by from_end.
externT is the external character type (i.e., the second template parameter of codecvt).
- from_next
- Pointer type able to point to an element in the above range. Once the function returns, this object points to the element in the source range beyond the last one successfully translated.
- to, to_limit
- Pointer to the initial and final characters of the destination sequence. The range used is [to,to_limit), which contains all the characters between to and to_limit, including the character pointed by to but not the character pointed by to_limit.
A translation does not necessarily need to fill up the range to its limit, and may also exhaust it (in which case it returns codecvt::partial).
internT is the internal character type (i.e., the first template parameter of codecvt).
- to_next
- Pointer type able to point to an element in the above range. Once the function returns, this object points to the element in the destination range beyond the last one successfully translated.
Return value
An object of type codecvt::result, with the following possible values:
value | result |
ok | Conversion completed |
partial | Not all source characters converted |
error | A character in the source could not be converted |
noconv | Source and destination character types are the same. No conversion technique used. |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
// codecvt::in example
#include <iostream>
#include <locale>
#include <string>
using namespace std;
int main ()
{
locale mylocale;
mbstate_t mystate;
wstring mywstring;
const codecvt<wchar_t,char,mbstate_t>& myfacet =
use_facet<codecvt<wchar_t,char,mbstate_t> >(mylocale);
codecvt<wchar_t,char,mbstate_t>::result myresult;
char mystr[] = "Test string";
const size_t size = sizeof(mystr);
wchar_t pwstr[size];
const char* pc;
wchar_t* pwc;
// translate characters:
myresult = myfacet.in (mystate,
mystr, mystr+size, pc,
pwstr, pwstr+size, pwc);
if ( myresult == codecvt<wchar_t,char,mbstate_t>::ok )
{
cout << "Translation successful: ";
wcout << pwstr << endl;
}
return 0;
}
|
Output:
Translation successful: Test string
|
See also
codecvt::out | Translate out characters (public member function) |
codecvt::do_in | Translate in characters [virtual] (virtual protected member function) |
|