[SCM] exiv2 packaging branch, master, updated. debian/0.25-3.1-3734-gdcbc29a

Maximiliano Curia maxy at moszumanska.debian.org
Thu Jul 13 17:42:45 UTC 2017


Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/exiv2.git;a=commitdiff;h=32e0ade

The following commit has been merged in the master branch:
commit 32e0ade243eee772e45582688219b890b1ece9e8
Author: Andreas Huggel <ahuggel at gmx.net>
Date:   Wed Sep 7 13:58:17 2011 +0000

    #708: Implemented charset conversions with native Windows functions if iconv is not available.
---
 doc/ChangeLog   |   2 +
 src/convert.cpp | 215 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 src/convert.hpp |  32 ++++++++-
 src/tags.cpp    |  89 +++--------------------
 4 files changed, 242 insertions(+), 96 deletions(-)

diff --git a/doc/ChangeLog b/doc/ChangeLog
index ff66e1d..ba801e4 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -29,6 +29,8 @@ Changes from version 0.21.1 to 0.22
 	           segment. (Reported by Stefan Brandl)
 	- 0000757: Wrong ELSE statement in src/CMakeLists.txt.
 	           (Reported by Michael Hansen)
+	- 0000708: On Windows (MSVC and MSYS/MinGw builds), charset conversions
+	           now use respective Windows functions if iconv is not available.
 	- 0000689: Support for Encapsulated PostScript (*.eps) files.
 	           (Michael Ulbrich, Volker Grabsch)
 	- 0000439: The exiv2 library should be re-entrant.
diff --git a/src/convert.cpp b/src/convert.cpp
index 8e03d30..135fd0a 100644
--- a/src/convert.cpp
+++ b/src/convert.cpp
@@ -40,6 +40,7 @@ EXIV2_RCSID("@(#) $Id$")
 #include "convert.hpp"
 
 // + standard includes
+#include <utility>
 #include <iostream>
 #include <iomanip>
 #include <ios>
@@ -50,6 +51,10 @@ EXIV2_RCSID("@(#) $Id$")
 #endif
 #include <cstring>
 
+#if defined WIN32 && !defined __CYGWIN__
+# include <windows.h>
+#endif
+
 #ifdef EXV_HAVE_ICONV
 # include <iconv.h>
 # include <errno.h>
