Add two optimized versions of the ucs4 to local encoding.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18306 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-05-14 09:41:00 +00:00
parent e2da5d1771
commit c35007dbce
2 changed files with 44 additions and 0 deletions

View File

@ -307,4 +307,40 @@ ucs4_to_eightbit(char_type const * ucs4str, size_t ls, string const & encoding)
return iconv_convert<char>(processors[encoding], ucs4str, ls);
}
char ucs4_to_eightbit(char_type ucs4, string const & encoding)
{
static map<string, IconvProcessor> processors;
map<string, IconvProcessor>::iterator it = processors.find(encoding);
if (it == processors.end()) {
IconvProcessor processor(encoding.c_str(), ucs4_codeset);
it = processors.insert(make_pair(encoding, processor)).first;
}
char out;
int const bytes = it->second.convert((char *)(&ucs4), 4, &out, 1);
if (bytes > 0)
return out;
return 0;
}
void ucs4_to_multibytes(char_type ucs4, vector<char> & out,
string const & encoding)
{
static map<string, IconvProcessor> processors;
map<string, IconvProcessor>::iterator it = processors.find(encoding);
if (it == processors.end()) {
IconvProcessor processor(encoding.c_str(), ucs4_codeset);
it = processors.insert(make_pair(encoding, processor)).first;
}
out.resize(4);
int bytes = it->second.convert((char *)(&ucs4), 4, &out[0], 4);
if (bytes > 0)
out.resize(bytes);
else
out.clear();
}
} // namespace lyx

View File

@ -89,6 +89,14 @@ eightbit_to_ucs4(char const * s, size_t ls, std::string const & encoding);
std::vector<char>
ucs4_to_eightbit(char_type const * ucs4str, size_t ls, std::string const & encoding);
/// convert ucs4 character \p c to encoding \p encoding.
/// \p encoding must be a valid iconv 8bit encoding
char ucs4_to_eightbit(char_type c, std::string const & encoding);
///
void ucs4_to_multibytes(char_type ucs4, std::vector<char> & out,
std::string const & encoding);
extern char const * ucs4_codeset;