cosmetics

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21853 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-11-29 07:24:55 +00:00
parent efbf9fec5e
commit 9160d824d8
3 changed files with 39 additions and 51 deletions

View File

@ -17,6 +17,7 @@
#include "support/Package.h"
#include "support/unicode.h"
#include <boost/assert.hpp>
#include <boost/current_function.hpp>
#include <cerrno>

View File

@ -52,47 +52,47 @@ namespace lyx {
static const iconv_t invalid_cd = (iconv_t)(-1);
struct IconvProcessor::Private {
Private(): cd(invalid_cd) {}
~Private()
struct IconvProcessor::Impl
{
Impl(std::string const & to, std::string const & from)
: cd(invalid_cd), tocode_(to), fromcode_(from)
{}
~Impl()
{
if (cd != invalid_cd) {
if (iconv_close(cd) == -1) {
lyxerr << "Error returned from iconv_close("
<< errno << ")" << endl;
}
}
if (cd != invalid_cd && iconv_close(cd) == -1)
LYXERR0("Error returned from iconv_close(" << errno << ")");
}
iconv_t cd;
std::string tocode_;
std::string fromcode_;
};
IconvProcessor::IconvProcessor(char const * tocode, char const * fromcode)
: tocode_(tocode), fromcode_(fromcode),
pimpl_(new IconvProcessor::Private)
: pimpl_(new IconvProcessor::Impl(tocode, fromcode))
{
}
IconvProcessor::IconvProcessor(IconvProcessor const & other)
: tocode_(other.tocode_), fromcode_(other.fromcode_),
pimpl_(new IconvProcessor::Private)
: pimpl_(new IconvProcessor::Impl(other.pimpl_->tocode_, other.pimpl_->fromcode_))
{
}
IconvProcessor & IconvProcessor::operator=(IconvProcessor const & other)
IconvProcessor::~IconvProcessor()
{
if (&other == this)
return *this;
tocode_ = other.tocode_;
fromcode_ = other.fromcode_;
pimpl_.reset(new Private);
return *this;
delete pimpl_;
}
IconvProcessor::~IconvProcessor() {}
void IconvProcessor::operator=(IconvProcessor const & other)
{
if (&other != this)
pimpl_ = new Impl(other.pimpl_->tocode_, other.pimpl_->fromcode_);
}
bool IconvProcessor::init()
@ -100,15 +100,15 @@ bool IconvProcessor::init()
if (pimpl_->cd != invalid_cd)
return true;
pimpl_->cd = iconv_open(tocode_.c_str(), fromcode_.c_str());
pimpl_->cd = iconv_open(pimpl_->tocode_.c_str(), pimpl_->fromcode_.c_str());
if (pimpl_->cd != invalid_cd)
return true;
lyxerr << "Error returned from iconv_open" << endl;
switch (errno) {
case EINVAL:
lyxerr << "EINVAL The conversion from " << fromcode_
<< " to " << tocode_
lyxerr << "EINVAL The conversion from " << pimpl_->fromcode_
<< " to " << pimpl_->tocode_
<< " is not supported by the implementation."
<< endl;
break;
@ -154,8 +154,8 @@ int IconvProcessor::convert(char const * buf, size_t buflen,
case EILSEQ:
lyxerr << "EILSEQ An invalid multibyte sequence"
<< " has been encountered in the input.\n"
<< "When converting from " << fromcode_
<< " to " << tocode_ << ".\n";
<< "When converting from " << pimpl_->fromcode_
<< " to " << pimpl_->tocode_ << ".\n";
lyxerr << "Input:" << std::hex;
for (size_t i = 0; i < buflen; ++i) {
// char may be signed, avoid output of
@ -169,8 +169,8 @@ int IconvProcessor::convert(char const * buf, size_t buflen,
case EINVAL:
lyxerr << "EINVAL An incomplete multibyte sequence"
<< " has been encountered in the input.\n"
<< "When converting from " << fromcode_
<< " to " << tocode_ << ".\n";
<< "When converting from " << pimpl_->fromcode_
<< " to " << pimpl_->tocode_ << ".\n";
lyxerr << "Input:" << std::hex;
for (size_t i = 0; i < buflen; ++i) {
// char may be signed, avoid output of
@ -200,9 +200,7 @@ namespace {
template<typename RetType, typename InType>
vector<RetType>
iconv_convert(IconvProcessor & processor,
InType const * buf,
size_t buflen)
iconv_convert(IconvProcessor & processor, InType const * buf, size_t buflen)
{
if (buflen == 0)
return vector<RetType>();

View File

@ -15,9 +15,6 @@
#include "support/strfwd.h"
#include <boost/scoped_ptr.hpp>
#include <string>
#include <vector>
@ -26,34 +23,26 @@ namespace lyx {
class IconvProcessor
{
public:
IconvProcessor(
char const * tocode = "",
char const * fromcode = "");
IconvProcessor(char const * tocode = "", char const * fromcode = "");
/// copy constructor needed because of pimpl_
IconvProcessor(IconvProcessor const &);
/// assignment operator needed because of pimpl_
IconvProcessor & operator=(IconvProcessor const &);
/// destructor (needs to be implemented in the .C file because the
/// boost::scoped_ptr destructor needs a fully defined type
void operator=(IconvProcessor const &);
/// destructor
~IconvProcessor();
/// convert any data from \c fromcode to \c tocode unicode format.
/// \return the number of bytes of the converted output buffer.
int convert(
char const * in_buffer,
size_t in_size,
char * out_buffer,
size_t max_out_size);
int convert(char const * in_buffer, size_t in_size,
char * out_buffer, size_t max_out_size);
private:
/// open iconv.
/// \return true if the processor is ready to use.
bool init();
std::string tocode_;
std::string fromcode_;
struct Private;
::boost::scoped_ptr<Private> pimpl_;
/// hide internals
struct Impl;
Impl * pimpl_;
};
// A single codepoint conversion for utf8_to_ucs4 does not make