]> git.lyx.org Git - lyx.git/blobdiff - src/support/unicode.cpp
Remove unused macros USE_INCLUDED_STRING and STD_STRING_IS_GOOD
[lyx.git] / src / support / unicode.cpp
index 09bf8c450eb4e44fad2593c5072d089ee5e0ff56..8e003437e3be72ae4b71aa61eab03e3904640af8 100644 (file)
@@ -3,7 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
  *
  * Full author contact details are available in file CREDITS.
  *
 #include <iomanip>
 #include <ostream>
 #include <map>
+#include <string>
 
-using std::endl;
-using std::map;
-using std::make_pair;
-using std::string;
-using std::vector;
+using namespace std;
 
 namespace {
 
@@ -54,7 +51,7 @@ static const iconv_t invalid_cd = (iconv_t)(-1);
 
 struct IconvProcessor::Impl
 {
-       Impl(std::string const & to, std::string const & from)
+       Impl(string const & to, string const & from)
                : cd(invalid_cd), tocode_(to), fromcode_(from)
        {}
 
@@ -65,8 +62,8 @@ struct IconvProcessor::Impl
        }
 
        iconv_t cd;
-       std::string tocode_;
-       std::string fromcode_;
+       string tocode_;
+       string fromcode_;
 };
 
 
@@ -137,7 +134,12 @@ int IconvProcessor::convert(char const * buf, size_t buflen,
 
        int res = iconv(pimpl_->cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
 
-       //lyxerr << std::dec;
+       // flush out remaining data. This is needed because iconv sometimes
+       // holds back chars in the stream, waiting for a combination character
+       // (see e.g. http://sources.redhat.com/bugzilla/show_bug.cgi?id=1124)
+       iconv(pimpl_->cd, NULL, NULL, &outbuf, &outbytesleft);
+
+       //lyxerr << dec;
        //lyxerr << "Inbytesleft: " << inbytesleft << endl;
        //lyxerr << "Outbytesleft: " << outbytesleft << endl;
 
@@ -156,7 +158,7 @@ int IconvProcessor::convert(char const * buf, size_t buflen,
                                << " has been encountered in the input.\n"
                                << "When converting from " << pimpl_->fromcode_
                                << " to " << pimpl_->tocode_ << ".\n";
-                       lyxerr << "Input:" << std::hex;
+                       lyxerr << "Input:" << hex;
                        for (size_t i = 0; i < buflen; ++i) {
                                // char may be signed, avoid output of
                                // something like 0xffffffc2
@@ -164,14 +166,14 @@ int IconvProcessor::convert(char const * buf, size_t buflen,
                                        *reinterpret_cast<unsigned char const *>(buf + i);
                                lyxerr << " 0x" << (unsigned int)b;
                        }
-                       lyxerr << std::dec << endl;
+                       lyxerr << dec << endl;
                        break;
                case EINVAL:
                        lyxerr << "EINVAL An incomplete multibyte sequence"
                                << " has been encountered in the input.\n"
                                << "When converting from " << pimpl_->fromcode_
                                << " to " << pimpl_->tocode_ << ".\n";
-                       lyxerr << "Input:" << std::hex;
+                       lyxerr << "Input:" << hex;
                        for (size_t i = 0; i < buflen; ++i) {
                                // char may be signed, avoid output of
                                // something like 0xffffffc2
@@ -179,7 +181,7 @@ int IconvProcessor::convert(char const * buf, size_t buflen,
                                        *reinterpret_cast<unsigned char const *>(buf + i);
                                lyxerr << " 0x" << (unsigned int)b;
                        }
-                       lyxerr << std::dec << endl;
+                       lyxerr << dec << endl;
                        break;
                default:
                        lyxerr << "\tSome other error: " << errno << endl;