From 9160d824d87d27088db65afa0bcf0951c2db08cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 29 Nov 2007 07:24:55 +0000 Subject: [PATCH] cosmetics git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21853 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/support/Messages.cpp | 1 + src/support/unicode.cpp | 60 +++++++++++++++++++--------------------- src/support/unicode.h | 29 ++++++------------- 3 files changed, 39 insertions(+), 51 deletions(-) diff --git a/src/support/Messages.cpp b/src/support/Messages.cpp index b86874c178..1af0503e86 100644 --- a/src/support/Messages.cpp +++ b/src/support/Messages.cpp @@ -17,6 +17,7 @@ #include "support/Package.h" #include "support/unicode.h" +#include #include #include diff --git a/src/support/unicode.cpp b/src/support/unicode.cpp index d34f7c8e90..09bf8c450e 100644 --- a/src/support/unicode.cpp +++ b/src/support/unicode.cpp @@ -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 vector -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(); diff --git a/src/support/unicode.h b/src/support/unicode.h index e3804350b3..d81b454502 100644 --- a/src/support/unicode.h +++ b/src/support/unicode.h @@ -15,9 +15,6 @@ #include "support/strfwd.h" -#include - -#include #include @@ -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 pimpl_; + /// hide internals + struct Impl; + Impl * pimpl_; }; // A single codepoint conversion for utf8_to_ucs4 does not make