@@ -65,6 +70,14 @@ EXIV2_RCSID("@(#) $Id$")
 // *****************************************************************************
 // local declarations
 namespace {
+#if defined WIN32 && !defined __CYGWIN__
+    // Convert string charset with Windows MSVC functions.
+    bool convertStringCharsetMsvc(std::string& str, const char* from, const char* to);
+#endif
+#if defined EXV_HAVE_ICONV
+    // Convert string charset with iconv.
+    bool convertStringCharsetIconv(std::string& str, const char* from, const char* to);
+#endif
     /*!
       @brief Get the text value of an XmpDatum \em pos.
 
@@ -1318,7 +1331,184 @@ namespace Exiv2 {
     bool convertStringCharset(std::string &str, const char* from, const char* to)
     {
         if (0 == strcmp(from, to)) return true; // nothing to do
+        bool ret = false;
 #if defined EXV_HAVE_ICONV
+        ret = convertStringCharsetIconv(str, from, to);
+#elif defined WIN32 && !defined __CYGWIN__
+        ret = convertStringCharsetMsvc(str, from, to);
+#else
+# ifndef SUPPRESS_WARNINGS
+        EXV_WARNING << "Charset conversion required but no character mapping functionality available.
";
+# endif
+#endif
+        return ret;
+    }
+}                                       // namespace Exiv2
+
+// *****************************************************************************
+// local definitions
+namespace {
+
+    using namespace Exiv2;
+
+#if defined WIN32 && !defined __CYGWIN__
+    bool swapBytes(std::string& str)
+    {
+        // Naive byte-swapping, I'm sure this can be done more efficiently
+        if (str.size() & 1) {
+#ifdef DEBUG
+            EXV_DEBUG << "swapBytes: Size " << str.size() << " of input string is not even.
";
+#endif
+            return false;
+        }
+        for (unsigned int i = 0; i < str.size() / 2; ++i) {
+            char t = str[2 * i];
+            str[2 * i] = str[2 * i + 1];
+            str[2 * i + 1] = t;
+        }
+        return true;
+    }
+
+    bool mb2wc(UINT cp, std::string& str)
+    {
+        if (str.empty()) return true;
+        int len = MultiByteToWideChar(cp, 0, str.c_str(), str.size(), 0, 0);
+        if (len == 0) {
+#ifdef DEBUG
+            EXV_DEBUG << "mb2wc: Failed to determine required size of output buffer.
";
+#endif
+            return false;
+        }
+        std::vector<std::string::value_type> out;
+        out.resize(len * 2);
+        int ret = MultiByteToWideChar(cp, 0, str.c_str(), str.size(), (LPWSTR)&out[0], len * 2);
+        if (ret == 0) {
+#ifdef DEBUG
+            EXV_DEBUG << "mb2wc: Failed to convert the input string to a wide character string.
";
+#endif
+            return false;
+        }
+        str.assign(out.begin(), out.end());
+        return true;
+    }
+
+    bool wc2mb(UINT cp, std::string& str)
+    {
+        if (str.empty()) return true;
+        if (str.size() & 1) {
+#ifdef DEBUG
+            EXV_DEBUG << "wc2mb: Size " << str.size() << " of input string is not even.
";
+#endif
+            return false;
+        }
+        int len = WideCharToMultiByte(cp, 0, (LPCWSTR)str.data(), str.size() / 2, 0, 0, 0, 0);
+        if (len == 0) {
+#ifdef DEBUG
+            EXV_DEBUG << "wc2mb: Failed to determine required size of output buffer.
";
+#endif
+            return false;
+        }
+        std::vector<std::string::value_type> out;
+        out.resize(len);
+        int ret = WideCharToMultiByte(cp, 0, (LPCWSTR)str.data(), str.size() / 2, (LPSTR)&out[0], len, 0, 0);
+        if (ret == 0) {
+#ifdef DEBUG
+            EXV_DEBUG << "wc2mb: Failed to convert the input string to a multi byte string.
";
+#endif
+            return false;
+        }
+        str.assign(out.begin(), out.end());
+        return true;
+    }
+
+    bool utf8ToUcs2be(std::string& str)
+    {
+        bool ret = mb2wc(CP_UTF8, str);
+        if (ret) ret = swapBytes(str);
+        return ret;
+    }
+
+    bool utf8ToUcs2le(std::string& str)
+    {
+        return mb2wc(CP_UTF8, str);
+    }
+
+    bool ucs2beToUtf8(std::string& str)
+    {
+        bool ret = swapBytes(str);
+        if (ret) ret = wc2mb(CP_UTF8, str);
+        return ret;
+    }
+
+    bool ucs2beToUcs2le(std::string& str)
+    {
+        return swapBytes(str);
+    }
+
+    bool ucs2leToUtf8(std::string& str)
+    {
+        return wc2mb(CP_UTF8, str);
+    }
+
+    bool ucs2leToUcs2be(std::string& str)
+    {
+        return swapBytes(str);
+    }
+
+    bool iso88591ToUtf8(std::string& str)
+    {
+        bool ret = mb2wc(28591, str);
+        if (ret) ret = wc2mb(CP_UTF8, str);
+        return ret;
+    }
+
+    bool asciiToUtf8(std::string& /*str*/)
+    {
+        // nothing to do
+        return true;
+    }
+
+    typedef bool (*ConvFct)(std::string& str);
+    
+    struct ConvFctList {
+        bool operator==(std::pair<const char*, const char*> fromTo) const
+            { return 0 == strcmp(from_, fromTo.first) && 0 == strcmp(to_, fromTo.second); }
+        const char* from_;
+        const char* to_;
+        ConvFct convFct_;
+    };
+
+    const ConvFctList convFctList[] = {
+        { "UTF-8",      "UCS-2BE", utf8ToUcs2be   },
+        { "UTF-8",      "UCS-2LE", utf8ToUcs2le   },
+        { "UCS-2BE",    "UTF-8",   ucs2beToUtf8   },
+        { "UCS-2BE",    "UCS-2LE", ucs2beToUcs2le },
+        { "UCS-2LE",    "UTF-8",   ucs2leToUtf8   },
+        { "UCS-2LE",    "UCS-2BE", ucs2leToUcs2be },
+        { "ISO-8859-1", "UTF-8",   iso88591ToUtf8 },
+        { "ASCII",      "UTF-8",   asciiToUtf8    }
+        // Update the convertStringCharset() documentation if you add more here!
+    };
+
+    bool convertStringCharsetMsvc(std::string& str, const char* from, const char* to)
+    {
+        bool ret = false;
+        const ConvFctList* p = find(convFctList, std::make_pair(from, to));
+        if (p) ret = p->convFct_(str);
+#ifndef SUPPRESS_WARNINGS
+        else {
+            EXV_WARNING << "No Windows function to map character string from " << from << " to " << to << " available.
";
+        }
+#endif
+        return ret;
+    }
+
+#endif // defined WIN32 && !defined __CYGWIN__
+#if defined EXV_HAVE_ICONV
+    bool convertStringCharsetIconv(std::string& str, const char* from, const char* to)
+    {
+        if (0 == strcmp(from, to)) return true; // nothing to do
+
         bool ret = true;
         iconv_t cd;
         cd = iconv_open(to, from);
@@ -1329,18 +1519,18 @@ namespace Exiv2 {
             return false;
         }
         std::string outstr;
-        EXV_ICONV_CONST char *inptr = const_cast<char *>(str.c_str());
+        EXV_ICONV_CONST char* inptr = const_cast<char*>(str.c_str());
         size_t inbytesleft = str.length();
         while (inbytesleft) {
-            char outbuf[100];
-            char *outptr = outbuf;
-            size_t outbytesleft = sizeof(outbuf) - 1;
+            char outbuf[256];
+            char* outptr = outbuf;
+            size_t outbytesleft = sizeof(outbuf);
             size_t rc = iconv(cd,
                               &inptr,
                               &inbytesleft,
                               &outptr,
                               &outbytesleft);
-            int outbytesProduced = sizeof(outbuf) - 1 - outbytesleft;
+            int outbytesProduced = sizeof(outbuf) - outbytesleft;
             if (rc == size_t(-1) && errno != E2BIG) {
 #ifndef SUPPRESS_WARNINGS
                 EXV_WARNING << "iconv: " << strError()
@@ -1349,7 +1539,6 @@ namespace Exiv2 {
                 ret = false;
                 break;
             }
-            *outptr = '

-- 
exiv2 packaging



More information about the pkg-kde-commits mailing list