]> git.lyx.org Git - features.git/commitdiff
cosmetics
authorAndré Pönitz <poenitz@gmx.net>
Thu, 29 Nov 2007 07:24:55 +0000 (07:24 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 29 Nov 2007 07:24:55 +0000 (07:24 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21853 a592a061-630c-0410-9148-cb99ea01b6c8

src/support/Messages.cpp
src/support/unicode.cpp
src/support/unicode.h

index b86874c1780af8431c687f9f54c92fca5b4b220c..1af0503e861fec9538a7fc780846afaa5de5119d 100644 (file)
@@ -17,6 +17,7 @@
 #include "support/Package.h"
 #include "support/unicode.h"
 
+#include <boost/assert.hpp>
 #include <boost/current_function.hpp>
 
 #include <cerrno>
index d34f7c8e9080f5914d21d6097831517519a1b013..09bf8c450eb4e44fad2593c5072d089ee5e0ff56 100644 (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>();
index e3804350b314d367eaa0519a2309cddb6908726b..d81b454502b254505a4c3abc3239d82f4691a1cb 100644 (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