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/Package.h"
#include "support/unicode.h" #include "support/unicode.h"
#include <boost/assert.hpp>
#include <boost/current_function.hpp> #include <boost/current_function.hpp>
#include <cerrno> #include <cerrno>

View File

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

View File

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