|
Boost : |
From: Alexander A Potocki (sane_at_[hidden])
Date: 2006-07-06 13:51:06
Hi boost community!
I would like to propose my iterator based conversion library.
It allows declaring and using transformations by following way:
std::wstring utf16string(Lâsome sequence to convertâ);
typedef cvt::encoder<wchar_t, char> coder_t;
coder_t coder = cvt::utf16() >> cvt::utf8();
That piece of code declares converter from wchar_t to char sequences and
then instantiate such converter by utf16 to utf8 transformation.
Then that converter instance can be used by following way:
typedef cvt::convert_input_iterator<coder_t, std::wstring::const_iterator >
it_t;
- declaration of input iterator
std::string result;
std::copy(
it_t(coder, utf16string.begin(), utf16string.end()),
it_t(coder, utf16string.end(), utf16string.end()),
std::back_inserter(result)
);
Now we have utf8 encoded string in result container. Thatâs all.
Library contains implementation for following transformations/algorithms:
utf7, utf8, utf16(be/le), utf32(be, le), Unicode simple folding, base64,
rc5(cipher/decipher).
Library allows creating pipeline converters, e.g.:
typedef cvt::encoder<char, char> coder_t; // char to char sequence
transformation
coder_t coder = cvt::utf7() >> cvt::utf16() >> cvt::utf8() / cvt::int8() >>
cvt::rc5<32,12,8>(key) / cvt::int8() >> cvt::base64();
That expression defines pipeline transformation. Utf7 encoded sequence
transforms to utf16 encoded sequence, then to utf8 encoded, then performs
rc5 cipher with specified key, then performs base64 encoding.
Library can be found at http://sourceforge.net/projects/trotter-cvt/
Alexander Potocki
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk